FreeRedis.DistributedCache 1.2.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package FreeRedis.DistributedCache --version 1.2.5                
NuGet\Install-Package FreeRedis.DistributedCache -Version 1.2.5                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FreeRedis.DistributedCache" Version="1.2.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FreeRedis.DistributedCache --version 1.2.5                
#r "nuget: FreeRedis.DistributedCache, 1.2.5"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FreeRedis.DistributedCache as a Cake Addin
#addin nuget:?package=FreeRedis.DistributedCache&version=1.2.5

// Install FreeRedis.DistributedCache as a Cake Tool
#tool nuget:?package=FreeRedis.DistributedCache&version=1.2.5                

<h1 align="center"> 🦄 FreeRedis </h1>

<div align="center">

FreeRedis is a redis client based on .NET, supports .NET Core 2.1+, .NET Framework 4.0+, and Xamarin.

nuget stats GitHub license

<p> <span>English</span> |
<a href="">中文</a> </p>


  • 🌈 RedisClient Keep all method names consistent with redis-cli
  • 🌌 Support Redis Cluster (requires redis-server 3.2 and above)
  • ⛳ Support Redis Sentinel
  • 🎣 Support Redis Master-Slave
  • 📡 Support Redis Pub-Sub
  • 📃 Support Redis Lua Scripting
  • 💻 Support Pipeline
  • 📰 Support Transaction
  • 🌴 Support Geo type commands (requires redis-server 3.2 and above)
  • 🌲 Support Streams type commands (requires redis-server 5.0 and above)
  • ⚡ Support Client-side-caching (requires redis-server 6.0 and above)
  • 🌳 Support Redis 6 RESP3 Protocol

QQ Groups:4336577(full)、8578575(available)52508226(available)

🚀 Quick start

public static RedisClient cli = new RedisClient(",password=123,defaultDatabase=13");
cli.Serialize = obj => JsonConvert.SerializeObject(obj);
cli.Deserialize = (json, type) => JsonConvert.DeserializeObject(json, type);
cli.Notice += (s, e) => Console.WriteLine(e.Log); //print command log

cli.Set("key1", "value1");
cli.MSet("key1", "value1", "key2", "value2");

string value1 = cli.Get("key1");
string[] vals = cli.MGet("key1", "key2");

Supports strings, hashes, lists, sets, sorted sets, bitmaps, hyperloglogs, geo, streams And BloomFilter.

Parameter Default Explain
protocol RESP2 If you use RESP3, you need redis 6.0 environment
user <empty> Redis server username, requires redis-server 6.0
password <empty> Redis server password
defaultDatabase 0 Redis server database
max poolsize 100 Connection max pool size
min poolsize 5 Connection min pool size
idleTimeout 20000 Idle time of elements in the connection pool (MS), suitable for connecting to remote redis server
connectTimeout 10000 Connection timeout (MS)
receiveTimeout 10000 Receive timeout (MS)
sendTimeout 10000 Send timeout (MS)
encoding utf-8 string charset
retry 0 Protocol error retry execution times
ssl false Enable encrypted transmission
name <empty> Connection name, use client list command to view
prefix <empty> The prefix of the key, all methods will have this prefix. cli.Set(prefix + "key", 111);
exitAutoDisposePool true AppDomain.CurrentDomain.ProcessExit/Console.CancelKeyPress auto disposed
subscribleReadbytes false Subscrible read bytes

IPv6: [fe80::b164:55b3:4b4f:7ce6%15]:6379

//services.AddSingleton<IDistributedCache>(new FreeRedis.DistributedCache(cli));

🎣 Master-Slave

public static RedisClient cli = new RedisClient(

var value = cli.Get("key1");

Write data at; randomly read data from port 6380 or 6381.

⛳ Redis Sentinel

public static RedisClient cli = new RedisClient(
    new [] { "", "", "" },
    true //This variable indicates whether to use the read-write separation mode.

🌌 Redis Cluster

Suppose, a Redis cluster has three master nodes (7001-7003) and three slave nodes (7004-7006), then use the following code to connect to the cluster:

public static RedisClient cli = new RedisClient(
    new ConnectionStringBuilder[] { "", "", "" }

⚡ Client-side-caching

requires redis-server 6.0 and above

cli.UseClientSideCaching(new ClientSideCachingOptions
    //Client cache capacity
    Capacity = 3,
    //Filtering rules, which specify which keys can be cached locally
    KeyFilter = key => key.StartsWith("Interceptor"),
    //Check long-term unused cache
    CheckExpired = (key, dt) => DateTime.Now.Subtract(dt) > TimeSpan.FromSeconds(2)

📡 Subscribe

using (cli.Subscribe("abc", ondata)) //wait .Dispose()

void ondata(string channel, string data) =>
    Console.WriteLine($"{channel} -> {data}");

xadd + xreadgroup:

using (cli.SubscribeStream("stream_key", ondata)) //wait .Dispose()

void ondata(Dictionary<string, string> streamValue) =>

// NoAck xpending
cli.XPending("stream_key", "FreeRedis__group", "-", "+", 10);

lpush + blpop:

using (cli.SubscribeList("list_key", ondata)) //wait .Dispose()

void ondata(string listValue) =>

📃 Scripting

var r1 = cli.Eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", 
    new[] { "key1", "key2" }, "first", "second") as object[];

var r2 = cli.Eval("return {1,2,{3,'Hello World!'}}") as object[];

    new[] { Guid.NewGuid().ToString() })

💻 Pipeline

using (var pipe = cli.StartPipe())
    pipe.IncrBy("key1", 10);
    pipe.Set("key2", Null);

    object[] ret = pipe.EndPipe();
    Console.WriteLine(ret[0] + ", " + ret[2]);

📰 Transaction

using (var tran = cli.Multi())
    tran.IncrBy("key1", 10);
    tran.Set("key2", Null);

    object[] ret = tran.Exec();
    Console.WriteLine(ret[0] + ", " + ret[2]);

📯 GetDatabase: switch database

using (var db = cli.GetDatabase(10))
    db.Set("key1", 10);
    var val1 = db.Get("key1");

🔍 Scan

Support cluster mode

foreach (var keys in cli.Scan("*", 10, null))
    Console.WriteLine(string.Join(", ", keys));

👯 Contributors

<a href=""> <img src="" /> </a>

💕 Donation

Thank you for your donation

🗄 License


Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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 is compatible.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (9)

Showing the top 5 NuGet packages that depend on FreeRedis.DistributedCache:

Package Downloads






Package Description


Package Description

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on FreeRedis.DistributedCache:

Repository Stars
😃A simple and practical CMS implemented by .NET + FreeSql;前后端分离、Docker部署、OAtuh2授权登录、自动化部署DevOps、自动同步至Gitee、代码生成器、仿掘金专栏
Version Downloads Last updated
1.3.0 199 7/2/2024
1.2.5 9,070 11/15/2023
1.0.5 5,926 2/17/2023
1.0.0 294 12/29/2022