20210812初步练习redis

Aug 12, 2021

初步练习redis

redis 包含数据类型: string list set zset(sort set), 另有事务、发布订阅等,这篇是自己简单练习数据类型总结

string

set key1 v1
get key1
mset key2 v2 key3 v3
keys *
exists key1
del key2
expire key3 20
ttl key3
persist key3

hash

hmset user:1000 username aker age 16 job it
hget user:1000 username
hmget user:1000 username age job
hgetall user:1000
hset user:1000 job chifan
hset user:1000 home sh
hvals user:1000
hdel user:1000 job [field2...]

set

sadd set1 1 2 3 4 5
smembers set1
srem set1 1 4
sadd set2 1 3 4 5 1 3
sdiff set1 set2
sinter set1 set2
sunion set1 set2

zset

zadd zkey0 1 redis 2 mongo  5 mysql 6 tidb 6 mariadb
zrange zkey0 0 -1 [withscores]
zcard zkey0
zincrby zkey0 2 redis

list

rpush list1 A
rpush list1 B
lpush list1 top1
lrange list1 0 -1
lrange list1 1 2
lrange list1 -3 -1
rpop list1
lpop list1
llen list1
lindex list1
lrem list1 -1 A

参考