Skip to main content
.NETFramework4.5.NETFramework4.6.1net8.0.NETStandard2.0.NETStandard2.1

้ซ˜ๆ€ง่ƒฝRedisๅฎขๆˆท็ซฏ๏ผŒๆ”ฏๆŒRESP2/RESP3ๅ่ฎฎ๏ผŒ่ฆ†็›–Redis 2.8๏ฝž7.xๅ…จ้ƒจๆ•ฐๆฎ็ป“ๆž„ไธŽๅ‘ฝไปค๏ผŒๅ†…็ฝฎๆถˆๆฏ้˜Ÿๅˆ—๏ผˆ็ฎ€ๅ•/ๅฏ้ /ๅปถ่ฟŸ/Stream๏ผ‰๏ผŒๆ”ฏๆŒ้›†็พค/ๅ“จๅ…ต/ไบ‘ๅŽ‚ๅ•†้€‚้…๏ผŒ็ปๆ—ฅๅ‡80+ไบฟๆฌก่ฐƒ็”จ้ชŒ่ฏ

Published
Oct 19, 2026
3d ago
Total Downloads
740.2K
740,163

Install

dotnet add package NewLife.Redis --version 6.6.2026.1019-beta1511
ProductVersions
.NET
net8.0
.NET Standard
netstandard2.0netstandard2.1
Other
.NETFramework4.5.NETFramework4.6.1

README

NewLife.Redis โ€” High-Performance Redis Client Component

GitHub top language

GitHub License NuGet Downloads NuGet NuGet prerelease test locales platform arch contributors

๐ŸŒ ็ฎ€ไฝ“ไธญๆ–‡ | ็น้ซ”ไธญๆ–‡ | Espaรฑol | Deutsch | ๆ—ฅๆœฌ่ชž | Franรงais | Portuguรชs | ะ ัƒััะบะธะน | ํ•œ๊ตญ์–ด | ุงู„ุนุฑุจูŠุฉ

NewLife.Redis is a high-performance / high-throughput / easy-to-integrate .NET Redis client component built by the NewLife team. Since 2017, it has been running stably on multiple production platforms handling billions of records and high concurrency, processing 80+ billion command calls daily.

๐Ÿ“– Full Documentation: Requirements (ไธญๆ–‡) | Architecture (ไธญๆ–‡) | Feature List (ไธญๆ–‡) | Competitive Analysis (ไธญๆ–‡) | Garnet Compatibility (ไธญๆ–‡) | AOT Compatibility (ไธญๆ–‡)


Table of Contents


Introduction

NewLife.Redis provides .NET developers with full-lifecycle Redis access:

  • Complete Protocol: Implements RESP2, covers all mainstream commands from Redis 2.8 to 7.x, supports all data structures: String / List / Hash / Set / Sorted Set / Stream / Geo / HyperLogLog.
  • Message Queues: Built-in simple queue, reliable queue (RPOPLPUSH + Ack semantics), delay queue, and Stream multi-consumer-group queue โ€” ready to use, no need to reinvent the wheel.
  • Clustering & HA: Supports Standalone / Master-Replica / Sentinel / Native Cluster, with automatic failover.
  • Cloud Provider Adapters: Specialized configuration and adaptation for Alibaba Cloud KVStore / Tencent Cloud Redis / Huawei Cloud DCS, covering proxy mode, ACL authentication, SSL encryption, special auth formats, and other differences.
  • Compatible Implementations: Auto-detects Microsoft Garnet, kvrocks, and other Redis-compatible servers, gracefully degrades with clear alternatives when features are unsupported.
  • Broad Framework Support: A single package covers .NET Framework 4.5 to .NET 10+, suitable for industrial control, government, IoT, and other legacy scenarios.

Core Features

  • Battle-tested at scale: 200+ Redis instances, daily peak of 100M+ business object writes / 80B+ command calls
  • Low latency: Single Get/Set round-trip 200โ€“600ยตs (including network)
  • High throughput: Built-in connection pool (max 100,000 concurrent) + efficient synchronous RESP protocol parsing + optional auto-pipeline batching
  • Auto retry & multi-address failover: Server supports comma-separated nodes, rapid failover on network errors, default 10-second shielding window
  • Rich advanced structures: List / Hash / Set / SortedSet / Stack / Geo / HyperLogLog / Stream
  • Multiple message queue paradigms: Simple / Reliable / Delay / Stream / Multi-consumer-group
  • Pluggable encoder: Default JSON, extensible to binary serialization
  • APM tracing: Supports ITracer distributed tracing + PerfCounter performance counters
  • Strong-named + multi-target: net45 / net461 / netstandard2.0 / netstandard2.1 / net8.0 (extensions include netcoreapp3.1 โ†’ net10)
  • NativeAOT support: IsAotCompatible checks on net8.0, AotSmoke project + CI regression; AOT smoke & unit tests cover win-x64 / linux-x64 / linux-arm64 / linux-la64 (LA64 via QEMU emulation), plus win-arm64, macOS and musl RIDs under native compilation (linux-x64 blocking, others in observation) โ€” see AOT Compatibility (ไธญๆ–‡)
  • Zero heavy external dependencies, fully leverages the NewLife ecosystem (logging, config, serialization, security)

Redis Protocol & Version Support

RESP Protocol Support

Protocol Status Description
RESP2 โœ… Fully supported Simple String / Error / Integer / Bulk String / Array
RESP3 โœ… Fully supported Map / Set / Double / Boolean / Null / Blob Error types, negotiated via HELLO handshake (Redis 6.0+)

Redis Version Feature Support

Redis Version Key Features Status
2.8 Basic commands, SCAN, HyperLogLog, Pub/Sub โœ… Fully supported
3.0 Native Cluster, CRC16 shard routing โœ… Fully supported
3.2 GEO spatial data โœ… Fully supported
4.0 UNLINK async delete, MODULE ๐Ÿ”„ Partial support
5.0 Stream data structure (full XADD/XREAD/XGROUP/XACK) โœ… Fully supported
6.0 ACL access control, TLS/SSL, LMOVE, RESET โœ… Fully supported
6.2 COPY, GETDEL, GETEX, GEOSEARCH โœ… Core commands supported
7.0 Functions (FCALL), LMPOP/ZMPOP, sharded Pub/Sub ๐Ÿ”„ Planned
7.2 SSUBSCRIBE / SPUBLISH ๐Ÿ”„ Planned

Architecture & Module Breakdown

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                     Application Layer                            โ”‚
โ”‚  ASP.NET Core / Console / WinForms / IoT / Worker Service        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚          Extension Integration (NewLife.Redis.Extensions)        โ”‚
โ”‚  IDistributedCache ยท IDataProtection ยท AddRedisCaching DI        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                 Advanced Features (FullRedis)                    โ”‚
โ”‚  RedisList<T> ยท RedisHash<T> ยท RedisSet<T> ยท RedisSortedSet<T>  โ”‚
โ”‚  RedisStack<T> ยท RedisGeo ยท HyperLogLog ยท RedisRedLock         โ”‚
โ”‚  RedisQueue<T> ยท RedisReliableQueue<T> ยท RedisDelayQueue<T>      โ”‚
โ”‚  RedisStream<T> ยท PubSub ยท RedisEventBus                         โ”‚
โ”‚  RedisCluster ยท RedisSentinel ยท RedisReplication                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  Core Client Layer (Redis)                       โ”‚
โ”‚  Connection Pool ObjectPool<RedisClient> (Min=10, Max=100,000)   โ”‚
โ”‚  Multi-Node Failover ยท Pipeline Mgmt ยท Encoder ยท Config Parsing  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  Protocol Layer (RedisClient)                    โ”‚
โ”‚  TCP/TLS Connection ยท RESP2 Codec ยท ArrayPool<byte> Buffers      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚ TCP/TLS
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Redis Server / Garnet / kvrocks / Alibaba / Tencent / Huawei   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Key Class Descriptions:

Class Role
Redis Core client: connection pool, multi-node failover, pipeline, configuration management
FullRedis Enhanced client: cluster routing, key prefix, data structure factory methods
RedisClient RESP protocol unit: TCP connection, command encoding/decoding (internal, pool-managed)
RedisList<T> etc. Generic data structure wrappers with unified encoding strategy
RedisReliableQueue<T> Reliable message queue (RPOPLPUSH + Ack confirmation)
RedisStream<T> Stream queue (Redis 5.0+, consumer-group mode)
IPacketEncoder Pluggable encoding/decoding strategy

Installation & Quick Start

# Stable release
dotnet add package NewLife.Redis
# ASP.NET Core extensions
dotnet add package NewLife.Redis.Extensions
# Development release (includes prereleases)
dotnet add package NewLife.Redis --prerelease

Recommended: singleton, thread-safe, reuse throughout the application lifetime:

using NewLife.Caching;
using NewLife.Log;

XTrace.UseConsole();

var rds = new FullRedis("127.0.0.1:6379", "password", 0)
{
    Log = XTrace.Log,           // Optional: component-level logging
    AutoPipeline = 100,         // Optional: auto-commit pipeline when command count reaches 100
};

// Write an object (auto JSON serialization)
rds.Set("user:1", new { Name = "Alice", Age = 30 }, expire: 3600);

// Read (auto deserialization)
var name = rds.Get<String>("user:1");
Console.WriteLine(name);

Connection string mode (recommended for config centers):

var rds = FullRedis.Create("server=127.0.0.1:6379;password=pass;db=0;timeout=3000");

Basic Usage

// Write / Read
rds.Set("k1", 123, expire: 600);
var v = rds.Get<Int32>("k1");

// Set only if key does not exist
var ok = rds.Add("k2", "init");

// Replace and return old value
var old = rds.Replace("k2", "new");

// Counters
rds.Increment("counter", 1);
rds.Decrement("counter", 2);

// Expiry management
rds.SetExpire("k1", TimeSpan.FromMinutes(10));
var ttl = rds.GetExpire("k1");

// Batch read/write
rds.SetAll(new Dictionary<String, Object> { ["a"] = 1, ["b"] = 2 }, expire: 300);
var dict = rds.GetAll<Int32>(["a", "b"]);

// Key prefix (FullRedis.Prefix)
var scoped = rds.GetPrefixed("myapp:");
scoped.Set("user", "Alice");  // Actual key is myapp:user

Data Structure Operations

List

var list = rds.GetList<String>("queue:demo");
list.Add("job1");
list.Add("job2");
var first = list[0];
var popped = list.RightPop();

Hash

var hash = rds.GetDictionary<String>("user:1001");
hash["Name"] = "Alice";
hash["Email"] = "[email protected]";
var name = hash["Name"];
var all = hash.GetAll();

Set / Sorted Set

var set = rds.GetSet<String>("tags");
set.Add("redis");
set.Add("cache");
var contains = set.Contains("redis");

var zset = rds.GetSortedSet<String>("leaderboard");
zset.Add("Player1", 100.0);
zset.Add("Player2", 95.5);
var top3 = zset.GetByRank(0, 2);

Stack

var stack = rds.GetStack<String>("undo:ops");
stack.Push("op1");
stack.Push("op2");
var last = stack.Pop();   // "op2"

Geo

var geo = rds.GetGeo("locations");
geo.Add("Beijing",  116.4074, 39.9042);
geo.Add("Shanghai", 121.4737, 31.2304);
var dist = geo.GetDistance("Beijing", "Shanghai", "km");
var nearby = geo.Search("Beijing", 500, "km");

HyperLogLog

var hll = rds.GetHyperLogLog("uv:today");
hll.Add("user1", "user2", "user3");
var count = hll.Count;  // Approximate cardinality
hll.Merge("uv:yesterday");

Note: The base Redis instance only supports KV operations. Use FullRedis for advanced collections.


Pipeline & Auto Batching

Pipeline significantly reduces network round-trips (RTT) and improves bulk operation throughput:

// Explicit pipeline
rds.StartPipeline();
for (var i = 0; i < 1000; i++) rds.Set($"p:{i}", i);
var results = rds.StopPipeline(true);

Auto mode (recommended for production):

rds.AutoPipeline = 100;    // Auto-commit when 100 write operations accumulate
rds.FullPipeline = true;   // Both reads and writes enter the pipeline (throughput-first scenarios)

Message Queues

Simple Queue

var queue = rds.GetQueue<OrderMsg>("orders");

// Producer
queue.Add(new OrderMsg { OrderId = "12345", Amount = 99.9m });

// Consumer (blocking wait; timeout=0 means block indefinitely)
var msg = queue.TakeOne(timeout: 30);

Reliable Queue (at-least-once semantics)

var queue = rds.GetReliableQueue<OrderMsg>("orders");

// Produce
queue.Add(new OrderMsg { OrderId = "12345" });

// Consume + Acknowledge
var msg = queue.TakeOne(timeout: 30);
if (msg != null)
{
    // Process the message...
    queue.Acknowledge(msg);   // Acknowledge consumption; removed from Ack queue
}
// If the process crashes without acknowledging, the message is automatically rolled back
// to the main queue after 60 seconds

Delay Queue

var delay = rds.GetDelayQueue<OrderMsg>("orders:delay");

// Available for consumption after 60 seconds
delay.Add(new OrderMsg { OrderId = "12345" }, delay: 60);

// Consume (auto-waits for due messages)
var msg = delay.TakeOne(timeout: 5);

Stream Queue (Redis 5.0+, multi-consumer-group)

var stream = rds.GetStream<LogEntry>("logs");
stream.Group = "processor-group";

// Produce
stream.Add(new LogEntry { Level = "INFO", Message = "Application started" });

// Consume (multiple instances compete within the same group)
var entry = stream.TakeOne(timeout: 15);
if (entry != null)
{
    // Process...
    stream.Acknowledge(entry.Id);
}

Publish / Subscribe

var pubsub = rds.GetPubSub("events:user");

// Publish
pubsub.Publish("login:Alice");

// Subscribe (async loop)
var cts = new CancellationTokenSource();
await pubsub.SubscribeAsync((channel, message) =>
{
    Console.WriteLine($"[{channel}] {message}");
}, cts.Token);

Clustering & High Availability

Multi-Address Auto Failover

// Comma-separated addresses; auto-failover on network errors;
// switches back to the primary node after 60 seconds
var rds = new FullRedis("10.0.0.1:6379,10.0.0.2:6379,10.0.0.3:6379", "pass", 0)
{
    ShieldingTime = 10,   // Shield unavailable nodes for 10 seconds (default)
    Retry = 3,            // Retry count (default)
};

Auto Cluster Mode Detection

// When AutoDetect=true, automatically detect the working mode via INFO
// โš ๏ธ For public cloud proxy mode, keep the default false to avoid obtaining internal node addresses
var rds = new FullRedis("sentinel-host:26379", "pass", 0)
{
    AutoDetect = true,    // Auto-detect Cluster / Sentinel / Replication
};

Cloud Provider Adapters

Alibaba Cloud KVStore / Tair

// Standard edition (Redis 2.8/4.0/5.0/6.0/7.0)
var rds = new FullRedis("xxxxxx.redis.rds.aliyuncs.com:6379", "YourPassword", 0);

// Redis 6.0 ACL user authentication
var rds = new FullRedis("xxxxxx.redis.rds.aliyuncs.com:6379", "YourUser", "YourPassword", 0);

// SSL encrypted connection
var rds = new FullRedis("xxxxxx.redis.rds.aliyuncs.com:6380", "YourPassword", 0)
{
    SslProtocol = SslProtocols.Tls12,
};

// โš ๏ธ Public cloud proxy mode: Keep AutoDetect at its default false
// โš ๏ธ Cluster edition: Proxy handles shard routing; clients don't need to know the internal topology

Tencent Cloud Redis

// Tencent Cloud standard/cluster edition: use instance ID as UserName (AUTH instanceId:password format)
var rds = new FullRedis("xxxxxx.redis.tencentcds.com:6379", "instanceId", "YourPassword", 0);

// Or via connection string
var rds = FullRedis.Create("server=xxxxxx.redis.tencentcds.com:6379;username=instanceId;password=YourPassword;db=0");

Huawei Cloud DCS

// Master/Standby edition (standard AUTH)
var rds = new FullRedis("xxxxxx.dcs.myhuaweicloud.com:6379", "YourPassword", 0);

// SSL edition (use after downloading the PEM certificate)
var rds = new FullRedis("xxxxxx.dcs.myhuaweicloud.com:6380", "YourPassword", 0)
{
    SslProtocol = SslProtocols.Tls12,
    Certificate = new X509Certificate2("huawei-dcs.pem"),
};

// โš ๏ธ Cluster edition does not support SELECT; Db must be 0
// โš ๏ธ AutoDetect = false (default) to avoid internal node address issues

General Cloud Provider Notes:

  • Public cloud proxy mode: Keep AutoDetect = false (default) to prevent auto-detection of internal nodes
  • Connection quota: Each cloud provider and instance size has connection limits; set the pool Max parameter accordingly
  • TCP keepalive: Huawei Cloud defaults to a 300-second TCP idle timeout; set Timeout below that value and periodically PING

Serialization & Encoders

Default encoder: RedisJsonEncoder (built-in JSON host), ready to use out of the box.

// Inspect current JSON configuration
var jsonHost = RedisJsonEncoder.GetJsonHost();

// Switch to a custom encoder (e.g., MessagePack)
rds.Encoder = new MyMessagePackEncoder();

Primitive types (String / Int32 / Int64 / Double / Boolean) are serialized directly without going through JSON for maximum performance.


Security & Authentication

// Redis 6.0+ ACL authentication
var rds = new FullRedis("host:6379", "username", "password", 0);

// TLS encryption (specify protocol version)
rds.SslProtocol = SslProtocols.Tls12;

// Certificate verification (mutual mTLS)
rds.Certificate = new X509Certificate2("client.pem", "certPassword");

// Connection string password encryption (ProtectedKey mechanism)
// Configure ProtectedKey.Instance.Secret; passwords in connection strings are auto-decrypted

Observability

// Structured logging
rds.Log       = XTrace.Log;      // Component-level logs (connection changes, cluster changes, retries)
rds.ClientLog = XTrace.Log;      // Protocol-level logs (every command; enable only when debugging)

// Performance counters
rds.Counter = new PerfCounter();
var stats = rds.Counter.GetAll();   // Get ops/s, latency, error rate

// APM distributed tracing (compatible with NewLife.Stardust / OpenTelemetry)
rds.Tracer = DefaultTracer.Instance;
// All Execute / queue produce-consume operations are automatically instrumented, with key as tag

// OpenTelemetry native tracing (net8.0+): subscribe to the built-in ActivitySource
// builder.Services.AddOpenTelemetry().WithTracing(t => t.AddSource(Redis.ActivitySourceName));

Extension Packages

NewLife.Redis.Extensions provides deep ASP.NET Core integration:

dotnet add package NewLife.Redis.Extensions
// Program.cs
builder.Services.AddRedisCaching(options =>
{
    options.Server   = "127.0.0.1:6379";
    options.Password = "pass";
    options.Db       = 0;
    options.Prefix   = "myapp:";
});

// Automatically registers IDistributedCache + FullRedis as singletons

// Persist data protection keys to Redis
builder.Services.AddDataProtection()
    .PersistKeysToRedis(redis, "DataProtection-Keys");

Garnet Compatibility

NewLife.Redis fully supports Microsoft's Garnet high-performance Redis-compatible server, with auto-detection and graceful degradation.

var redis = new FullRedis("127.0.0.1:7000", null, 0);

// Auto-detect server type
if (redis.IsGarnet)
    Console.WriteLine("Connected to Garnet server");

Console.WriteLine($"Server type: {redis.ServerType}");  // Redis / Garnet / Unknown
Console.WriteLine($"Server version: {redis.Version}");
Feature Garnet Support Status
String / List / Hash / Set / Sorted Set โœ… Fully supported
HyperLogLog / Geo โœ… Fully supported
Pub/Sub / Transactions / Lua Scripts โœ… Fully supported
Pipeline โœ… Fully supported
RedisQueue<T> / RedisDelayQueue<T> โœ… Fully supported
RedisReliableQueue<T> โœ… Fully supported
RedisStream<T> โŒ Garnet does not support Stream yet; automatically throws NotSupportedException with suggested alternatives

See: Garnet Compatibility Documentation (ไธญๆ–‡)


Feature Completion Status

Legend: โœ… Completed | ๐Ÿ”„ Planned | โŒ Explicitly Not Planned

Data Structures

Structure Status Description
String KV + Batch โœ… MGET/MSET/INCR/APPEND/GETRANGE, etc.
List โœ… LPUSH/RPOP/LRANGE/LMOVE, etc.
Hash โœ… HGET/HSET/HMGET/HSCAN, etc.
Set โœ… SADD/SMEMBERS/SUNION/SDIFF, etc.
Sorted Set โœ… ZADD/ZRANGE/ZPOPMIN/ZSCAN, etc.
Stream โœ… Full XADD/XREAD/XGROUP/XACK
Geo โœ… GEOADD/GEODIST/GEOSEARCH, etc.
HyperLogLog โœ… PFADD/PFCOUNT/PFMERGE
Bitmap / Bitfield ๐Ÿ”„ SETBIT/BITCOUNT/BITFIELD

Message Queues

Queue Type Status Delivery Semantics
RedisQueue<T> โœ… At most once
RedisReliableQueue<T> โœ… At least once (RPOPLPUSH + Ack)
RedisDelayQueue<T> โœ… Delayed delivery (Sorted Set)
RedisStream<T> โœ… Ordered + Consumer Group + XACK
MultipleConsumerGroupsQueue<T> โœ… Multi-consumer-group broadcast
PubSub + RedisEventBus โœ… Real-time push
RedLock Distributed Lock ๐Ÿ”„ Multi-instance Redlock algorithm

Cluster Support

Mode Status
Standalone โœ…
Master-Replica Replication โœ…
Sentinel โœ…
Native Cluster โœ…
kvrocks Auto-Adapt โœ…
Garnet Auto-Detect โœ…
Valkey Auto-Detect โœ…

Protocol & Advanced Features

Feature Status
RESP2 Full Support โœ…
RESP3 โœ…
SSL/TLS โœ…
ACL Authentication โœ…
Transactions MULTI/EXEC/WATCH โœ…
Lua Scripts EVAL/EVALSHA โœ…
Redis Functions ๐Ÿ”„ Planned
Pipeline (Explicit + Auto) โœ…
Pattern Subscription PSUBSCRIBE ๐Ÿ”„
UNLINK Async Delete ๐Ÿ”„

Performance Benchmarks

Built-in benchmark in source (Samples/Benchmark), typical results (40 logical processors, local Redis 7.0):

Write 400,000 items | 4 threads  | ~576,368 ops/s
Read  800,000 items | 8 threads  | ~647,249 ops/s
Delete 800,000 items | 8 threads | ~1,011,378 ops/s
Batch Write (pipeline) | 4 threads | ~1,800,000 ops/s

Manual bench trigger:

rds.Bench(rand: true, batch: 100);  // Random keys + batch optimization

Actual performance is affected by network RTT / value size / serialization complexity. It is recommended to keep individual values between 1โ€“1.4KB.


Best Practices

  • Singleton reuse: FullRedis has an internal connection pool; strongly recommend using a single instance for the entire application lifetime โ€” do not new each time
  • Key design: Use : as a hierarchical separator, e.g., user:1001:profile; use Prefix for namespace isolation in production
  • Batch first: Prefer GetAll/SetAll over looping single-key operations; use AutoPipeline to auto-merge write operations
  • Value size: Keep values within 1โ€“2KB; split large objects / compress / use Hash for field-level storage
  • Reliable consumption: Use RedisReliableQueue<T> in production rather than a simple List to avoid message loss
  • Cloud providers: Keep AutoDetect = false on public clouds to avoid internal node address issues
  • Monitoring: Enable Counter statistics in production; only enable ClientLog when debugging to avoid hot-path logging overhead
  • SSL: Enable TLS encrypted transport on public clouds and in production environments

FAQ

Q: Does it support Redis Cluster sharding? A: Yes. FullRedis auto-detects Cluster mode with AutoDetect=true. CRC16 routing, MOVED/ASK redirections are all implemented. For public cloud proxy mode, keep the default AutoDetect=false.

Q: How does it compare to StackExchange.Redis? A: NewLife.Redis uses a connection-pool model (vs. StackExchange's multiplexing) for more intuitive connection behavior. Built-in message queue wrappers (reliable queue / delay queue) are a key differentiator. It also supports .NET Framework 4.5. See Competitive Analysis (ไธญๆ–‡).

Q: How to handle slow queries caused by large values? A: Split data structures (e.g., Hash per-field) + batch reads/writes + binary encoder + control MaxMessageSize (default 1MB limit).

Q: What if the connection pool runs out? A: The default max is 100,000 connections; normal workloads won't exhaust it. The pool is configurable via Redis.PoolConfig (RedisPoolConfig): min idle / max capacity / idle cleanup time / max lifetime / borrow wait timeout. Connections idle beyond IdleTime are proactively PING-checked when leased; for master-slave switch or rolling proxy update scenarios, lower MaxLifetime to recycle connections faster. If you see wait timeouts, check for connection leaks (missing Dispose) or operations that hold connections for excessively long periods.

Q: Why do connections fail on Alibaba Cloud / Tencent Cloud? A: Check: โ‘  Is AutoDetect set to false (correct default)? โ‘ก Is the auth format correct (Tencent Cloud requires username=instanceId)? โ‘ข Are the network security group / whitelist allowing the client IP? โ‘ฃ Does the cluster edition prohibit using SELECT to switch databases?

Q: Does Garnet support all features? A: Basic operations, List/Hash/Set/ZSet/HLL/Geo, and queues are all supported. Stream is not yet supported and will automatically throw NotSupportedException with a suggestion to use RedisQueue<T> as an alternative.


Roadmap

  • RESP3 protocol support (Completed)
  • Redis Functions (FCALL/FUNCTION, replacing Lua scripts)
  • LMPOP / ZMPOP (Redis 7.0 batch pop)
  • RedLock multi-instance distributed lock
  • Bitmap / Bitfield operations
  • Pattern subscription PSUBSCRIBE full implementation
  • UNLINK async delete
  • Prometheus metrics export adapter
  • Alibaba Cloud Tair Extension (TairString / TairHash / TairZSet supported)
  • Huawei Cloud DCS cluster edition node address mapping adapter
  • Pub/Sub (Completed)
  • RedisStream multi-consumer-group (Completed)
  • Garnet server type detection (Completed)

Feedback and feature requests welcome via Issue / PR.


Competitive Comparison

Capability NewLife.Redis StackExchange.Redis FreeRedis Notes
.NET Framework 4.5 โœ… โŒ (4.6.1+) โŒ Critical for industrial/gov legacy systems
Connection Model Connection Pool Multiplexing Connection Pool Each has its use cases
Command Coverage ~98% ~95% ~98% All documented commands except explicitly unplanned ones
Built-in Message Queue Wrappers โœ… Complete โŒ ๐Ÿ”„ Partial Unique reliable/delay queues
Built-in Serialization โœ… โŒ Manual โŒ Manual Reduces boilerplate code
Cloud Provider Specialized Adapters โœ… (Alibaba/Tencent/Huawei) Generic Generic Dedicated documentation
Garnet Explicit Adapter โœ… โŒ โŒ Type detection + graceful degradation
kvrocks Adapter โœ… โŒ โŒ Auto-detection
Valkey Auto-Detect โœ… โŒ โŒ INFO server=valkey / valkey_version
APM Tracing ITracer + ActivitySource (net8.0+) ActivitySource โŒ Native OpenTelemetry integration
RESP3 โœ… โœ… โœ… Verified via RESP3 test suite

See Competitive Analysis Document (ไธญๆ–‡) for details.


NewLife Project Matrix

Project Description
NewLife.Core Core library: logging / config / caching / serialization / APM
NewLife.XCode Big-data ORM, billions of records + sharding + read/write separation
NewLife.Net Ultra-high-performance networking library (tens of millions throughput)
Stardust Distributed service / config / registry / publish center
AntJob Distributed computing & scheduling platform
NewLife.RocketMQ RocketMQ pure managed client

Full matrix, enterprise solutions, and commercial support: https://newlifex.com


Contributing & Community

  1. Before submitting, read the repository .github/copilot-instructions.md (coding standards & review checklist)
  2. PRs: Keep changes minimal, add necessary comments and test descriptions
  3. Issues: Provide version, runtime environment, and a minimal reproduction scenario

Community: QQ groups 1600800 / 1600838; GitHub Discussions / Issues.


License

MIT License. Free to use commercially / modify / redistribute (no additional authorization required). Just retain the copyright notice.


NewLife Development Team

XCode

Since 2002, the team has maintained 80+ .NET / IoT / distributed open-source projects, with over 4 million cumulative NuGet downloads. Products and components are widely used in electric power, logistics, industrial control, education, telecommunications, cultural heritage, and other industries.

Website: https://newlifex.com | Open Source: https://github.com/NewLifeX

WeChat Official Account:

ๆ™บ่ƒฝๅคง็Ÿณๅคด


If this document doesn't cover your use case, feel free to submit an Issue โ€” let's improve the documentation together!

Changes from Previous Version

No structural changes between v6.6.2026.1019-beta0424 and v6.6.2026.1019-beta1511.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 5 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.