我需要用到一些与set操作相关的redis命令。我正在使用 StackExchange.Redis 连接到我的 redis 服务器并执行所需的操作。具体我需要进行以下操作
- 将项目添加到集合 (SADD)
- 检查两组之间的差异 (SDIFF)
- 获取两组之间的共同元素(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
关于redis - 使用 StackExchange.Redis 中的 REDIS Sets 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37070124/