127.0.0.1:6379> set bar 1
OK
# 获取Redis中所有的键,keys命令需要遍历Redis中所有的键。当键的数量过多时,不建议使用。
127.0.0.1:6379> KEYS *
1) "bar"
127.0.0.1:6379> exists bar
(integer) 1
127.0.0.1:6379> exists note
(integer) 0
127.0.0.1:6379> del bar
(integer) 1
127.0.0.1:6379> del bar
(integer) 0
127.0.0.1:6379> set allms 1
OK
127.0.0.1:6379> type allms
string
# 键的赋值
- 语法:set key value
127.0.0.1:6379> set a hello
OK
# 键的取值
- 语法:get key
- 返回:key对应的值 键不存在时返回空
127.0.0.1:6379> get a
"hello"
127.0.0.1:6379> get b
(nil)
127.0.0.1:6379> incr num
(integer) 1 因为num键是不存在的,所有默认的键值为0,递增后的键值为1
127.0.0.1:6379> incr num
(integer) 2
127.0.0.1:6379> incr num
(integer) 3
127.0.0.1:6379> set info test
OK
127.0.0.1:6379> get info
"test"
127.0.0.1:6379> incr info
(error) ERR value is not an integer or out of range
127.0.0.1:6379> set num 100
OK
127.0.0.1:6379> get num
"100"
127.0.0.1:6379> incrby num 200
(integer) 300
127.0.0.1:6379> get num
"300"
127.0.0.1:6379> get num
"300"
127.0.0.1:6379> decr num
(integer) 299
127.0.0.1:6379> decr num
(integer) 298
127.0.0.1:6379> get num
"298"
127.0.0.1:6379> get num
"298"
127.0.0.1:6379> decrby num 100
(integer) 198
127.0.0.1:6379> get num
"198"
127.0.0.1:6379> set num 1.0
OK
127.0.0.1:6379> get num
"1.0"
127.0.0.1:6379> incrbyfloat num 9.9
"10.9"
127.0.0.1:6379> get num
"10.9"
127.0.0.1:6379> incrbyfloat num 5E+4 #递增一个双精度的浮点数 5x10^4
"50010.900000000001"
127.0.0.1:6379> set allms hello
OK
127.0.0.1:6379> append allms " world!" # 此处有一个空格,故加了一个双引号,默认可不加
(integer) 12
127.0.0.1:6379> get allms
"hello world!"
127.0.0.1:6379> strlen allms
(integer) 12
127.0.0.1:6379> keys *
1) "qfmx"
2) "num"
3) "allms"
127.0.0.1:6379> mget qfmx num allms
1) "data"
2) "50010.900000000001"
3) "hello world!"
127.0.0.1:6379> mset test1 data1 test2 data2 test3 data3
OK
127.0.0.1:6379> mget test1 test2 test3
1) "data1"
2) "data2"
3) "data3"
ID | color | name | price |
---|---|---|---|
1 | 黑色 | 宝马 | 100万 |
2 | 白色 | 奔驰 | 80万 |
3 | 红色 | 奥迪 | 99万 |
redis的散列类型的汽车对象ID为2的汽车信息的存储结构
键 | 字段 | 字段值 |
---|---|---|
Car:2 | ||
color | 白色 | |
name | 奔驰 | |
price | 80万 |