redis - 使用 StackExchange.Redis 中的 REDIS Sets 命令

标签 redis stackexchange.redis

我需要用到一些与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可以是UnionIntersectDifference

看看一些 tests

关于redis - 使用 StackExchange.Redis 中的 REDIS Sets 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37070124/

相关文章:

python - 在写入它的函数内部或全局外部打开与 Redis 数据库的连接是一种好习惯吗?

ruby-on-rails - Resque 或 Gearman - 为后台作业选择合适的工具

c# - 无法将 Redis.RedisValue 转换为 Task<T>

asp.net-mvc - 使用自定义输出缓存提供程序 RedisOutputCacheProvider 时出现 ProviderException

docker - StackExchange.Redis.RedisConnectionException : No connection (requires writable - not eligible for replica)

memory-leaks - 如何判断Redis内存泄漏?

redis-cli : Unrecognized option or bad number of args for: '--tls'

ruby - 如何保存和展示 Dashing 的历史值?

caching - 使用来自多台机器的外部查询结果更新 Redis

redis - Redis集群如何启动一定数量的节点