使用 StackExchange.Redis 中的 REDIS 集命令
Using REDIS Sets command from StackExchange.Redis
我需要用到一些与set操作相关的redis命令。我正在使用 StackExchange.Redis 连接到我的 redis 服务器并执行所需的操作。具体我需要进行以下操作
- 将项目添加到集合 (SADD)
- 检查两组之间的差异 (SDIFF)
- 获取 2 组之间的共同元素 (SINTER)
我可以在 IDatabase 界面中看到 SetAdd,但我怎样才能获得 SDIFF 和 SINTER 命令?
对于命令 SDIFF、SUNION 或 SINTER,您应该使用方法 IDatabase.SetCombine()
。
/// <summary>
/// Returns the members of the set resulting from the specified operation against the given sets.
/// </summary>
/// <returns>list with members of the resulting set.</returns>
/// <remarks>http://redis.io/commands/sunion</remarks>
/// <remarks>http://redis.io/commands/sinter</remarks>
/// <remarks>http://redis.io/commands/sdiff</remarks>
RedisValue[] SetCombine(SetOperation operation, RedisKey first, RedisKey second, CommandFlags flags = CommandFlags.None);
其中 SetOperation
可以是 Union
、Intersect
或 Difference
看看一些 tests
我需要用到一些与set操作相关的redis命令。我正在使用 StackExchange.Redis 连接到我的 redis 服务器并执行所需的操作。具体我需要进行以下操作
- 将项目添加到集合 (SADD)
- 检查两组之间的差异 (SDIFF)
- 获取 2 组之间的共同元素 (SINTER)
我可以在 IDatabase 界面中看到 SetAdd,但我怎样才能获得 SDIFF 和 SINTER 命令?
对于命令 SDIFF、SUNION 或 SINTER,您应该使用方法 IDatabase.SetCombine()
。
/// <summary>
/// Returns the members of the set resulting from the specified operation against the given sets.
/// </summary>
/// <returns>list with members of the resulting set.</returns>
/// <remarks>http://redis.io/commands/sunion</remarks>
/// <remarks>http://redis.io/commands/sinter</remarks>
/// <remarks>http://redis.io/commands/sdiff</remarks>
RedisValue[] SetCombine(SetOperation operation, RedisKey first, RedisKey second, CommandFlags flags = CommandFlags.None);
其中 SetOperation
可以是 Union
、Intersect
或 Difference
看看一些 tests