使用 StackExchange.Redis 中的 REDIS 设置命令

Pra*_*rya 3 redis stackexchange.redis

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

  • 添加项目到集合 (SADD)
  • 检查两组之间的差异 (SDIFF)
  • 获取 2 个集合之间的公共元素 (SINTER)

我可以在 IDatabase 界面中看到 SetAdd,但如何获取 SDIFF 和 SINTER 命令?

the*_*000 5

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);
Run Code Online (Sandbox Code Playgroud)

SetOperation可以在哪里UnionIntersect或者Difference

看看一些测试