NewLife.Redis
้ซๆง่ฝRedisๅฎขๆท็ซฏ๏ผๆฏๆRESP2/RESP3ๅ่ฎฎ๏ผ่ฆ็Redis 2.8๏ฝ7.xๅ จ้จๆฐๆฎ็ปๆไธๅฝไปค๏ผๅ ็ฝฎๆถๆฏ้ๅ๏ผ็ฎๅ/ๅฏ้ /ๅปถ่ฟ/Stream๏ผ๏ผๆฏๆ้็พค/ๅจๅ ต/ไบๅๅ้้ ๏ผ็ปๆฅๅ80+ไบฟๆฌก่ฐ็จ้ช่ฏ
Install
| Product | Versions |
|---|---|
| .NET | |
| .NET Standard | |
| Other |
README
NewLife.Redis โ High-Performance Redis Client Component
๐ ็ฎไฝไธญๆ | ็น้ซไธญๆ | 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
- NewLife.Redis โ High-Performance Redis Client Component
- Table of Contents
- Introduction
- Core Features
- Redis Protocol & Version Support
- Architecture & Module Breakdown
- Installation & Quick Start
- Basic Usage
- Data Structure Operations
- Pipeline & Auto Batching
- Message Queues
- Publish / Subscribe
- Clustering & High Availability
- Cloud Provider Adapters
- Serialization & Encoders
- Security & Authentication
- Observability
- Extension Packages
- Garnet Compatibility
- Feature Completion Status
- Performance Benchmarks
- Best Practices
- FAQ
- Roadmap
- Competitive Comparison
- NewLife Project Matrix
- Contributing & Community
- License
- NewLife Development Team
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
ITracerdistributed tracing +PerfCounterperformance 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
Redisinstance only supports KV operations. UseFullRedisfor 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
Maxparameter accordingly - TCP keepalive: Huawei Cloud defaults to a 300-second TCP idle timeout; set
Timeoutbelow 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:
FullRedishas an internal connection pool; strongly recommend using a single instance for the entire application lifetime โ do notneweach time - Key design: Use
:as a hierarchical separator, e.g.,user:1001:profile; usePrefixfor namespace isolation in production - Batch first: Prefer
GetAll/SetAllover looping single-key operations; useAutoPipelineto 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 = falseon public clouds to avoid internal node address issues - Monitoring: Enable
Counterstatistics in production; only enableClientLogwhen 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
- Before submitting, read the repository
.github/copilot-instructions.md(coding standards & review checklist) - PRs: Keep changes minimal, add necessary comments and test descriptions
- 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

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
Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.