- redis中的字串(String)
- redis中的列表(List)
- redis中的集合(Set)
- redis中的雜湊(Hash)
- redis中的有序集合(Zset)
字串
常用指令及基本操作:set、get、del
127.0.0.1:6379> clear
127.0.0.1:6379> set name nanshen
OK
127.0.0.1:6379> get name
"nanshen"
127.0.0.1:6379> del name
(integer) 1
127.0.0.1:6379> get name
(nil)
127.0.0.1:6379>
複製程式碼
列表
常用指令:rpush(lpush)、rpop(lpop)、lrange、lindex
127.0.0.1:6379> rpush class item
(integer) 1
127.0.0.1:6379> rpush class item1
(integer) 2
127.0.0.1:6379> rpush class item2
(integer) 3
127.0.0.1:6379> lrange class 0 -1
1) "item"
2) "item1"
3) "item2"
127.0.0.1:6379> lindex class 0
"item"
127.0.0.1:6379> lindex class -1
"item2"
127.0.0.1:6379> rpop class
"item2"
127.0.0.1:6379>
複製程式碼
集合
常用指令:sadd、srem、smembers、sismember
127.0.0.1:6379> sadd emp a
(integer) 1
127.0.0.1:6379> sadd emp b
(integer) 1
127.0.0.1:6379> sadd emp c
(integer) 1
127.0.0.1:6379> smembers emp
1) "a"
2) "b"
3) "c"
127.0.0.1:6379> sismember emp d
(integer) 0
127.0.0.1:6379> sismember emp a
(integer) 1
127.0.0.1:6379> srem emp a
(integer) 1
127.0.0.1:6379> smembers emp
1) "b"
2) "c"
127.0.0.1:6379>
複製程式碼
雜湊
常用指令:hset、hget、hdel、hgetall
127.0.0.1:6379> hset mini chengxu chen
(integer) 1
127.0.0.1:6379> hset mini chengxu nan
(integer) 0
127.0.0.1:6379> hset mini chengxu chen
(integer) 0
127.0.0.1:6379> hset mini meishu nan
(integer) 1
127.0.0.1:6379> hset mini cehua shen
(integer) 1
127.0.0.1:6379> hgetall mini
1) "chengxu"
2) "chen"
3) "meishu"
4) "nan"
5) "cehua"
6) "shen"
127.0.0.1:6379> hget mini chengxu
"chen"
127.0.0.1:6379> hdel mini chengxu
(integer) 1
127.0.0.1:6379> hgetall mini
1) "meishu"
2) "nan"
3) "cehua"
4) "shen"
127.0.0.1:6379>
複製程式碼
有序集合
常用指令:zadd、zrange、zrangebyscore、zrem
127.0.0.1:6379> zadd class1 1 chen
(integer) 1
127.0.0.1:6379> zadd class1 2 nan
(integer) 1
127.0.0.1:6379> zadd class1 3 shen
(integer) 1
127.0.0.1:6379> zrange class1 0 -1
1) "chen"
2) "nan"
3) "shen"
127.0.0.1:6379> zrange class1 0 -1 withscores
1) "chen"
2) "1"
3) "nan"
4) "2"
5) "shen"
6) "3"
127.0.0.1:6379> zrangebyscore class1 0 1
1) "chen"
127.0.0.1:6379> zrangebyscore class1 0 1 withscores
1) "chen"
2) "1"
127.0.0.1:6379> zrem class1 nan
(integer) 1
127.0.0.1:6379> zrange class1 0 -1 withscores
1) "chen"
2) "1"
3) "shen"
4) "3"
127.0.0.1:6379>
複製程式碼