首页 > 数据库技术 > 详细

[redis] 获得 database, key, value

时间:2015-06-01 06:13:24      阅读:267      评论:0      收藏:0      [点我收藏+]

获得 database

The INFO KEYSPACE command can be used to check whether some keys are defined in several databases.

redis 127.0.0.1:6379[1]> info keyspace
# Keyspace
db0:keys=1,expires=0
db1:keys=1,expires=0

The SELECT command can be used to switch a session to another database.The SELECT command can be used to switch a session to another database.

redis 127.0.0.1:6379> select 1
OK
redis 127.0.0.1:6379[1]> keys *
1) "bar"

获取所有的 key

keys **是通配符

http://redis.io/commands/keyshttp://redis.io/commands/keys

获取 key 的 value

因为 redis 有多种数据类型,并且每种类型的取值方法不同,所有首先需要知道 key 存储的 value 类型

You will need to perform for each key a type and depending on the response perform:

  • for “string”: get
  • for “hash”: hgetall
  • for “list”: lrange 0 -1
  • for “set”: smembers
  • for “zset”: zrange 0 -1 withscores

Keep in mind that for hashes and sorted sets you will be getting the keys/scores and values.

[redis] 获得 database, key, value

原文:http://my.oschina.net/xieyunzi/blog/423199

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!