使用来自StackExchange.Redis的REDIS Sets命令

时间:2016-05-06 10:30:35

标签: redis stackexchange.redis

我需要使用一些与set操作相关的redis命令。我正在使用StackExchange.Redis连接到我的redis服务器并执行所需的操作。具体来说,我需要执行以下操作

  • 添加要设置的项目(SADD)
  • 检查两组之间的差异(SDIFF)
  • 获取2套(SINTER)之间的共同元素

我能够在IDatabase界面中看到SetAdd但是如何获得SDIFF和SINTER命令?

1 个答案:

答案 0 :(得分:4)

您应该使用方法IDatabase.SetCombine()执行命令SDIFF,SUNION或SINTER。

    /// <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