Redis set of command
The following table lists the Redis set of basic commands:
No. | Command and description |
---|---|
1 | SADD key member1 [member2] to add one or more members to the collection |
2 | SCARD key Gets the number of members of the collection |
3 | SDIFF key1 [key2] Returns all differences for a given set of Assembly |
4 | SDIFFSTORE destination key1 [key2] Returns all differences for a given set of set and stored in the destination |
5 | SINTER key1 [key2] returned to the intersection of a given set of all |
6 | SINTERSTORE destination key1 [key2] Returns the intersection of all the given set and stored in the destination |
7 | SISMEMBER key member to determine whether the member is a member of the set of key elements of |
8 | SMEMBERS key return all the members of the collection |
9 | The SMOVE source destination member to the mobile member from the source element to the destination collection set |
10 | SPOP key is removed and returns a random element in the set |
11 | SRANDMEMBER key [count] Returns a collection or plurality of random numbers |
12 | SREM key member1 [member2] to remove one or more members of the set of |
13 | SUNION key1 [key2] return all of the given set and set |
14 | SUNIONSTORE destination key1 [key2] in the set of all destination and set a given set of storage |
15 | SSCAN key cursor [MATCH pattern] [ COUNT count] iterations elements in the collection |
Examples are as follows:
127.0.0.1:6379> SADD users a1 a2 a3 a4
(integer) 4
127.0.0.1:6379> SMEMBERS users
1) "a1"
2) "a4"
3) "a2"
4) "a3"
127.0.0.1:6379> SREM users a1
(integer) 1
127.0.0.1:6379> SMEMBERS users
1) "a4"
2) "a2"
3) "a3"
127.0.0.1:6379> SCARD users
(integer) 3
127.0.0.1:6379> SISMEMBER users a1
(integer) 0
127.0.0.1:6379>
Business scene
Sets 3 content hobby when each user first use headlines today, but the latter in order to increase the degree of active users, points of interest, the user must be
increasingly interested in other categories of information, increase customer retention degree, how to achieve?
Business analysis
system to analyze the latest or hottest entries in each category of information organized into a set and a set of
randomly selected some of the information
with the full set of information users concerned about the hot spot information to organize information into categories show
127.0.0.1:6379> SADD role r1 r2 r3 r4
(integer) 4
127.0.0.1:6379> SRANDMEMBER role
"r1"
127.0.0.1:6379> SRANDMEMBER role
"r3"
127.0.0.1:6379> SRANDMEMBER role
"r4"
127.0.0.1:6379> SRANDMEMBER role
"r1"
127.0.0.1:6379> SRANDMEMBER role
"r2"
127.0.0.1:6379> SPOP role
"r3"
127.0.0.1:6379> SPOP role
"r2"
127.0.0.1:6379> SMEMBERS role
1) "r4"
2) "r1"
127.0.0.1:6379>
redis recommendation applies to random class information retrieval, such as hot song single recommendation, recommend hot news, hot tourist routes, application APP recommended, recommended and other large V
extended operation set the type of data
micro-channel public number is one channel micro-channel flow of information, increasing the number of users of public attention as a way to increase user activity, and how to help
users accumulate more number of public concern?
US group into a single takeaway in order to enhance the amount of food necessary to help users tap the demand, how to recommend to the user the most suitable for their own food?
127.0.0.1:6379> sadd u a1 b1 c1
(integer) 3
127.0.0.1:6379> sadd uu a1 b2
(integer) 2
127.0.0.1:6379> sadd u22 a2
(integer) 1
127.0.0.1:6379> SINTER u uu
1) "a1"
127.0.0.1:6379> sunion u uu
1) "a1"
2) "c1"
3) "b2"
4) "b1"
127.0.0.1:6379> sdiff u uu
1) "c1"
2) "b1"
127.0.0.1:6379> SDIFF uu u
1) "b2"
127.0.0.1:6379> sinterstore uuu u uu
(integer) 1
127.0.0.1:6379> SMEMBERS uuu
1) "a1"
127.0.0.1:6379> sunionstore uuuu u uu
(integer) 4
127.0.0.1:6379> SMOVE u uu c1
(integer) 1
127.0.0.1:6379> SMEMBERS u
1) "a1"
2) "b1"
127.0.0.1:6379> SMEMBERS uu
1) "c1"
2) "a1"
3) "b2"
127.0.0.1:6379>
redis 应用于同类信息的关联搜索,二度关联搜索,深度关联搜索显示共同关注(一度)
显示共同好友(一度)
由用户A出发,获取到好友用户B的好友信息列表(一度)
由用户A出发,获取到好友用户B的购物清单列表(二度)
由用户A出发,获取到好友用户B的游戏充值列表(二度)
业务场景
集团公司共具有12000名员工,内部OA系统中具有700多个角色,3000多个业务操作,23000多种数据,每
位员工具有一个或多个角色,如何快速进行业务操作的权限校验?
127.0.0.1:6379> sadd r01 getall getById
(integer) 2
127.0.0.1:6379> sadd r02 getall insert
(integer) 2
127.0.0.1:6379> SUNIONSTORE u07 r01 r02
(integer) 3
127.0.0.1:6379> SMEMBERS u07
1) "getall"
2) "insert"
3) "getById"
127.0.0.1:6379> SISMEMBER u07 insert
(integer) 1
127.0.0.1:6379>