关于redis:Redis的底层类型之set

7次阅读

共计 1330 个字符,预计需要花费 4 分钟才能阅读完成。

sets

A Redis set is an unordered collection of unique strings (members).
无序的字符串汇合

相干命令:

  • SADD
SADD key member [member ...]
  • SREM
SREM key member [member ...]
  • SMEMBERS

Returns all the members of the set value stored at key.

  • SISMEMBER
SISMEMBER key member

Returns if member is a member of the set stored at key.1 if the element is a member of the set.0 if the element is not a member of the set, or if key does not exist.

  • SMISMEMBER

Returns whether each member is a member of the set stored at key.

SMISMEMBER key member [member ...]
  • SINTER

    SINTER key [key ...]

    Returns the members of the set resulting from the intersection of all the given sets. 求交加

  • SCARD

Returns the set cardinality (number of elements) of the set stored at key.
计算汇合中的基数,其实就是 set 中元素的总数量,因为 set 是没有反复的。

  • SDIFF
SDIFF key [key ...]

Returns the members of the set resulting from the difference between the first set and all the successive sets.

返回第一个汇合和残余汇合的差集,是指蕴含在第一个汇合中但不蕴含在其余汇合中的元素。

  • SDIFFSTORE
SDIFFSTORE destination key [key ...]

This command is equal to SDIFF, but instead of returning the resulting set, it is stored in destination.

  • SINTERCARD

This command is similar to SINTER, but instead of returning the result set, it returns just the cardinality of the result.

返回:后果交集中的元素数

  • SINTERSTORE

This command is equal to SINTER, but instead of returning the resulting set, it is stored in destination.

  • SMOVE

将 member 元素从 source 汇合挪动到 destination 汇合

  • SPOP

移除并返回汇合中的一个随机元素

  • SSCAN

Redis Sscan 命令用于迭代汇合中键的元素。

SADD myset1 "hello"
SADD myset1 "hi"
SADD myset1 "bar"
sscan myset1 0 match h*

1) "0"
2) 1) "hello"
   2) "h1"
  • SUNION
  • SUNIONSTORE
正文完
 0