日期:2014-05-16  浏览次数:20445 次

Redis学习笔记(四)——Redis常用命令入门——散列类型

三、散列命令

散列类型的键值其实也是一种字典解耦,其存储了字段和字段值的映射,但自断值只能是字符串,不支持其他数据类型,所以说散列类型不能嵌套其他的数据类型。一个散列类型的键可以包含最多2的32次方-1个字段。

另外提前说一声,除了散列类型,其他的数据类型同样不支持数据类型嵌套。

1、基本命令

例如现在要存储ID为1的文章,分别有title、author、time、content

则键为post:1,字段分别为title、author、time、content,值分别为“the first post”、“me”、“2014-03-04”、“This is my first post.”,存储如下

redis>hmset post:1 title "the first post" author me time 2014-03-04 content "This is my first post."
OK

这里使用的是hmset命令,具体散列的基本赋值命令如下
hset key field value ? #例如hset post:2 title “second post”

hget key field ? ? ? ? ? ? #例如hget post:2 title,获取id为2的post的title值

hmset key field value [field value ...] ?#这个同上,批量存值

hmget key field [field ...] ? ? ? ? ? ? ? ? ? ? ?#批量取值,取得列表

hgetall key ? ? ? ? ? ? ? ? ?#取得key所对应的所有键值列表,这里给出个例子

友情链接: 爱易网 云虚拟主机技术 云服务器技术 程序设计技术 开发网站 APP开发教程
Copyright © 2013-2024 爱易网页 当前在线:1194人  网站在22时59分20秒内访问总人数:267216人 当前 42.91%  粤ICP备18100884号-2