-
Notifications
You must be signed in to change notification settings - Fork 2
docs: 更新readme #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3fc1302
e405fca
f0f43e8
9a0aa6c
21800da
5cb8fe1
fa35dad
9750411
ecc0291
c8e9a4d
692f409
41b856e
097b1ef
364a659
d815c53
a66e61e
80eeca3
4920f4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| # TYLDDB-C# | ||
|
|
||
| C# version. | ||
|
|
||
| A strongly typed constrained distributed file system that can act as a database. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| using System.Diagnostics; | ||
Check warningCode scanning / Sonarscharp (reported by Codacy) Provide an 'AssemblyVersion' attribute for assembly 'srcassembly.dll'. Warning test
Provide an 'AssemblyVersion' attribute for assembly 'srcassembly.dll'.
Check noticeCode scanning / Sonarscharp (reported by Codacy) Provide a 'ComVisible' attribute for assembly 'srcassembly.dll'. Note test
Provide a 'ComVisible' attribute for assembly 'srcassembly.dll'.
Check warningCode scanning / Sonarscharp (reported by Codacy) Remove this unnecessary 'using'. Warning test
Remove this unnecessary 'using'.
Check noticeCode scanning / Sonarscharp (reported by Codacy) Provide a 'CLSCompliant' attribute for assembly 'srcassembly.dll'. Note test
Provide a 'CLSCompliant' attribute for assembly 'srcassembly.dll'.
Check warningCode scanning / Sonarscharp (reported by Codacy) Add or update the header of this file. Warning test
Add or update the header of this file.
|
||
|
|
||
| namespace TYLDDB.Utils.FastCache.Test | ||
| { | ||
| internal class HighPrecisionTimer | ||
| { | ||
| private Stopwatch stopwatch; | ||
Check noticeCode scanning / Sonarscharp (reported by Codacy) Make 'stopwatch' 'readonly'. Note test
Make 'stopwatch' 'readonly'.
|
||
|
|
||
| public HighPrecisionTimer() | ||
| { | ||
| stopwatch = new Stopwatch(); | ||
| } | ||
|
|
||
| // 启动计时器 | ||
| public void Start() | ||
| { | ||
| stopwatch.Start(); | ||
| } | ||
|
|
||
| // 停止计时器 | ||
| public void Stop() | ||
| { | ||
| stopwatch.Stop(); | ||
| } | ||
|
|
||
| // 重置计时器 | ||
| public void Reset() | ||
| { | ||
| stopwatch.Reset(); | ||
| } | ||
|
|
||
| // 获取已用时间(毫秒) | ||
| public double ElapsedMilliseconds() | ||
| { | ||
| return stopwatch.Elapsed.TotalMilliseconds; | ||
| } | ||
|
|
||
| // 获取已用时间(秒) | ||
| public double ElapsedSeconds() | ||
| { | ||
| return stopwatch.Elapsed.TotalSeconds; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| using TYLDDB.Utils.FastCache; | ||
Check warningCode scanning / Sonarscharp (reported by Codacy) Add or update the header of this file. Warning test
Add or update the header of this file.
Check noticeCode scanning / Sonarscharp (reported by Codacy) Provide a 'CLSCompliant' attribute for assembly 'srcassembly.dll'. Note test
Provide a 'CLSCompliant' attribute for assembly 'srcassembly.dll'.
Check warningCode scanning / Sonarscharp (reported by Codacy) Provide an 'AssemblyVersion' attribute for assembly 'srcassembly.dll'. Warning test
Provide an 'AssemblyVersion' attribute for assembly 'srcassembly.dll'.
Check noticeCode scanning / Sonarscharp (reported by Codacy) Provide a 'ComVisible' attribute for assembly 'srcassembly.dll'. Note test
Provide a 'ComVisible' attribute for assembly 'srcassembly.dll'.
|
||
| using TYLDDB.Utils.FastCache.Test; | ||
|
|
||
| SemaphoreSlimDefault(); | ||
|
|
||
| Console.ReadLine(); | ||
|
|
||
| // 普通线程锁的数据库读写运行 | ||
| static async void SemaphoreSlimDefault() | ||
| { | ||
| var setTime = new HighPrecisionTimer(); | ||
| var setAsyncTime = new HighPrecisionTimer(); | ||
| var getByKeyTime = new HighPrecisionTimer(); | ||
| var getByKeyAsyncTime = new HighPrecisionTimer(); | ||
| var getKeysByValueTime = new HighPrecisionTimer(); | ||
| var getKeysByValueAsyncTime = new HighPrecisionTimer(); | ||
| var getAllCacheTime = new HighPrecisionTimer(); | ||
| var getAllCacheAsyncTime = new HighPrecisionTimer(); | ||
|
|
||
| var cache = new Cache(); | ||
|
|
||
| setTime.Start(); | ||
| cache.Set("TESTKEY1", "TESTVALUE1"); | ||
| setTime.Stop(); | ||
|
|
||
| setAsyncTime.Start(); | ||
| await cache.SetAsync("TESTKEY2", "TESTVALUE2"); | ||
| setAsyncTime.Stop(); | ||
|
|
||
| getByKeyTime.Start(); | ||
| Console.WriteLine("TESTKEY1对应的值:" + cache.GetByKey("TESTKEY1")); | ||
| getByKeyTime.Stop(); | ||
|
|
||
| getByKeyAsyncTime.Start(); | ||
| Console.WriteLine("TESTKEY2对应的值:" + await cache.GetByKeyAsync("TESTKEY2")); | ||
| getByKeyAsyncTime.Stop(); | ||
|
|
||
| cache.Set("TESTKEY3", "TESTVALUE2"); | ||
|
|
||
| Console.WriteLine("TESTVALUE2对应的所有键:"); | ||
| getKeysByValueTime.Start(); | ||
| Console.WriteLine(string.Join(", ", cache.GetKeysByValue("TESTVALUE2"))); | ||
| getKeysByValueTime.Stop(); | ||
|
|
||
| Console.WriteLine("TESTVALUE2对应的所有键:"); | ||
| getKeysByValueAsyncTime.Start(); | ||
| Console.WriteLine(string.Join(", ", await cache.GetKeysByValueAsync("TESTVALUE2"))); | ||
| getKeysByValueAsyncTime.Stop(); | ||
|
|
||
| // 获取并输出所有缓存项(同步方法) | ||
| getAllCacheTime.Start(); | ||
| var allCacheSync = cache.GetAllCache(); | ||
| Console.WriteLine("同步获取所有缓存项:"); | ||
| foreach (var kvp in allCacheSync) | ||
| { | ||
| Console.WriteLine($"{kvp.Key}: {kvp.Value}"); | ||
| } | ||
| getAllCacheTime.Stop(); | ||
|
|
||
| // 获取并输出所有缓存项(异步方法) | ||
| getAllCacheAsyncTime.Start(); | ||
| var allCacheAsync = await cache.GetAllCacheAsync(); | ||
| Console.WriteLine("异步获取所有缓存项:"); | ||
| foreach (var kvp in allCacheAsync) | ||
| { | ||
| Console.WriteLine($"{kvp.Key}: {kvp.Value}"); | ||
| } | ||
| getAllCacheAsyncTime.Stop(); | ||
|
|
||
|
|
||
| Console.WriteLine("时间消耗:"); | ||
| Console.WriteLine($"设置键值(同步):{setTime.ElapsedMilliseconds()}ms 设置键值(异步):{setAsyncTime.ElapsedMilliseconds()}ms"); | ||
| Console.WriteLine($"根据键获取值(同步):{getByKeyTime.ElapsedMilliseconds()}ms 根据键获取值(异步):{getByKeyAsyncTime.ElapsedMilliseconds()}ms"); | ||
| Console.WriteLine($"根据值获取键(同步):{getKeysByValueTime.ElapsedMilliseconds()}ms 根据值获取键(异步):{getKeysByValueAsyncTime.ElapsedMilliseconds()}ms"); | ||
| Console.WriteLine($"获取所有缓存项(同步):{getAllCacheTime.ElapsedMilliseconds()}ms 获取所有缓存项(异步):{getAllCacheAsyncTime.ElapsedMilliseconds()}ms"); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\TYLDDB\TYLDDB.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # How to use TYLDDB | ||
|
|
||
| ## Basic content | ||
|
|
||
| ### Read database | ||
|
|
||
| #### Instantiate the LDDB class | ||
|
|
||
| ```c# | ||
| LDDB lddb = new LDDB(); | ||
| ``` | ||
|
|
||
| If you are using a higher version .NET, you can also write a little simpler. | ||
|
|
||
| ```c# | ||
| LDDB lddb = new(); | ||
| ``` | ||
|
|
||
| #### Read file | ||
|
|
||
| ```c# | ||
| lddb.FilePath = "./example.lddb"; | ||
| lddb.ReadingFile(); | ||
| ``` | ||
|
|
||
| The contents of the file are then loaded into memory. | ||
|
|
||
| #### Select the database to read | ||
|
|
||
| ```c# | ||
| lddb.LoadDatabase("database1"); | ||
| ``` | ||
|
|
||
| This allows you to select the contents of the database for the next operation | ||
|
|
||
| If you want to get all the contents of this database, you can use `lddb.GetLoadingDatabaseContent()` , which returns a string. | ||
|
|
||
| #### Gets all database names | ||
|
|
||
| ```c# | ||
| lddb.ReadAllDatabaseName(); | ||
| ``` | ||
|
|
Check notice
Code scanning / devskim
A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note