Redis基本数据类型:集合(set)
Redis内部使用两种结构来实现set
- 哈希表(hashtable)
- 整数集合(intset)
1. 哈希表(hashtable)
在介绍哈希类型时已经提过了,这里就略过了
使用这种结构时,redisObject.encoding = OBJ_ENCODING_HT
2. 整数集合(intset)
当插入的值是整数时,Redis会使用intset结构来保存数据
使用这种结构时,redisObject.encoding = OBJ_ENCODING_INTSET
intset定义如下:
typedef struct intset {
uint32_t encoding;
uint32_t length;
int8_t contents[];
} intset;
- encoding - 数据的内部编码方式,现在有三种,分别对应int16,int32,int64
- length - 元素个数
- contents - 存储元素数组
3. command
- SADD - Add one or more members to a set
- SCARD - Get the number of members in a set
- SDIFF - Subtract multiple sets
- SDIFFSTORE - Subtract multiple sets and store the resulting set in a key
- SINTER - Intersect multiple sets
- SINTERSTORE - Intersect multiple sets and store the resulting set in a key
- SISMEMBER - Determine if a given value is a member of a set
- SMEMBERS - Get all the members in a set
- SMOVE - Move a member from one set to another
- SPOP - Remove and return one or multiple random members from a set
- SRANDMEMBER - Get one or multiple random members from a set
- SREM - Remove one or more members from a set
- SSCAN - Incrementally iterate Set elements
- SUNION - Add multiple sets
- SUNIONSTORE - Add multiple sets and store the resulting set in a key
上一篇:Redis学习小计(6) - 基本数据类型:哈希(hash)
下一篇:Redis学习小计(8) - 基本数据类型:有序集合(sorted set)