Redis开发运维实践数据操作之哈希操作

    xiaoxiao2026-09-20  0

    2.6.1 设置hash值

    hset key field value

    设置hash field为指定值,如果key不存在,则先创建。

    hsetnx

    设置hash field为指定值,如果 key 不存在,则先创建。如果 field已经存在,返回0,nx是not exist的意思。

    2.6.2 获取hash值

    hget key field

    获取指定的hash field

    hmget key filed1....fieldN

    获取全部指定的hash filed

    hmset key filed1 value1 ... filedN valueN

    同时设置hash的多个field

    2.6.3 递增某一个域的值

    hincrby key field integer

    将指定的hash filed 加上给定值

    2.6.4 判断某一个域是否存在

    hexists key field

    测试指定field是否存在

    2.6.5 删除域

    hdel key field

    删除指定的hash field

    2.6.6 获取域的数量

    hlen key

    返回指定hash的field数量

    2.6.7 获取所有的域名

    hkeys key

    返回hash的所有field

    2.6.8 获取所有域的值

    hvals key

    返回hash的所有value

    2.6.9 获取所有域名和值

    hgetall

    返回hash的所有filed和value

    本文为《Redis开发运维实践指南》内容,该书作者为黄鹏程,已授权云栖社区转载。

    最新回复(0)