Simple to use:
Set insert String, get view
[Root@yum-down ~]# redis-cli-h 10.10.0.250-p 6379
10.10.0.250:6379> Set KeyName Hello
Ok
10.10.0.250:6379> Get KeyName
"Hello"
10.10.0.250:6379>
Filter:
Show All
10.10.0.250:6379> keys *
1) "Keya"
2) "Keyna"
3) "KeyName1"
4) "KeyName"
Match KeyName Start
10.10.0.250:6379> keys KeyName?
1) "KeyName2"
2) "KeyName1"
10.10.0.250:6379>
Determine whether the key exists, 0 does not exist, not 0 exist, indicating quantity
10.10.0.250:6379> EXISTS Keya
(integer) 1
10.10.0.250:6379> EXISTS KEYA1
(integer) 0
10.10.0.250:6379>
Delete: 0 does not exist, non 0 exists, indicating quantity
10.10.0.250:6379> DEL Keya
(integer) 1
10.10.0.250:6379> DEL Keya
(integer) 0
10.10.0.250:6379>
Info
Keyspace
Db0:keys=2,expires=0,avg_ttl=0
Db0: Example
as follows: SELECT 1 and 22 instances, insert data separately
10.10.0.250:6379[2]> SELECT 1
Ok
10.10.0.250:6379[1]> SELECT 2
Ok
10.10.0.250:6379[2]> SET 1 1
Ok
10.10.0.250:6379[2]> SELECT 1
Ok
10.10.0.250:6379[1]> SET 1 1
Ok
There are 1 and 2 instances of using the info view
Keyspace
Db0:keys=2,expires=0,avg_ttl=0
Db1:keys=1,expires=0,avg_ttl=0
Db2:keys=1,expires=0,avg_ttl=0
Flushall to empty all instances
10.10.0.250:63791> Flushall
Number of Keys:key
Expires: Expired Quantity
Number of Avg_ttl:ttl
Append: Append
You can often use set to append
127.0.0.1:6379> Set 1 Hello
Ok
127.0.0.1:6379> Get 1
"Hello"
Set Append
127.0.0.1:6379> Set 1 Hello,word
Ok
127.0.0.1:6379> Get 1
"Hello,word"
Append Append
127.0.0.1:6379> Append 1 W
(integer) 11
127.0.0.1:6379> Append 1 Word
(integer) 15
127.0.0.1:6379> Get 1
"Hello,wordwword"
127.0.0.1:6379>
Single Data append: INCR
127.0.0.1:6379> INCR New
(integer) 1
127.0.0.1:6379> INCR New
(integer) 2
127.0.0.1:6379> INCR New
(integer) 3
127.0.0.1:6379> INCR New
(integer) 4
127.0.0.1:6379> INCR New
(integer) 5
127.0.0.1:6379> get new
"5"
127.0.0.1:6379>
Append multiple: Incrby
127.0.0.1:6379> get new
"5"
127.0.0.1:6379> Incrby New 100
(integer) 105
127.0.0.1:6379> get new
"105"
127.0.0.1:6379>
Reduced: DECR
127.0.0.1:6379> get new
"105"
127.0.0.1:6379> DECR New
(integer) 104
127.0.0.1:6379> DECR New
(integer) 103
127.0.0.1:6379> DECR New
(integer) 102
127.0.0.1:6379> DECR New
(integer) 101
127.0.0.1:6379> DECR New
(integer) 100
127.0.0.1:6379> get new
"100"
127.0.0.1:6379>
Floating point: Incrbyeloat
127.0.0.1:6379> incrbyfloat Key 0.1
"0.2"
127.0.0.1:6379> incrbyfloat Key 0.1
"0.3"
127.0.0.1:6379> incrbyfloat Key 0.1
"0.4"
127.0.0.1:6379> incrbyfloat Key 0.1
"0.5"
127.0.0.1:6379> incrbyfloat Key 0.1
"0.6"
127.0.0.1:6379> incrbyfloat Key 0.1
"0.7"
127.0.0.1:6379>
Mset use:
127.0.0.1:6379> mset key 1 Key2 2 Key3 3
Ok
127.0.0.1:6379> Get key
"1"
127.0.0.1:6379> Get Key2
"2"
127.0.0.1:6379> Get Key3
"3"
127.0.0.1:6379> mget Key Key2 Key3
1) "1"
2) "2"
3) "3"
127.0.0.1:6379>
Calculate the key value based on the UTF-8 encoding:
127.0.0.1:6379> set key "Linuxea blog"
Ok
127.0.0.1:6379> Get key
"Linuxea\xe5\x8d\x9a\xe5\xae\xa2"
127.0.0.1:6379> strlen Key
(integer) 13
127.0.0.1:6379>
=================== Hash Type =====================
Hash Type:
Hset
127.0.0.1:6379> hset Xuhao Name 1
(integer) 1
127.0.0.1:6379> Hset Xuhao Co red
(integer) 1
127.0.0.1:6379> Hset Xuhao Price 3
(integer) 1
Hgetall View All
127.0.0.1:6379> Hgetall Xuhao
1) "Name"
2) "1"
3) "CO"
4) "Red"
5) "Price"
6) "3"
Hget Single View
127.0.0.1:6379> hget Xuhao Name
"1"
127.0.0.1:6379> Hget Xuhao Co
"Red"
127.0.0.1:6379> Hget Xuhao Price
"3"
127.0.0.1:6379>
Hmset:
127.0.0.1:6379> hmset pc name ThinkPad Co Black Price 3000
Ok
127.0.0.1:6379> Hgetall pc
1) "Name"
2) "ThinkPad"
3) "CO"
4) "Black"
5) "Price"
6) "3000"
127.0.0.1:6379> hset pc Mode1 "Bu Huan Jia"
(integer) 1
127.0.0.1:6379> hget pc Mode1
"Bu Huan Jia"
127.0.0.1:6379>
Delete:
127.0.0.1:6379> hget pc Mode1
"Bu Huan Jia"
127.0.0.1:6379> Hdel pc Mode1
(integer) 1
127.0.0.1:6379> Hgetall Mode1
(empty list or set)
Determine if there is another:
127.0.0.1:6379> hexists mode1 "Bu Huan Jia"
(integer) 0
127.0.0.1:6379>
To determine whether a key exists:
127.0.0.1:6379> EXISTS Mode1
(integer) 0
127.0.0.1:6379>
=================== List Type =====================
List type:
[Root@yum-down ~]# Redis-cli
127.0.0.1:6379> del New
(integer) 1
127.0.0.1:6379> Lpush New 1
(integer) 1
127.0.0.1:6379> Lpush New 2
(integer) 2
127.0.0.1:6379> Lpush New 3
(integer) 3
Insert from right
127.0.0.1:6379> Rpush new 4
(integer) 4
127.0.0.1:6379> Llen New
(integer) 4
127.0.0.1:6379>
Eject one from the left:
127.0.0.1:6379> Lpop New
"1"
Eject one from the right:
127.0.0.1:6379> Rpop New
"4"
127.0.0.1:6379>
Two popup, only 2 characters left to view
127.0.0.1:6379> Llen New
(integer) 2
127.0.0.1:6379>
A certain range: Lrange
-1 represents the first element from the right
127.0.0.1:6379> Lrange New 1 2
1) "2"
2) "3"
127.0.0.1:6379> Lrange New 0-1
-0 is viewed from the left
127.0.0.1:6379> lindex New 0
"1"
127.0.0.1:6379>
Keep only the specified entries:
For example: Keep only 0-4 entries:
127.0.0.1:6379> LTRIM New 1 4
Ok
View
127.0.0.1:6379> Lrange New 0-1
1) "4"
2) "Llen"
3) "New"
4) "Llen"
Keep only 0-3 entries
127.0.0.1:6379> LTRIM New 1 3
Ok
View
127.0.0.1:6379> Lrange New 0-1
1) "Llen"
2) "New"
3) "Llen"
127.0.0.1:6379>
For example: Just look at the logs 100 data:
127.0.0.1:6379> Lpush Logs Newlog
(integer) 1
127.0.0.1:6379> LTRIM Logs 0 99
Ok
127.0.0.1:6379>
=================== collection type ====================
Collection type: Sadd
127.0.0.1:6379> Sadd Jihe a b C
(integer) 3
127.0.0.1:6379> Sadd jihe2 E F g
(integer) 3
127.0.0.1:6379> smembers Jihe
1) "C"
2) "B"
3) "A"
127.0.0.1:6379> smembers Jihe2
1) "E"
2) "G"
3) "F"
127.0.0.1:6379>
Determine if there is: Sismember
127.0.0.1:6379> Sismember Jihe2 A
(integer) 0
127.0.0.1:6379> Sismember jihe2 E
(integer) 1
127.0.0.1:6379>
Judgment difference set: Sdiff
127.0.0.1:6379> Sdiff Jihe Jihe2
1) "C"
2) "A"
3) "B"
127.0.0.1:6379>
Intersection operation: sinter
127.0.0.1:6379> smembers Jihe2
1) "A"
2) "E"
3) "G"
4) "F"
127.0.0.1:6379> smembers Jihe
1) "C"
2) "B"
3) "A"
127.0.0.1:6379> sinter Jihe Jihe2
1) "A"
127.0.0.1:6379>
Collection: Sunion
127.0.0.1:6379> sunion Jihe Jihe2
1) "E"
2) "A"
3) "B"
4) "F"
5) "G"
6) "C"
127.0.0.1:6379>
Ordered collections:
127.0.0.1:6379> Zadd Jihea A
(integer) 1
127.0.0.1:6379> Zadd Jihea Bayi b
(integer) 1
127.0.0.1:6379> Zadd Jihea C
(integer) 1
127.0.0.1:6379> Zadd Jihea D
(integer) 1
127.0.0.1:6379> Zadd Jihea E
(integer) 1
View
127.0.0.1:6379> Zscore Jihea A
"80"
127.0.0.1:6379> Zscore Jihea b
"81"
127.0.0.1:6379> Zscore Jihea C
"82"
127.0.0.1:6379> Zscore Jihea D
"83"
127.0.0.1:6379>
View all:
127.0.0.1:6379> zrange Jihea 0-1
1 "a"
2) "B"
3) "C"
4) "D"
5) "E"
127.0.0.1:6379>