![]() |
VOOZH | about |
dotnet add package FreeRedis.DistributedCache --version 1.5.2
NuGet\Install-Package FreeRedis.DistributedCache -Version 1.5.2
<PackageReference Include="FreeRedis.DistributedCache" Version="1.5.2" />
<PackageVersion Include="FreeRedis.DistributedCache" Version="1.5.2" />Directory.Packages.props
<PackageReference Include="FreeRedis.DistributedCache" />Project file
paket add FreeRedis.DistributedCache --version 1.5.2
#r "nuget: FreeRedis.DistributedCache, 1.5.2"
#:package FreeRedis.DistributedCache@1.5.2
#addin nuget:?package=FreeRedis.DistributedCache&version=1.5.2Install as a Cake Addin
#tool nuget:?package=FreeRedis.DistributedCache&version=1.5.2Install as a Cake Tool
<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+, Xamarin, and AOT.
👁 nuget
👁 stats
👁 GitHub license
<p>
<span>English</span> |
<a href="README.zh-CN.md">中文</a>
</p>
</div>
QQ Groups:4336577(full)、8578575(available)、52508226(available)
public static RedisClient cli = new RedisClient("127.0.0.1:6379,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 |
| subscribeReadbytes | false | Subscribe read bytes |
IPv6: [fe80::b164:55b3:4b4f:7ce6%15]:6379
//FreeRedis.DistributedCache
//services.AddSingleton<IDistributedCache>(new FreeRedis.DistributedCache(cli));
public static RedisClient cli = new RedisClient(
"127.0.0.1:6379,password=123,defaultDatabase=13",
"127.0.0.1:6380,password=123,defaultDatabase=13",
"127.0.0.1:6381,password=123,defaultDatabase=13"
);
var value = cli.Get("key1");
Write data at 127.0.0.1:6379; randomly read data from port 6380 or 6381.
public static RedisClient cli = new RedisClient(
"mymaster,password=123",
new [] { "192.169.1.10:26379", "192.169.1.11:26379", "192.169.1.12:26379" },
true //This variable indicates whether to use the read-write separation mode.
);
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[] { "192.168.0.2:7001", "192.168.0.2:7002", "192.168.0.2:7003" }
);
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)
});
using (cli.Subscribe("abc", ondata)) //wait .Dispose()
{
Console.ReadKey();
}
void ondata(string channel, string data) =>
Console.WriteLine($"{channel} -> {data}");
xadd + xreadgroup:
using (cli.SubscribeStream("stream_key", ondata)) //wait .Dispose()
{
Console.ReadKey();
}
void ondata(Dictionary<string, string> streamValue) =>
Console.WriteLine(JsonConvert.SerializeObject(streamValue));
// NoAck xpending
cli.XPending("stream_key", "FreeRedis__group", "-", "+", 10);
lpush + blpop:
using (cli.SubscribeList("list_key", ondata)) //wait .Dispose()
{
Console.ReadKey();
}
void ondata(string listValue) =>
Console.WriteLine(listValue);
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[];
cli.Eval("return redis.call('set',KEYS[1],'bar')",
new[] { Guid.NewGuid().ToString() })
using (var pipe = cli.StartPipe())
{
pipe.IncrBy("key1", 10);
pipe.Set("key2", Null);
pipe.Get("key1");
object[] ret = pipe.EndPipe();
Console.WriteLine(ret[0] + ", " + ret[2]);
}
using (var tran = cli.Multi())
{
tran.IncrBy("key1", 10);
tran.Set("key2", Null);
tran.Get("key1");
object[] ret = tran.Exec();
Console.WriteLine(ret[0] + ", " + ret[2]);
}
using (var db = cli.GetDatabase(10))
{
db.Set("key1", 10);
var val1 = db.Get("key1");
}
Support cluster mode
foreach (var keys in cli.Scan("*", 10, null))
{
Console.WriteLine(string.Join(", ", keys));
}
var delayQueue = cli.DelayQueue("TestDelayQueue");
//Add queue
delayQueue.Enqueue($"Execute in 5 seconds.", TimeSpan.FromSeconds(5));
delayQueue.Enqueue($"Execute in 10 seconds.", DateTime.Now.AddSeconds(10));
delayQueue.Enqueue($"Execute in 15 seconds.", DateTime.Now.AddSeconds(15));
delayQueue.Enqueue($"Execute in 20 seconds.", TimeSpan.FromSeconds(20));
delayQueue.Enqueue($"Execute in 25 seconds.", DateTime.Now.AddSeconds(25));
delayQueue.Enqueue($"Execute in 2024-07-02 14:30:15", DateTime.Parse("2024-07-02 14:30:15"));
//Consumption queue
await delayQueue.DequeueAsync(s =>
{
output.WriteLine($"{DateTime.Now}:{s}");
return Task.CompletedTask;
});
cli.FtCreate(...).Execute();
cli.FtSearch(...).Execute();
cli.FtAggregate(...).Execute();
//... or ...
[FtDocument("index_post", Prefix = "blog:post:")]
class TestDoc
{
[FtKey]
public int Id { get; set; }
[FtTextField("title", Weight = 5.0)]
public string Title { get; set; }
[FtTextField("category")]
public string Category { get; set; }
[FtTextField("content", Weight = 1.0, NoIndex = true)]
public string Content { get; set; }
[FtTagField("tags")]
public string[] Tags { get; set; } //or string
[FtNumericField("views")]
public int Views { get; set; }
}
var repo = cli.FtDocumentRepository<TestDoc>();
repo.CreateIndex();
repo.Save(new TestDoc { Id = 1, Title = "test title1 word", Category = "class 1", Content = "test content 1 suffix", Tags = "user1,user2", Views = 101 });
repo.Save(new TestDoc { Id = 2, Title = "prefix test title2", Category = "class 2", Content = "test infix content 2", Tags = "user2,user3", Views = 201 });
repo.Save(new TestDoc { Id = 3, Title = "test title3 word", Category = "class 1", Content = "test word content 3", Tags = "user2,user5", Views = 301 });
repo.Delete(1, 2, 3);
repo.Save(new[]
{
new TestDoc { Id = 1, Title = "test title1 word", Category = "class 1", Content = "test content 1 suffix", Tags = "user1,user2", Views = 101 },
new TestDoc { Id = 2, Title = "prefix test title2", Category = "class 2", Content = "test infix content 2", Tags = "user2,user3", Views = 201 },
new TestDoc { Id = 3, Title = "test title3 word", Category = "class 1", Content = "test word content 3", Tags = "user2,user5", Views = 301 }
});
var list = repo.Search("*").InFields(a => new { a.Title }).ToList();
list = repo.Search("*").Return(a => new { a.Title, a.Tags }).ToList();
list = repo.Search("*").Return(a => new { tit1 = a.Title, tgs1 = a.Tags, a.Title, a.Tags }).ToList();
list = repo.Search(a => a.Title == "word" && a.Tags.Contains("user1")).Filter(a => a.Views, 1, 1000).ToList();
list = repo.Search("word").ToList();
list = repo.Search("@title:word").ToList();
<a href="https://github.com/2881099/FreeRedis/graphs/contributors"> <img src="https://contributors-img.web.app/image?repo=2881099/FreeRedis" /> </a>
Thank you for your donation
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 is compatible. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 is compatible. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 is compatible. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on FreeRedis.DistributedCache:
| Package | Downloads |
|---|---|
|
SupervisorySystem.Commons
realtimehot@outlook.com |
|
|
JetyDu.BaseDB
Package Description |
|
|
CDCD.Charging.Cache
Package Description |
|
|
Galosys.Foundation.FreeRedis
Galosys.Foundation快速开发库 |
|
|
Custom.CommonBase
Package Description |
Showing the top 2 popular GitHub repositories that depend on FreeRedis.DistributedCache:
| Repository | Stars |
|---|---|
|
luoyunchong/lin-cms-dotnetcore
😃A simple and practical CMS implemented by .NET + FreeSql;前后端分离、Docker部署、OAtuh2授权登录、自动化部署DevOps、自动同步至Gitee、代码生成器、仿掘金专栏
|
|
|
leooneone/aibpm.plus
AIBPM是一个开源的工作流引擎。本项目是后端服务,前端请移步aibpm.ui.plus。
|
| Version | Downloads | Last Updated |
|---|---|---|
| 1.5.2 | 14,427 | 11/12/2025 |
| 1.5.1 | 1,508 | 11/2/2025 |
| 1.5.0 | 676 | 9/19/2025 |
| 1.4.2 | 990 | 9/8/2025 |
| 1.4.1 | 369 | 8/22/2025 |
| 1.4.0 | 2,524 | 6/6/2025 |
| 1.3.9 | 304 | 6/5/2025 |
| 1.3.8 | 535 | 5/29/2025 |
| 1.3.7 | 1,135 | 5/8/2025 |
| 1.3.6 | 5,762 | 12/20/2024 |
| 1.3.5 | 896 | 12/14/2024 |
| 1.3.4 | 7,059 | 11/18/2024 |
| 1.3.3 | 352 | 11/12/2024 |
| 1.3.2 | 12,750 | 9/8/2024 |
| 1.3.0 | 3,833 | 7/2/2024 |
| 1.2.5 | 27,649 | 11/15/2023 |
| 1.0.5 | 8,246 | 2/17/2023 |
| 1.0.0 | 586 | 12/29/2022 |