(一)Redis基础类型
程序员文章站
2022-07-14 12:34:08
...
Redis有五种基础类型:
一下图片均来自Redis in action
String:
string command:
http://redis.io/commands#string
set hello world
get hello
del hello
get hello
list:
List command:
http://redis.io/commands#list
rpush list-key item
rpush list-key item2
rpush list-key item
lrange list-key 0 -1
"item"
"item2"
"item"
lindex list-key 1
lpop list-key
lrange list-key 0 -1
Set:
Set command :
http://redis.io/commands#set
sadd set-key item
sadd set-key item2
sadd set-key item3
sadd set-key item
smembers set-key
1) "item"
2) "item2"
3) "item3"
Hash
hash command :
http://redis.io/commands#hash
hset hash-key sub-key1 value1
hset hash-key sub-key2 value2
hset hash-key sub-key1 value1
hgetall hash-key
1) "sub-key1"
2) "value1"
3) "sub-key2"
4) "value2"
sorted set:
sorted set command :
http://redis.io/commands#sorted_set
zadd zset-key 728 member1
zadd zset-key 982 member0
zadd zset-key 982 member0
zrange zset-key 0 -1 withscores
1) "member1"
2) "728"
3) "member0"
4) "982"
zrangebyscore zset-key 0 800 withscores
zrem zset-key member1
zrem zset-key member1
zrange zset-key 0 -1 withscores
String List Set Hash Zset(sorted set)
一下图片均来自Redis in action
String:
string command:
http://redis.io/commands#string
set hello world
get hello
del hello
get hello
list:
List command:
http://redis.io/commands#list
rpush list-key item
rpush list-key item2
rpush list-key item
lrange list-key 0 -1
"item"
"item2"
"item"
lindex list-key 1
lpop list-key
lrange list-key 0 -1
Set:
Set command :
http://redis.io/commands#set
sadd set-key item
sadd set-key item2
sadd set-key item3
sadd set-key item
smembers set-key
1) "item"
2) "item2"
3) "item3"
Hash
hash command :
http://redis.io/commands#hash
hset hash-key sub-key1 value1
hset hash-key sub-key2 value2
hset hash-key sub-key1 value1
hgetall hash-key
1) "sub-key1"
2) "value1"
3) "sub-key2"
4) "value2"
sorted set:
sorted set command :
http://redis.io/commands#sorted_set
zadd zset-key 728 member1
zadd zset-key 982 member0
zadd zset-key 982 member0
zrange zset-key 0 -1 withscores
1) "member1"
2) "728"
3) "member0"
4) "982"
zrangebyscore zset-key 0 800 withscores
zrem zset-key member1
zrem zset-key member1
zrange zset-key 0 -1 withscores
上一篇: http&servlet