NRedisStack 指南 (C#/.NET)
将 .NET 应用程序连接到 Redis 数据库
NRedisStack 是 Redis 的 .NET 客户端。
以下部分介绍了如何安装NRedisStack
并连接您的应用程序
添加到 Redis 数据库。
NRedisStack
需要正在运行的 Redis 或 Redis Stack 服务器。请参阅 Redis 安装说明入门。
您还可以使用对象映射客户端界面访问 Redis。有关更多信息,请参阅适用于 .NET 的 Redis OM。
安装
使用dotnet
CLI 中,运行:
dotnet add package NRedisStack
Connect and test
Connect to localhost on port 6379.
using NRedisStack;
using NRedisStack.RedisStackCommands;
using StackExchange.Redis;
//...
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
You can test the connection by storing and retrieving a simple string.
db.StringSet("foo", "bar");
Console.WriteLine(db.StringGet("foo")); // prints bar
Store and retrieve a HashMap.
var hash = new HashEntry[] {
new HashEntry("name", "John"),
new HashEntry("surname", "Smith"),
new HashEntry("company", "Redis"),
new HashEntry("age", "29"),
};
db.HashSet("user-session:123", hash);
var hashFields = db.HashGetAll("user-session:123");
Console.WriteLine(String.Join("; ", hashFields));
// Prints:
// name: John; surname: Smith; company: Redis; age: 29
Redis Stack modules
To access Redis Stack capabilities, use the appropriate interface like this:
IBloomCommands bf = db.BF();
ICuckooCommands cf = db.CF();
ICmsCommands cms = db.CMS();
IGraphCommands graph = db.GRAPH();
ITopKCommands topk = db.TOPK();
ITdigestCommands tdigest = db.TDIGEST();
ISearchCommands ft = db.FT();
IJsonCommands json = db.JSON();
ITimeSeriesCommands ts = db.TS();
More information
See the other pages in this section for more information and examples.
On this page