Redis有五种基础类型:
一下图片均来自Redis in action
[color=red]String:[/color]
[img]http://dl2.iteye.com/upload/attachment/0088/3855/27ff0ec4-3443-35f7-aa78-79174f006d99.png[/img]
string command:
[url]http://redis.io/commands#string[/url]
set hello world
get hello
del hello
get hello
[color=red]list:[/color]
[img]http://dl2.iteye.com/upload/attachment/0088/3857/8d9db9a3-e724-3bdd-926a-4f78714d193e.png[/img]
List command:
[url]http://redis.io/commands#list[/url]
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
[color=red]Set:[/color]
[img]http://dl2.iteye.com/upload/attachment/0088/3859/8f5c3cb1-5438-3614-8d5a-23e15895653b.png[/img]
Set command :
[url]http://redis.io/commands#set[/url]
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"
[color=red]Hash[/color]
[img]http://dl2.iteye.com/upload/attachment/0088/3861/5dfb5bfc-4279-3917-95de-f460d58f42b4.png[/img]
hash command :
[url]http://redis.io/commands#hash[/url]
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"
[color=red]sorted set:[/color]
[img]http://dl2.iteye.com/upload/attachment/0088/3863/6b02696b-1c11-3d35-a19d-c90cc8900875.png[/img]
sorted set command :
[url]http://redis.io/commands#sorted_set[/url]
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
[color=red]String:[/color]
[img]http://dl2.iteye.com/upload/attachment/0088/3855/27ff0ec4-3443-35f7-aa78-79174f006d99.png[/img]
string command:
[url]http://redis.io/commands#string[/url]
set hello world
get hello
del hello
get hello
[color=red]list:[/color]
[img]http://dl2.iteye.com/upload/attachment/0088/3857/8d9db9a3-e724-3bdd-926a-4f78714d193e.png[/img]
List command:
[url]http://redis.io/commands#list[/url]
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
[color=red]Set:[/color]
[img]http://dl2.iteye.com/upload/attachment/0088/3859/8f5c3cb1-5438-3614-8d5a-23e15895653b.png[/img]
Set command :
[url]http://redis.io/commands#set[/url]
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"
[color=red]Hash[/color]
[img]http://dl2.iteye.com/upload/attachment/0088/3861/5dfb5bfc-4279-3917-95de-f460d58f42b4.png[/img]
hash command :
[url]http://redis.io/commands#hash[/url]
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"
[color=red]sorted set:[/color]
[img]http://dl2.iteye.com/upload/attachment/0088/3863/6b02696b-1c11-3d35-a19d-c90cc8900875.png[/img]
sorted set command :
[url]http://redis.io/commands#sorted_set[/url]
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