redis五大基础类型练习
127.0.0.1:6379> set key value
OK
127.0.0.1:6379> get key
"value"
127.0.0.1:6379> mset key1 1 key2 2 --set多个值
OK
127.0.0.1:6379> mget key1 key2 key
1) "1"
2) "2"
3) "value"
127.0.0.1:6379> set key 2
OK
127.0.0.1:6379> mget key1 key2 key
1) "1"
2) "2"
3) "2"
127.0.0.1:6379> set key value
OK
127.0.0.1:6379> incr key
(error) ERR value is not an integer or out of range
127.0.0.1:6379> incr key1 --自增
(integer) 2
127.0.0.1:6379> decr key1 --自减
(integer) 1
127.0.0.1:6379> append key vvv --拼接
(integer) 8
127.0.0.1:6379> get key
"valuevvv"
127.0.0.1:6379> del key key1 key2 --删除
(integer) 3
127.0.0.1:6379> hset user id 1 --set
(integer) 1
127.0.0.1:6379> hset user name zhao
(integer) 1
127.0.0.1:6379> hset user sex man
(integer) 1
127.0.0.1:6379> hget user
(error) ERR wrong number of arguments for 'hget' command
127.0.0.1:6379> hget user id
"1"
127.0.0.1:6379> hget user name
"zhao"
127.0.0.1:6379> hget user sex
"man"
127.0.0.1:6379> hgetall user --set获取全部
1) "id"
2) "1"
3) "name"
4) "zhao"
5) "sex"
6) "man"
127.0.0.1:6379> hmset user age 18 email 1@qq.com --set多个
OK
127.0.0.1:6379> hmget user age email
1) "18"
2) "1@qq.com"
127.0.0.1:6379> hmget user age email name
1) "18"
2) "1@qq.com"
3) "zhao"
127.0.0.1:6379> hdel user email
(integer) 1
127.0.0.1:6379> hdel user age sex
(integer) 2
127.0.0.1:6379> hexists user id --判断存在
(integer) 1
127.0.0.1:6379> hkeys user --获取all key
1) "id"
2) "name"
127.0.0.1:6379> hvals user --获取all values
1) "1"
2) "zhao"
127.0.0.1:6379> hlen user --length
(integer) 2
127.0.0.1:6379> hdel id name
(integer) 0
127.0.0.1:6379> hlen user
(integer) 2
127.0.0.1:6379> hdel user id name --del
(integer) 2
127.0.0.1:6379> hlen user
(integer) 0
127.0.0.1:6379> lpush key1 1 key2 2 --left push
(integer) 3
127.0.0.1:6379> rpush key1 1 key2 2 --right push
(integer) 6
127.0.0.1:6379> llen key1
(integer) 6
127.0.0.1:6379> lrange key1 0 6
1) "2"
2) "key2"
3) "1"
4) "1"
5) "key2"
6) "2"
127.0.0.1:6379> lpush key1 3
(integer) 7
127.0.0.1:6379> lrange key1 0 6
1) "3"
2) "2"
3) "key2"
4) "1"
5) "1"
6) "key2"
7) "2"
127.0.0.1:6379> lindex key1 0
"3"
127.0.0.1:6379> lset key1 0 10
OK
127.0.0.1:6379> lrang key1 0 10
(error) ERR unknown command 'lrang'
127.0.0.1:6379> lrange key1 0 10
1) "10"
2) "2"
3) "key2"
4) "1"
5) "1"
6) "key2"
7) "2"
127.0.0.1:6379> lpop key1 --left remove
"10"
127.0.0.1:6379> rpop key1 --right remove
"2"
127.0.0.1:6379> lrange key1 0 10
1) "2"
2) "key2"
3) "1"
4) "1"
5) "key2"
127.0.0.1:6379> ltrim key1 1 3 --trim list
OK
127.0.0.1:6379> lrange key1 0 10 --range list
1) "key2"
2) "1"
3) "1"
127.0.0.1:6379> linsert key1 after 2 10011 --after 后的2为value,而不是index
(integer) -1
127.0.0.1:6379> lrange key1 0 10
1) "key2"
2) "1"
3) "1"
127.0.0.1:6379> linsert key1 after 1 11 --左起第一个1后追加11
(integer) 4
127.0.0.1:6379> lrange key1 0 10
1) "key2"
2) "1"
3) "11"
4) "1"
127.0.0.1:6379> rpush key1 100111
(integer) 5
127.0.0.1:6379> lrange key1 0 10
1) "key2"
2) "1"
3) "11"
4) "1"
5) "100111"
127.0.0.1:6379> lpush key1 100111
(integer) 6
127.0.0.1:6379> lrange key1 0 10
1) "100111"
2) "key2"
3) "1"
4) "11"
5) "1"
6) "100111"
127.0.0.1:6379> lpushx key1 10086
(integer) 7
127.0.0.1:6379> lpush key1 10096
(integer) 8
127.0.0.1:6379> lrem key1 1 0 --lremove key count value
(integer) 0
127.0.0.1:6379> lrange key1 0 10
1) "10096"
2) "10086"
3) "100111"
4) "key2"
5) "1"
6) "11"
7) "1"
8) "100111"
127.0.0.1:6379> ltrim key1 0 100
OK
127.0.0.1:6379> lrange key1 0 10
1) "10096"
2) "10086"
3) "100111"
4) "key2"
5) "1"
6) "11"
7) "1"
8) "100111"
127.0.0.1:6379> ltrim key1 0 -1
OK
127.0.0.1:6379> lrange key1 0 10
1) "10096"
2) "10086"
3) "100111"
4) "key2"
5) "1"
6) "11"
7) "1"
8) "100111"
127.0.0.1:6379> del key1
(integer) 1
127.0.0.1:6379> lrange key1 0 10
(empty list or set)
127.0.0.1:6379> sadd key value --set
(integer) 1
127.0.0.1:6379> smembers key --show all values
1) "value"
127.0.0.1:6379> sadd key val
(integer) 1
127.0.0.1:6379> smembers key
1) "val"
2) "value"
127.0.0.1:6379> sadd key2 kkk
(integer) 1
127.0.0.1:6379> sadd key2 value
(integer) 1
127.0.0.1:6379> smembers key
1) "val"
2) "value"
127.0.0.1:6379> smembers key2
1) "value"
2) "kkk"
127.0.0.1:6379> sdiff key key2 --key different key2
1) "val"
127.0.0.1:6379> sinter key key2 --key in key2
1) "value"
127.0.0.1:6379> sunion key key2 --union
1) "value"
2) "val"
3) "kkk"
127.0.0.1:6379> lpush keyl valuse value
(integer) 2
127.0.0.1:6379> sunion key key2 keyl --not the same kind
(error) WRONGTYPE Operation against a key holding the wrong kind of value
127.0.0.1:6379> del keyl
(integer) 1
127.0.0.1:6379> scard key2 --count
(integer) 2
127.0.0.1:6379> del key
(integer) 1
127.0.0.1:6379> del key2
(integer) 1
127.0.0.1:6379> scard key
(integer) 0
127.0.0.1:6379> scard key2
(integer) 0
127.0.0.1:6379> scard key1111
(integer) 0
127.0.0.1:6379> zadd key 1 1 --zset --zadd key score value
(integer) 1
127.0.0.1:6379> zadd key 2 2
(integer) 1
127.0.0.1:6379> zscore key 1
"1"
127.0.0.1:6379> zscore key 2
"2"
127.0.0.1:6379> zrange key 0 1
1) "1"
2) "2"
127.0.0.1:6379> zrang key 0.5 0.5
(error) ERR unknown command 'zrang'
127.0.0.1:6379> zadd key 0.5 0.5
(integer) 1
127.0.0.1:6379> zrange key 0 2 --score排序,结果为value
1) "0.5"
2) "1"
3) "2"
127.0.0.1:6379> zrevrange key 0 3 --score逆排序 ,结果为value
1) "2"
2) "1"
3) "0.5"
127.0.0.1:6379> zadd key 0.5 1
(integer) 0
127.0.0.1:6379> zrank key 1
(integer) 1
127.0.0.1:6379> withscores
(error) ERR unknown command 'withscores'
127.0.0.1:6379> zrange key 0 2 withscores --add scores
1) "0.5"
2) "0.5"
3) "1"
4) "0.5"
5) "2"
6) "2"
127.0.0.1:6379> zrevrank key 1
(integer) 1
127.0.0.1:6379> zrangebyscore key 0 10
1) "0.5"
2) "1"
3) "2"
127.0.0.1:6379> zincry key 10 1
(error) ERR unknown command 'zincry'
127.0.0.1:6379> zincrby key 10 1 --给value为1的score加分
"10.5"
127.0.0.1:6379> zrangebyscore key 0 10 --
1) "0.5"
2) "2"
127.0.0.1:6379> zcount key 0 10
(integer) 2
127.0.0.1:6379> zremrangebyrank key 0 1
(integer) 2
127.0.0.1:6379> zrange key 0 100
1) "1"
127.0.0.1:6379> del key
(integer) 1
127.0.0.1:6379> zrange key 0 100
(empty list or set)
127.0.0.1:6379>