#设置键值 ex表示妙 nx:键不存在时创建 set a 1 ex 100 nx #px 代表毫秒 xx:存在时创建 set a 1 px 1000 xx #获取建 get a #删除 del a #获取所有键 keys * #获取10条与a有关的从0位置开始 scan 0 match '*a*' 10 #自增 incr #递减 decr #指定键加3 incrby a 3 #指定键减3 decrby a 3 #字符串抓加456 append a 456 #批量赋值 mset a 1 b 2 c 3 #清空当前数据库 flushdb #清空所有数据库 flushall
127.0.0.1:6379[2]> hset people age 18 (integer) 1 127.0.0.1:6379[2]> hset people name l (integer) 1 127.0.0.1:6379[2]> hget people age "18" 127.0.0.1:6379[2]> hmset people sex '男' phoen apple OK 127.0.0.1:6379[2]> hget people sex "\xe7\x94\xb7" 127.0.0.1:6379[2]> hget people phoen "apple" 127.0.0.1:6379[2]> hmget people phoen sex name age 1) "apple" 2) "\xe7\x94\xb7" 3) "l" 4) "18" 127.0.0.1:6379[2]> hgetall people 1) "age" 2) "18" 3) "name" 4) "l" 5) "sex" 6) "\xe7\x94\xb7" 7) "phoen" 8) "apple" 127.0.0.1:6379[2]> HEXISTS people age (integer) 1 127.0.0.1:6379[2]> HEXISTS people agea (integer) 0 127.0.0.1:6379[2]> HINCRBY people age 1 (integer) 19 127.0.0.1:6379[2]> hget people age "19" 127.0.0.1:6379[2]> hkeys people 1) "age" 2) "name" 3) "sex" 4) "phoen" 127.0.0.1:6379[2]> HVALS people 1) "19" 2) "l" 3) "\xe7\x94\xb7" 4) "apple" 127.0.0.1:6379[2]> hlen people (integer) 4 127.0.0.1:6379[2]> hsetnx people color green (integer) 1 127.0.0.1:6379[2]> hlen people (integer) 5 127.0.0.1:6379[2]> hgetall people 1) "age" 2) "19" 3) "name" 4) "l" 5) "sex" 6) "\xe7\x94\xb7" 7) "phoen" 8) "apple" 9) "color" 10) "green" 127.0.0.1:6379[2]> hkeys people 1) "age" 2) "name" 3) "sex" 4) "phoen" 5) "color"