ZayniFramework.Caching.RedisClient
2.2.1
See the version list below for details.
dotnet add package ZayniFramework.Caching.RedisClient --version 2.2.1
NuGet\Install-Package ZayniFramework.Caching.RedisClient -Version 2.2.1
<PackageReference Include="ZayniFramework.Caching.RedisClient" Version="2.2.1" />
<PackageVersion Include="ZayniFramework.Caching.RedisClient" Version="2.2.1" />
<PackageReference Include="ZayniFramework.Caching.RedisClient" />
paket add ZayniFramework.Caching.RedisClient --version 2.2.1
#r "nuget: ZayniFramework.Caching.RedisClient, 2.2.1"
#addin nuget:?package=ZayniFramework.Caching.RedisClient&version=2.2.1
#tool nuget:?package=ZayniFramework.Caching.RedisClient&version=2.2.1
Caching.RedisClient module example.
You can use the ZayniFramework.Caching.RedisClient module to help you to access the Redis Server. It helps you control the connection between and provide all the request & response action log between your application and Redis Server.
Add namespace using. You might need to add the StackExchange.Redis namespace too.
using StackExchange.Redis;
using ZayniFramework.Caching.RedisClientComponent;
using ZayniFramework.Common;
using ZayniFramework.Serialization;
Then, config your Redis Server connection in your app.config file. Like this,
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="ZayniFramework" type="ZayniFramework.Common.ZayniConfigSection, ZayniFramework.Common" />
</configSections>
<ZayniFramework>
<LoggingSettings eventLogEnable="false" logEnable="true">
<DefaultTextLogger>
<add name="_DefaultLog" enable="true" maxSize="8">
<LogFile path="D:\Logs\Zayni\Tracing.log" />
<Filter filterType="deny" category="Information,Warning" />
</add>
<add name="RedisClientTrace:MyLab" enable="true" maxSize="8" dbLoggerName="Zayni" dbLoggerType="MySQL">
<LogFile path="D:\Logs\Zayni\RedisClient-Tracing-Taipei-Dev.log" />
</add>
</DefaultTextLogger>
</LoggingSettings>
<RedisClientSettings>
<RedisClients>
<add name="RedisServer1" isDefault="true" traceLoggerName="RedisClientTrace:MyLab" host="XXX.XXX.XXX.XXX " port="6379" password="" dbNumber="1" connectTimeout="5000" responseTimeout="1000" />
</RedisClients>
</RedisClientSettings>
</ZayniFramework>
<connectionStrings>
<add name="Zayni" connectionString="SERVER=XXX.XXX.XXX.XXX;DATABASE=zayni;UID=XXX;PASSWORD=XXX;Allow User Variables=True;Charset=utf8;Convert Zero Datetime=True"
providerName="MySql.Data.MySqlClient" />
</connectionStrings>
</configuration>
Get a RedisClient object from the RedisClientContainer.
// Get the 'isDefault=ture'.
RedisClient redisClient = RedisClientContainer.Get();
// Get a RedisClient from the RedisClientContainer. By name.
RedisClient redisClient = RedisClientContainer.Get( "RedisServer1" );
Using StackExchange.Redis method to access redis server.
- With better performance.
- But no request and response action log between redis server.
// You can use the StackExchange.Redis' method like this. BUT you won't have a action log if you choose this way to access redis server. (Better performance!)
// Put string data into redis server. Using StringSet method.
bool isSuccess = redisClient.Db.StringSet( "MyKey", "AAA", when: When.Always );
// Get string data from redis sever. Using StringGet method.
string result = redisClient.Db.StringGet( "MyKey" );
Using RedisClient's wrapper method to access redis server.
- You will have the request and response log between redis server if you config the app.config correctly.
- The performance will be slower...
// Declare a delegate to wrap the StachExchange.Redis' method like this.
Delegate stringSet = (Func<string, string, When, bool>)( ( key, value, when ) => redisClient.Db.StringSet( key, value, when: when ) );
// Use RedisClient's ExecResult wrapper method to invoke the delegate like this.
// Put string data into redis server.
var r1 = redisClient.ExecResult<bool>( stringSet, "ZayniTest2", "BBB", When.Always );
Assert.IsTrue( r1.Success );
Assert.IsTrue( r1.Data );
Delegate stringGet = (Func<string, string>)( key => redisClient.Db.StringGet( key ) );
var r2 = redisClient.ExecResult<string>( stringGet, "ZayniTest2" );
Assert.IsTrue( r2.Success );
Assert.AreEqual( "BBB", r2.Data );
// =================
var hashName = new HashEntry( "name", "Pony Lin" );
var hashAge = new HashEntry( "age", 32 );
var hashSex = new HashEntry( "sex", 1 );
var hashDoB = new HashEntry( "dob", "1985-05-25" );
var hashSet = (Action<string, HashEntry[]>)( ( key, hashFields ) => redisClient.Db.HashSet( key, hashFields ) );
var r = redisClient.Exec( hashSet, "ZayniTest3", new HashEntry[] { hashName, hashAge, hashSex, hashDoB } );
Assert.IsTrue( r.Success );
var hashGet = (Func<string, string, string>)( ( key, hashField ) => redisClient.Db.HashGet( key, hashField ) );
var name = redisClient.ExecResult<string>( hashGet, "ZayniTest3", "name" ).Data;
var age = redisClient.ExecResult<string>( hashGet, "ZayniTest3", "age" ).Data;
var sex = redisClient.ExecResult<string>( hashGet, "ZayniTest3", "sex" ).Data;
var dob = redisClient.ExecResult<string>( hashGet, "ZayniTest3", "dob" ).Data;
Assert.AreEqual( "Pony Lin", name );
Assert.AreEqual( "32", age );
Assert.AreEqual( "1", sex );
Assert.AreEqual( "1985-05-25", dob );
Use the RedisClient's PutHashObject and GetHashObject methods.
var source = new UserModel()
{
Name = "Nancy",
Age = 26,
Birthday = new DateTime( 1993, 2, 24 ),
CashBalance = 3000,
TotalAssets = 4100
};
string key = $"ZayniTest123:{source.Name}";
// Put a data into redis in a hash type.
var p = redisClient.PutHashObject( key, source );
Assert.IsTrue( p.Success );
// Get a data from redis in a hash type.
var g = redisClient.GetHashObject<UserModel>( key );
Assert.IsTrue( g.Success );
Assert.AreEqual( source.Name, g.Data.Name );
Assert.AreEqual( source.Age, g.Data.Age );
Assert.AreEqual( source.Birthday, g.Data.Birthday );
Assert.AreEqual( source.CashBalance, g.Data.CashBalance );
Assert.AreEqual( source.TotalAssets, g.Data.TotalAssets );
More detail sample code. You can go to Test/UnitTests/Zayni.Caching.RedisClient.Test directory.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- StackExchange.Redis (>= 2.0.495)
- ZayniFramework.Common (>= 2.2.1)
- ZayniFramework.Logging (>= 2.2.1)
- ZayniFramework.Serialization (>= 2.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
8.0.142 | 157 | 3/19/2024 |
8.0.141 | 177 | 1/4/2024 |
8.0.140 | 158 | 12/17/2023 |
6.0.138 | 146 | 3/19/2024 |
6.0.137 | 178 | 9/20/2023 |
6.0.136 | 174 | 9/14/2023 |
6.0.135 | 175 | 9/10/2023 |
6.0.134 | 275 | 7/12/2023 |
6.0.133 | 216 | 7/10/2023 |
6.0.132 | 205 | 7/7/2023 |
6.0.131 | 196 | 6/19/2023 |
6.0.130 | 197 | 6/19/2023 |
6.0.129 | 589 | 7/2/2022 |
6.0.128 | 562 | 1/16/2022 |
6.0.127 | 505 | 1/15/2022 |
6.0.126 | 538 | 1/15/2022 |
6.0.125 | 397 | 1/8/2022 |
6.0.125-hotfix1 | 269 | 1/8/2022 |
6.0.124 | 329 | 1/7/2022 |
6.0.123 | 430 | 11/14/2021 |
5.0.129 | 523 | 7/2/2022 |
5.0.128 | 611 | 1/16/2022 |
5.0.125 | 405 | 1/8/2022 |
5.0.124 | 365 | 1/7/2022 |
5.0.123 | 526 | 11/14/2021 |
5.0.122 | 531 | 10/11/2021 |
5.0.121 | 566 | 5/1/2021 |
3.1.137 | 171 | 9/20/2023 |
3.1.136 | 157 | 9/14/2023 |
3.1.135 | 167 | 9/10/2023 |
3.1.134 | 203 | 7/12/2023 |
3.1.133 | 192 | 7/11/2023 |
3.1.132 | 189 | 7/8/2023 |
3.1.131 | 194 | 6/19/2023 |
3.1.130 | 359 | 2/1/2023 |
3.1.129 | 560 | 7/2/2022 |
3.1.128 | 593 | 1/16/2022 |
3.1.125 | 393 | 1/8/2022 |
3.1.124 | 396 | 1/7/2022 |
3.1.123 | 536 | 11/14/2021 |
3.1.122 | 462 | 10/11/2021 |
3.1.121 | 593 | 5/1/2021 |
2.31.120 | 523 | 3/14/2021 |
2.30.115 | 572 | 3/6/2021 |
2.30.114 | 518 | 3/6/2021 |
2.20.101 | 551 | 3/1/2021 |
2.19.3 | 503 | 2/11/2021 |
2.19.2 | 593 | 2/6/2021 |
2.19.1 | 508 | 1/6/2021 |
2.19.0 | 548 | 1/1/2021 |
2.18.3 | 655 | 12/27/2020 |
2.18.2 | 638 | 8/29/2020 |
2.18.1 | 673 | 8/26/2020 |
2.18.0 | 661 | 8/20/2020 |
2.17.135 | 599 | 8/19/2020 |
2.17.134 | 708 | 7/28/2020 |
2.17.133 | 693 | 7/27/2020 |
2.17.132 | 687 | 7/18/2020 |
2.17.131 | 670 | 7/11/2020 |
2.16.130 | 687 | 6/13/2020 |
2.15.128 | 701 | 6/3/2020 |
2.15.127 | 766 | 5/31/2020 |
2.15.126 | 731 | 4/30/2020 |
2.14.122 | 666 | 4/13/2020 |
2.13.100 | 696 | 3/12/2020 |
2.12.51 | 716 | 2/18/2020 |
2.11.50 | 1,316 | 2/10/2020 |
2.10.44 | 1,342 | 1/30/2020 |
2.9.43 | 1,494 | 1/11/2020 |
2.8.42 | 1,450 | 1/10/2020 |
2.8.41 | 1,354 | 1/5/2020 |
2.7.40 | 1,331 | 1/2/2020 |
2.7.39 | 1,369 | 1/2/2020 |
2.7.38 | 1,523 | 1/1/2020 |
2.6.37 | 1,426 | 12/23/2019 |
2.6.35 | 1,276 | 12/4/2019 |
2.6.1 | 1,312 | 12/2/2019 |
2.6.0 | 1,335 | 11/28/2019 |
2.5.2 | 1,596 | 11/26/2019 |
2.5.1 | 1,327 | 11/12/2019 |
2.5.0 | 1,367 | 11/9/2019 |
2.4.3 | 1,008 | 10/16/2019 |
2.4.2 | 1,049 | 10/16/2019 |
2.4.1 | 994 | 9/20/2019 |
2.3.113 | 525 | 3/6/2021 |
2.3.112 | 512 | 3/6/2021 |
2.3.28 | 1,369 | 9/19/2019 |
2.3.27 | 1,130 | 8/30/2019 |
2.3.26 | 1,242 | 8/20/2019 |
2.3.25 | 753 | 8/12/2019 |
2.3.22 | 1,005 | 7/31/2019 |
2.3.21 | 1,060 | 7/20/2019 |
2.3.20 | 1,145 | 6/22/2019 |
2.3.19 | 1,209 | 6/14/2019 |
2.3.18 | 1,013 | 6/13/2019 |
2.3.17 | 789 | 6/13/2019 |
2.3.15 | 1,081 | 6/8/2019 |
2.3.14 | 873 | 6/8/2019 |
2.3.13 | 1,477 | 5/30/2019 |
2.3.12 | 748 | 5/24/2019 |
2.3.11 | 784 | 5/24/2019 |
2.3.10 | 813 | 5/21/2019 |
2.3.9 | 790 | 5/9/2019 |
2.3.8 | 781 | 5/8/2019 |
2.3.7 | 837 | 4/30/2019 |
2.3.6 | 877 | 4/23/2019 |
2.3.5 | 764 | 4/19/2019 |
2.3.4 | 785 | 4/18/2019 |
2.3.3 | 770 | 4/17/2019 |
2.3.2 | 774 | 4/6/2019 |
2.3.1 | 911 | 12/15/2018 |
2.3.0 | 925 | 12/7/2018 |
2.2.6 | 954 | 11/25/2018 |
2.2.1 | 909 | 11/17/2018 |
2.2.0 | 911 | 11/16/2018 |
2.1.0 | 946 | 11/15/2018 |
2.0.1 | 940 | 11/6/2018 |
2.0.0 | 948 | 11/4/2018 |