(一)Redis基础类型

Redis有五种基础类型:
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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值