FreeRedis 1.3.6

dotnet add package FreeRedis --version 1.3.6
                    
NuGet\Install-Package FreeRedis -Version 1.3.6
                    
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" Version="1.3.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FreeRedis" Version="1.3.6" />
                    
Directory.Packages.props
<PackageReference Include="FreeRedis" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FreeRedis --version 1.3.6
                    
#r "nuget: FreeRedis, 1.3.6"
                    
#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.
#addin nuget:?package=FreeRedis&version=1.3.6
                    
Install FreeRedis as a Cake Addin
#tool nuget:?package=FreeRedis&version=1.3.6
                    
Install FreeRedis 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>

  • 🌈 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, Transaction, DelayQueue, RediSearch
  • 🌴 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("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));

🎣 Master-Slave

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.

⛳ Redis Sentinel

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.
    );

🌌 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[] { "192.168.0.2:7001", "192.168.0.2:7002", "192.168.0.2:7003" }
    );

⚡ 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()
{
    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);

📃 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[];

cli.Eval("return redis.call('set',KEYS[1],'bar')", 
    new[] { Guid.NewGuid().ToString() })

💻 Pipeline

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]);
}

📰 Transaction

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]);
}

📯 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));
}

🍡 DelayQueue

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;
});

🐆 RediSearch

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();

👯 Contributors

<a href="https://github.com/2881099/FreeRedis/graphs/contributors"> <img src="https://contributors-img.web.app/image?repo=2881099/FreeRedis" /> </a>

💕 Donation

Thank you for your donation

🗄 License

MIT

Product 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. 
.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 net40 is compatible.  net403 was computed.  net45 was computed.  net451 is compatible.  net452 was computed.  net46 was computed.  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 (116)

Showing the top 5 NuGet packages that depend on FreeRedis:

Package Downloads
PiratesCore

湖南医标通信息科技有限公司

FreeScheduler

轻量化定时任务调度,支持集群任务、临时的延时任务和重复循环任务,可按秒,每天/每周/每月固定时间,自定义间隔执行,支持 .NET Core 2.1+、.NET Framework 4.0+ 运行环境。

Zq.Utils

C# .NET Framework4.5版本工具类

QQZiFramework

.net core应用通过框架,包括orm、redis、消息列队、日志、审计、授权等功能

Zq.Utils.Core

.NET Standard2.0、.NET Standard2.1、.NET5、.NET6版本工具类

GitHub repositories (16)

Showing the top 16 popular GitHub repositories that depend on FreeRedis:

Repository Stars
SkyAPM/SkyAPM-dotnet
The .NET/.NET Core instrument agent for Apache SkyWalking
2881099/FreeIM
.NETCore websocket 实现简易、高性能、集群即时通讯组件,支持点对点通讯、群聊通讯、上线下线事件消息等众多实用性功能.
ldqk/Masuit.MyBlogs
基于C#/.NET8的 masuit.org个人博客站项目源码,https://masuit.org ,供参考、学习、引用、非商业性质的部署。
bing-framework/Bing.NetCore
Bing是基于 .net core 3.1 的框架,旨在提升团队的开发输出能力,由常用公共操作类(工具类、帮助类)、分层架构基类,第三方组件封装,第三方业务接口封装等组成。
luoyunchong/lin-cms-dotnetcore
😃A simple and practical CMS implemented by .NET + FreeSql;前后端分离、Docker部署、OAtuh2授权登录、自动化部署DevOps、自动同步至Gitee、代码生成器、仿掘金专栏
TeslaFly01/SmartSqlT
🔥🔥🔥 SmartSQL 是一款方便、快捷的数据库文档查询、导出工具!该工具从最初支持CHM文档格式开始,通过不断地探索开发、集思广益和不断改进,又陆续支持Word、Excel、PDF、Html、Xml、Json、MarkDown等文档格式的导出。同时支持SqlServer、MySql、PostgreSQL、SQLite等多种数据库的文档查询和导出功能。
aprilyush/EasyCMS
EasyCms基于Asp.net Core 的后台快速开发框架,内容管理系统
LeonKou/NetPro
🌈An enhanced version with clean architecture of asp.netcore,efficiently manage startup,Support for netcore3.1/6.0
whuanle/maomi
Maomi 框架是一个简单的、简洁的开发框架,除了框架本身提供的功能之外,Maomi 还作为一个易于阅读的开源项目,能够给开发者提供设计框架的思路和代码。
cocosip/sharp-abp
Abp-vNext extension modules
beetlex-io/BeetleX.Redis
A high-performance async/non-blocking redis client components for dotnet core,default data formater json protobuf and messagepack,support ssl
oncemi/OnceMi.AspNetCore.OSS
ASP.NET Core对象储存扩展包,支持Minio自建对象储存、阿里云OSS、腾讯云COS、七牛云Kodo、华为云OBS、百度云BOS、天翼云OOS经典版。
vla/BloomFilter.NetCore
A bloom filter implementation
leooneone/aibpm.plus
AIBPM是一个开源的工作流引擎。本项目是后端服务,前端请移步aibpm.ui.plus。
oncemi/OnceMi.Framework
基于.NET 7和Vue 2开发的企业级前后端分离权限管理开发框架(后台管理系统),具有组织管理、角色管理、用户管理、菜单管理、授权管理、计划任务、文件管理等功能。支持国内外多种流行数据库,支持IdentityServer4认证中心。
pridejoy/MalusAdmin
海棠后台管理系统,基于Net7+Vue3+Soybean 开发的前后端分离式权限管理系统,采用最原生最简洁的方式来实现, 前端清新优雅高颜值,后端 结构清晰,优雅易懂,功能强大,提供快速开发的解决方案。
Version Downloads Last updated
1.3.6 16,252 4 months ago
1.3.5 2,381 4 months ago
1.3.4 8,757 5 months ago
1.3.3 2,207 5 months ago
1.3.2 33,398 7 months ago
1.3.1 1,276 7 months ago
1.3.0 18,540 9 months ago
1.2.15 34,664 3/26/2024
1.2.14 12,011 3/14/2024
1.2.13 23,177 1/10/2024
1.2.12 21,679 12/25/2023
1.2.11 4,681 12/18/2023
1.2.10 4,300 12/14/2023
1.2.9 2,217 12/4/2023
1.2.7 3,143 11/22/2023
1.2.6 3,030 11/20/2023
1.2.5 9,377 11/15/2023
1.2.2 26,402 11/6/2023
1.1.12 4,478 10/24/2023
1.1.10 18,858 9/18/2023
1.1.9 10,249 9/7/2023
1.1.8 949 9/1/2023
1.1.7 11,674 8/25/2023
1.1.6 2,789 8/11/2023
1.1.5 37,035 6/30/2023
1.1.3 1,767 6/21/2023
1.1.2 6,100 6/12/2023
1.1.1 28,289 5/31/2023
1.1.0 1,020 5/28/2023
1.0.11 4,163 5/19/2023
1.0.10 14,426 4/23/2023
1.0.8 46,803 3/15/2023
1.0.7 7,369 3/1/2023
1.0.5 5,462 2/17/2023
1.0.4 7,771 2/1/2023
1.0.3 190,130 11/2/2022
1.0.2 36,063 9/15/2022
1.0.2-preview20220915 236 9/15/2022
1.0.1 11,578 9/7/2022
0.6.6 7,961 9/6/2022
0.6.5 17,318 8/13/2022
0.6.3 5,728 8/10/2022
0.6.2 8,116 8/2/2022
0.6.1 1,553 7/29/2022
0.5.9 6,181 7/26/2022
0.5.8 2,022 7/20/2022
0.5.5 2,062 7/14/2022
0.5.4 37,465 6/10/2022
0.5.3 6,299 5/28/2022
0.5.2 13,590 4/28/2022
0.5.1 1,534 4/22/2022
0.5.0 6,042 3/29/2022
0.3.7 55,247 9/7/2021
0.3.5 28,830 4/13/2021
0.3.0 53,122 1/16/2021
0.2.8 23,612 1/4/2021
0.2.7 9,951 12/22/2020
0.2.6 886 12/16/2020
0.2.5 609 12/16/2020
0.2.4 818 12/12/2020
0.2.1 840 12/11/2020
0.1.9 1,938 12/9/2020
0.1.8 2,171 12/5/2020
0.1.7 1,300 12/4/2020
0.1.6 885 12/1/2020
0.1.5 975 11/23/2020
0.1.3 683 11/19/2020
0.1.2 1,339 11/14/2020
0.1.0 844 11/10/2020
0.0.9 577 11/9/2020
0.0.8 678 11/7/2020
0.0.6 613 11/6/2020
0.0.5 780 11/3/2020