String
Search in string type keys
search pattern operator value
Prepare testing data.
set test1 'this is testing'
> OK
set test2 'this is article'
> OK
set test3 kris
> OK
set test4 10
> OK
set test5 100
> OK
= : Exact match
Find exact matches and output keys and values
search test* = kris
1) test3
2) kris
~ : Partial match
Search for partial matches
search test* ~ is
1) test2
2) this is article
3) test1
4) this is testing
5) test3
6) kris
<、>、<=、>= : Compare search
Find eligible numbers
search test* > 20
1) test5
2) 100
HASH
hsearch pattern field operator value ...
Search in the HASH type, all conditions must be met at the same time.
Prepare test data
hmset user:001 name kris email c2u@live.cn gender male age 16
> OK
hmset user:002 name sunny age 24
> OK
Search for keys and values with age greater than 18, and print the name field
hsearch user:* age > 18 name = *
1) user:002
2) 24
3) sunny
horsearch pattern field operator value ...
Search for the hash value, except for "field = *", which satisfies one condition.
horsearch user:* age > 18 gender = male name = *
1) user:002
2) 24
3)
4) sunny
5) user:001
6) 16
7) male
8) kris
hsearchids pattern [num of ids] id1 id2 ... field operator value ...
Search in specified ID
hsearchids user: 2 001 002 age > 18 name = *
1) user:002
2) 24
3) sunny
hselect [num of fields] field1 field2 ... key1 key2 ...
Print out the value of the specified field for the specified key.
hselect 3 name email age user:001 user:002
1) user:001
2) kris
3) c2u@live.cn
4) 16
5) user:002
6) sunny
7)
8) 24
hmgetall key1 key2 ...
Print out all fields and values of the specified key, each key separated by two consecutive empty data
hmgetall user:001 user:002
1) user:001
2) name
3) kris
4) email
5) c2u@live.cn
6) gender
7) male
8) age
9) 16
10)
11)
12) user:002
13) name
14) sunny
15) age
16) 24
17)
18)
hsetzsetkeys hashpattern hashid field keys zsetpattern score
** Deprecated **
Set keywords for hash keys and create indexes
hsetzsetkeys user: 001 skills java,php skill: 10001
1) 2
Equal to
zadd skill:java 10001 001
zadd skill:php 10001 001
hset user:001 skills java,php
hincrby key field increment [start]
Increase the value of the specified field in the hash set specified by key. Start is the default value. If the original value exists, start has no effect:
hincrby article:00test show 1
> 1
hincrby article:00test show 1 1000
> 2
hincrby article:00test visit 1 1000
> 1001
List
lxrange key from to
Find range values from an ordered list
lpush records 10 11 20 34 54 84 130 210
> 8
lxrange records 12 60
1) 54
2) 34
3) 20
lxsearch key value
Find a value from an ordered list
lxsearch records 54
> 3
lxinsert key value
Create a small to large sequence and return new location information
lxinsert order 9
> 0
lxinsert order 5
> 0
lxinsert order 13
> 2
lxinsert order 7
> 1
lxrange order 0 10000
1) 5
2) 7
3) 9
4) 13
lxinsertdesc key value
Insert numbers from big to small sequence and return new position information
lxinsertdesc numbers 9
> 0
lxinsertdesc numbers 5
> 1
lxinsertdesc numbers 13
> 0
lxinsertdesc numbers 7
> 2
lxrange numbers 0 10000
1) 13
2) 9
3) 7
4) 5
Sorted Set
zexists key member1 member2 ...
Get the number of keys in the sorts set
zexists tags zbc efg hi
> 0
zadd tags 1000 zbc 2000 efg 3000 hi
> 3
zexists tags zbc efg hi
> 3
zrangehmget key from to schema field1 ...
Get the corresponding field value of the corresponding HASH key in zset.
Prepare test data
upsert article id @=1000 002 name = dota age = 30 num = 28
upsert article id @=2000 003 name = like age = 40 num = 32
upsert article id @=3000 004 name = good age = 50 num = 34
*article stores article ID
zrange *article 0 -1 WITHSCORES
1) 002
2) 1000
3) 003
4) 2000
5) 004
6) 3000
Take out all the keys in article, and output all the keys and values of article:
将article中的key全部取出,并输出所有 article: 的键和值
zrangehmget *article 0 10 article:
1) 002 [member in zset]
2) 1000 [score in zset]
3) id [field]
4) 002 [value]
5) name
6) dota
7) age
8) 30
9) num
10) 28
11)
12)
13) 003
14) 2000
15) id
16) 003
17) name
18) like
19) age
20) 40
21) num
22) 32
23)
24)
25) 004
26) 3000
27) id
28) 004
29) name
30) good
31) age
32) 50
33) num
34) 34
35)
36)
Output the name and age field values of article:*
zrangehmget *article 1 2 article: name age
1) 003
2) 2000
3) like
4) 40
5)
6)
7) 004
8) 3000
9) good
10) 50
11)
12)
zrevrangehmget key from to schema field1 ...
Print in reverse order, corresponding hash in zset
zrevrangehmget *article 1 2 article: name age
1) 003
2) 2000
3) like
4) 40
5)
6)
7) 002
8) 1000
9) dota
10) 30
11)
12)
zrangehmgetbyscore key from to schema field1 ...
Output the corresponding HASH from the specified zset field by weight
zrangehmgetbyscore *article 1500 2200 article:
1) 003 [number in zset]
2) 2000 [score]
3) id [field]
4) 003 [value]
5) name
6) like
7) age
8) 40
9) num
10) 32
11)
12)
Output specified fields:
zrangehmgetbyscore *article 1500 2200 article: name
1) 003
2) 2000
3) like
4)
5)
zrevrangehmgetbyscore key from to schema field1 ...
Reverse order output
zrevrangehmgetbyscore *article 2200 1500 article: name
1) 003
2) 2000
3) like
4)
5)
zrangehmsum key from to schema field1 ...
Obtain the corresponding hash key from the ordered list and find the sum of the field values
zrangehmsum *article 0 10 article: age num
1) 3 [the number of elements in zset]
2) 3 [the number of elements exist in article:*]
3) 3 [count of age]
4) 120 [sums of age]
5) 3
6) 94
zrevrangehmsum key from to schema field1 ...
In reverse order of the ordered list, find the sum of the corresponding HASH key values
zrevrangehmsum *article 0 1 article: age num
1) 2
2) 2
3) 2
4) 90
5) 2
6) 66
zrangehmsumbyscore key score1 score2 schema field1 ...
Get the key from the range according to the score, find the corresponding hash, and find the sum of the field values
zrangehmsumbyscore *article 1500 2200 article: age num
1) 1 [the number of elements in zset]
2) 1 [the umber of elements exists in article:*]
3) 1 [count of age]
4) 40 [sums of age]
5) 1
6) 32
zrevrangehmsumbyscore key score1 score2 schema field1 ...
Sum in reverse order
zrevrangehmsumbyscore *article 2200 1500 article: age num
1) 1
2) 1
3) 1
4) 40
5) 1
6) 32
zhsearch key from to schema field operator value ...
Search for the corresponding hash from zset
upsert blog id @ 001 title = "God like" poster = dota visit = 10
upsert blog id @ 002 title = "First blood" poster = dota visit = 200
upsert blog id @ 003 title = "test title" poster = like visit = 40
zhsearch *blog 0 100 blog: visit > 28 poster = *
1) -1
2) blog:002
3) 200
4) dota
5) blog:003
6) 40
7) like
zrevhsearch key from to schema field operator value ...
Reverse search
zrevhsearch *blog 0 100 blog: visit > 28 poster = *
1) -1
2) blog:003
3) 40
4) like
5) blog:002
6) 200
7) dota
zhorsearch zsetkey from to schema field operator value ...
Or conditional search
zhorsearch *blog 0 100 blog: visit > 40 poster = like
1) -1
2) blog:002
3) 200
4) dota
5) blog:003
6) 40
7) like
zrevhorsearch zsetkey from to schema field operator value ...
Reverse order or conditional search
zrevhorsearch *blog 0 100 blog: visit > 40 poster = like
1) -1
2) blog:003
3) 40
4) like
5) blog:002
6) 200
7) dota
Set
shmget key schema field1 field2 ...
Output HASH objects by SET member
hset blog:001 name dota
> 1
hset blog:002 name kris
> 1
sadd blogs 001 002
> 2
shmget blogs blog: name
1) 002
2) kris
3)
4)
5) 001
6) dota
7)
8)
shmset key schema field value ...
** Deprecated **
Extract all members from the set, set the value of the corresponding hash member, and return the number of affected hash values
shmset blogs blog: home China tel 021-7000000
> 2
Result:
hmgetall blog:001 blog:002
1) blog:001
2) name
3) dota
4) home
5) China
6) tel
7) 021-7000000
8)
9)
10) blog:002
11) name
12) kris
13) home
14) China
15) tel
16) 021-7000000
17)
18)
shmsum setkey schema field ...
Find the sum of the specified fields in the corresponding hash member of SET
hmset job:001 salary 1000 worktime 6
> ok
hmset job:002 salary 2000 worktime 10
> ok
sadd jobs 001 002
> 2
shmsum jobs job: salary worktime
1) 2 [the number of elements in zset]
2) 2 [the number of elements exist in article:*]
3) 2 [counts]
4) 3000 [sums]
5) 2 ...
6) 16 ...