--get all config
config get *
config get configname
--set config
config set configname configvalue
Abount key
-- key
set key value --set key and value
del key -- delete key
exists key -- if exists
expire aaa 10 -- set the timeout 10s
pexpire aaa 5000 -- set timeout 5000mm
expireat aaa 1504771560 --set timeout at unixstamp
ttl key --show the seconds left before expire
rename key key1
String(字符串,整數(shù),浮點(diǎn)數(shù))
127.0.0.1:6379> set name zouyufei
127.0.0.1:6379> mset name zouyufei age 20 (multi set)
127.0.0.1:6379> get name
127.0.0.1:6379> getrange name 1 3 (index from 0)
127.0.0.1:6379> setrange name 7 aa (name = name from 0-7 + aa)
127.0.0.1:6379> mget name age (get multi keys)
127.0.0.1:6379> setex gender 10 male (set gender=male, and timeout=10s)
127.0.0.1:6379>setnx name zouyf (set name=zouyf if name doesn't exist)
127.0.0.1:6379> msetnx name zouyufei age 20 (multi set when all keys don't exist)
127.0.0.1:6379> strlen name (get name length)
127.0.0.1:6379> incr age (age ++)
127.0.0.1:6379> incrby age 10 (age+=10)
127.0.0.1:6379> decr age (age--)
127.0.0.1:6379> decrby age 10 (age -=10)
127.0.0.1:6379> append name dtc (name=name+dtc)
Hash(包含鍵值隊(duì)的無(wú)序散列表)
127.0.0.1:6379> hset mac cpu i7
127.0.0.1:6379> hmset mac cpu i5 memory 10G price 4999 (set multi)
127.0.0.1:6379> hgetall mac
127.0.0.1:6379> hget mac cpu
127.0.0.1:6379> hmget mac screen memory (get multi )
127.0.0.1:6379> hdel mac address screen (delete address and screen from mac)
127.0.0.1:6379> hexists mac name
127.0.0.1:6379> hincrby mac price 10 (mac's price +=10)
127.0.0.1:6379> hkeys mac (get all keys in mac)
127.0.0.1:6379> hlen mac (key count)
127.0.0.1:6379> hsetnx mac cpu i8 (set value only key doesn't exist)
127.0.0.1:6379> hvals mac (get all values)
List (一個(gè)鏈表,鏈表上每個(gè)結(jié)點(diǎn)都包含一個(gè)字符串)
127.0.0.1:6379> lpush list 1 (if list doesn't exist, create the list)
127.0.0.1:6379> lpush list 2 3 4 (push the elements from left)
127.0.0.1:6379> lpushx list 6 (if list doesn't exist, do nothing)
127.0.0.1:6379> lrange list 0 2
127.0.0.1:6379> lindex list 2 (get the second element)
127.0.0.1:6379> llen list (get length)
127.0.0.1:6379> lpop list (get first element from left - head)
127.0.0.1:6379> lrem list 2 5 (remove 5 twice from head)
127.0.0.1:6379> lset list 0 100 (set the first element from left to 100)
127.0.0.1:6379> ltrim list 0 4 (remain from 0 -4 elements)
127.0.0.1:6379> rpoplpush list list (pop first element from right and push to list from left)
127.0.0.1:6379> rpush list 2 3 4 (push the elements from right)
127.0.0.1:6379> rpushx list 6 (if list doesn't exist, do nothing)
127.0.0.1:6379> rpop list (get first element from right - tail)
Set (字符串無(wú)序收集器,每個(gè)元素唯一)
127.0.0.1:6379> sadd set 1 2 3 4
127.0.0.1:6379> srem set 4 (remove)
127.0.0.1:6379> smembers set (show all)
127.0.0.1:6379> scard set (show size)
127.0.0.1:6379> sdiff set set1 (get the difference between set and set1)
127.0.0.1:6379> sdiffstore diffset set set1 ( store the difference between set and set1 to diffset)
127.0.0.1:6379> sinter set set1 (交集)
127.0.0.1:6379> sinterstore interset set set1
127.0.0.1:6379> sunion set set1 (并集)
127.0.0.1:6379> sunionstore unionset set set1
127.0.0.1:6379> sismember set 1 (if 1 belongs to set)
127.0.0.1:6379> smove set set1 1 (remove 1 from set to set1)
127.0.0.1:6379> spop set 2 (drop 2 elements randomly from set)
127.0.0.1:6379> srandmember set 2 (get 2 elements randomly from set)
Sorted Set (字符串成員與浮點(diǎn)數(shù)分值之間的有序映射)
127.0.0.1:6379> zadd zet 1 a
127.0.0.1:6379> zadd zet 2 b
127.0.0.1:6379> zadd zet 1 a 2 b 3 c (add a,b,c with weight 1 2 3)
127.0.0.1:6379> zrank zet a (show the index of a order by score asc- from 0)
127.0.0.1:6379> zrevrank zet2 a (show the index of a order by score desc)
127.0.0.1:6379> zscore zet1 a(show the score of a)
127.0.0.1:6379> zrange zet 0 10 withscores (show the elements whose index between 0 and 10)
[127.0.0.1:6379>zrangebylex zet1 [a [c (show the elements whose score between a and c's score)]
127.0.0.1:6379> zcard zet (size)
127.0.0.1:6379> zcount zet 1 2 (get the count whose score between 1 and 2)
127.0.0.1:6379> zlexcount zet1 [a [b (get the count which weight between a and b's weight )
127.0.0.1:6379> zincrby zet 10 a (add 10 to the weight of a)
127.0.0.1:6379> zinterstore interzet 2 zet zet1 (交集)
127.0.0.1:6379> zunionstore unionzet 2 zet zet1(并集)
127.0.0.1:6379> zrem zet a
127.0.0.1:6379> zremrangebylex zet [a [b (remove elements whose score between a and b's)
127.0.0.1:6379> zremrangebyscore zet 0 4 (remove elements whose score between 0 and 4)
127.0.0.1:6379> zrevrange zet1 0 1(get the last 2 elements)