Redis Set Command

Source: Internet
Author: User

?

?

1.Set

Set is an unordered collection of type string, and its reference source should belong to the set in the STL.

?

The set element can contain a maximum of (2 of 32 square-1) elements.

The set is implemented by a hash table, and the hash table is automatically resized as it is added or deleted.

?

?

2. CRUD

    • Smembers:

      Smembers key returns all elements of the set corresponding to the key, the result is unordered

    1. Smembers S1

    • Sadd:

      Sadd Key member adds a string element to the set set of key corresponding to the successful return 1, if the element and the set returned in the collection 0,key the corresponding set does not exist return error

    1. Sadd S1 Hello

?

    • Srem:

      Srem Key member removes the given element from the key corresponding set, returns 1 successfully, if the member does not exist in the collection or the key does not exist return 0, if the key corresponding to a value other than the set type returns an error

    1. Srem S1 Hello

    • Spop

      Spop key deletes and returns the key corresponding to a random element in the set, if the set is null or the key does not exist return nil.

    1. Spop S1

?

    • Srandmember:

      Srandmember key with Spop, randomly takes an element in set, but does not delete the element.

    1. Srandmember S1

?

    • Smove:

      Smove Srckey Dstkey member remove Srckey from the member corresponding set and add it to the dstkey corresponding set, the entire operation is atomic. A successful return of 1 if member does not exist in Srckey returns 0 if key is not a set type that returns an error.

    1. Smove S1 S2 Hello3

?

    • Sismember:

      Sismember Key member determines whether the member is in set, there is a return 1,0 that does not exist or the key does not exist.

    1. Sismember S1 Hello4

?

    • SCard:

      SCard Key returns the number of elements of set, if set is empty or key does not exist return 0

    1. SCard S2

    • ?

?

3. Collection commands

    • Sinter

      Sinter key1 Key2...keyn Returns the intersection of all given keys

    1. sinter S1 s2

?

    • Sinterstore:

      Sinterstore Dstkey Key1...keyn with Sinter, but will also save the intersection to Dstkey

    1. Sinterstore S3 S1 S2

?

    • Sunion (for a set of two sets, similar to sinter)
    • Sunionstore (Find the set of two sets and store them in the third collection, similar to Sinterstore)
    • Sdiff (Find the difference set of two sets, similar to sinter)
    • Sdiffstore (Find the set of two sets and store them in the third collection, similar to Sinterstore)

Redis Set Command

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.