Redis's set is an unordered collection of type string. The set element can contain a maximum of (2 of 32 square-1) elements. The set is implemented by hash table, so the complexity of adding, deleting, and finding is O (1). The hash table is automatically resized as it is added or removed. It is important to note that when adjusting the hash table size, synchronization (acquisition of write locks) is required to block other read and write operations. It is possible that a skip list will be used instead of a jump table, which is already in use in sorted set. For the Set collection type in addition to the basic add-delete operation, other useful operations include the collection's union, intersection (intersection), and difference set (difference). Through these actions can easily realize the SNS in the Friend referral and blog tag function.
Set related commands:
Sadd Key member adds a string element to the set set that corresponds to key, successfully returns 1 if the element has returned 0 in the collection
scard Key Returns the number of elements of set, if set is empty or key does not exist return 0
smembers Key Returns all elements of the set corresponding to the key, the result is unordered
Sismember Key member determine if member is in set, there is a return 1,0 that does not exist or key does not exist
Srandmember key with Spop, randomly takes an element in set, but does not delete the element
spop key deletes and returns the key corresponding to a random element in set, if set is empty or key does not exist return nil
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
Smove srckey Dstkey member remove the member from the Srckey corresponding set and add it to the dstkey corresponding set, the entire operation is atomic. Successful return 1 if member does not exist in Srckey returns 0 if key is not a set type return error
Redis Learning Note (v)-set type of data type