设为首页 收藏本站
查看: 1211|回复: 0

[经验分享] Redis 数据结构之Keys

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-7-21 08:42:50 | 显示全部楼层 |阅读模式

  
  这是Redis官方文档的keys列表
  
  (1) set  key value--设置某个键为某个值
  (2) get key -- 获取设置的值
  (3)del key -- 删除设置的键
  (4)expire  key seconds-- 设置键值的存在时间
  (5)expireat key timestamp -- 更高级的键值保存时间。
  (6)keys pattern --查看键值的个数  (keys *可以返回所有的键)
  (7)move key db  -- 将某个键值移动到另外的数据库(可以用select db来选择数据库)
  (8)object --
  The OBJECT command allows to inspect the internals of Redis Objects associated with keys. It is useful for debugging or to understand if your keys are using the specially encoded data types to save space. Your application may also use the information reported by the OBJECT command to implement application level key eviction policies when using Redis as a Cache.
  The OBJECT command supports multiple sub commands:


  • OBJECT REFCOUNT returns the number of references of the value associated with the specified key. This command is mainly useful for debugging.
  • OBJECT ENCODING returns the kind of internal representation used in order to store the value associated with a key.
  • OBJECT IDLETIME returns the number of seconds since the object stored at the specified key is idle (not requested by read or write operations). While the value is returned in seconds the actual resolution of this timer is 10 seconds, but may vary in future implementations.
  Objects can be encoded in different ways:


  • Strings can be encoded as raw (normal string encoding) or int (strings representing integers in a 64 bit signed interval are encoded in this way in order to save space).
  • Lists can be encoded as ziplist or linkedlist. The ziplist is the special representation that is used to save space for small lists.
  • Sets can be encoded as intset or hashtable. The intset is a special encoding used for small sets composed solely of integers.
  • Hashes can be encoded as zipmap or hashtable. The zipmap is a special encoding used for small hashes.
  • Sorted Sets can be encoded as ziplist or skiplist format. As for the List type small sorted sets can be specially encoded using ziplist, while the skiplist encoding is the one that works with sorted sets of any size.
  All the specially encoded types are automatically converted to the general type once you perform an operation that makes it impossible for Redis to retain the space saving encoding.

Return value
  Different return values are used for different subcommands.


  • Subcommands refcount and idletime return integers.
  • Subcommand encoding returns a bulk reply.
  If the object you try to inspect is missing, a null bulk reply is returned.

Examples

redis> lpush mylist "Hello World"
(integer) 4
redis> object refcount mylist
(integer) 1
redis> object encoding mylist
"ziplist"
redis> object idletime mylist
(integer) 10

  In the following example you can see how the encoding changes once Redis is no longer able to use the space saving encoding.

redis> set foo 1000
OK
redis> object encoding foo
"int"
redis> append foo bar
(integer) 7
redis> get foo
"1000bar"
redis> object encoding foo
"raw"
  (9)pexpire key milliseconds -- 设置毫秒级别的键值保存
  (10)pexpireat key milliseconds--timestap
  (11)ttl key -- 返回设置的键值保存期限还有多少秒!
  (12)rename key newkey -- 重新命名一个新的key值
  (13)renamenx key newkey -- 重新命名一个新的key值仅仅在key 不存在的情况下
  (14)SORT key [BY pattern] [LIMIT offset count][GET pattern [GET pattern ...]] [ASC|DESC] [ALPHA][STORE destination]


  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-88872-1-1.html 上篇帖子: 深入redis内部--实现字符串 下篇帖子: 【redis源码】(三)Zipmap
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表