3

I need to use some redis commands related to set operations. I am using StackExchange.Redis to connect to my redis server and perform the required operations. Specifically I need to perform the following operations

  • Add Item to Set (SADD)
  • Check Difference between two sets (SDIFF)
  • Get the common elements between 2 sets (SINTER)

I am able to see SetAdd in the IDatabase interface but how can I get the SDIFF and SINTER command?

1 Answer 1

5

You should use the method IDatabase.SetCombine() for commands SDIFF, SUNION or 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);

Where SetOperation can be Union, Intersect or Difference

Take a look at some of the tests

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.