关于在linux中如何操作Redis不同的数据类型
1. Redis五大数据类型
- (1)String(字符串)
- (2)Hash(哈希,类似Java里的Map)
- (3)List(列表)
- (4)Set (集合)
- (5)Zset(sorted set:有序集合)
2. Redis操作数据库命令
3. Redis Key常用操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| key *
set [key] [value]
get [key]
del [key]
exists [key]
move [key] [database]
exprie [key] [time]
ttl [key]
type [key]
|
4. Redis String常用操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| append [key] [value]
incr [key]
decr [key]
incrby [key] [value]
decrby [key] [value]
getrange [key] [start] [end]
setrange [key] [start] [value]
setex [key] [time] [value]
setnx [key] [value]
mset [key1] [value1] [key2] [value2] ...
mget [key1] [key2] ...
msetnx [key1] [value1] [key2] [value2] ...
|
5. Redis List常用操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| lpush [list] [value1] [value2] [value3] ...
rpush [list] [value1] [value2] [value3] ...
lrange [list] [start] [end]
lpop [list]
rpop [list]
lindex [list] [index]
llen [list]
lrem [list] [times] [value]
ltrim [list] [start] [end]
rpoplpush [list1] [list2]
lset [list] [index] [value]
linsert [list] before/after [value1] [value2]
|
6. Redis Set常用操作
Set和List差不多,只是Set的数据不允许重复,List数据允许
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| sadd [set] [value1] [value2] [value3] ...
smembers [set]
sismenber [set] [value]
srem [set] [value]
srandmember [set] [number]
spop [set]
smove [set1] [set2] [value]
sdiff [set1] [set2]
sinter [set1] [set2]
sunion [set1] [set2]
|
7. Redis Hash常用操作
hash可以暂时理解为K-V形式,key是String类型,value是个对象
深层次理解为KV模式,但value是一个键值对
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| hset [key] [v-key] [v-value]
hget [key] [v-key]
hmset [key] [v-key1] [v-value1] [v-key2] [v-value2] ...
hmget [key] [v-key1] [v-key2] ...
hgetall [key]
hdel [key] [v-key]
hlen [key]
hexists [key] [v-key]
hkeys [key]
hvals [key]
hincrby [key] [v-key] [number]
hincrbyfloat [key] [v-key] [float-number]
hsetnx [key] [v-key] [v-value]
|
8. Redis Zset常用操作
Zset 是 sort set 的简称
zset是在原有set的基础上,添加了个score值
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| zadd [zset] [score1] [value1] [score2] [value2] [score3] [value3] ...
zrange [zset] [start] [end]
zrange [zset] [start] [end] withscores
zrangebyscore [zset] [score-start] [score-end]
zrangebyscore [zset] ([score-start] ([score-end]
zrangebyscore [zset] [score-start] [score-end] withscores
zrangebyscore [zset] [score-start] [score-end] limit [start] [number]
zrem [zset] [value]
zcard [zset]
zcount [zset] [score-start] [score-end]
zrank [zset] [value]
zscore [zset] [value]
zrevrank [zset] [value]
zrevrange [zset] [start] [end]
zrevrangebyscore [zset] [score-end] [score-start]
|