当前位置:网站首页>Redis:哈希hash类型数据操作命令
Redis:哈希hash类型数据操作命令
2022-07-04 03:52:00 【dengfengling999】
单key:对象(属性名-属性值...)
哈希类型(hash)
Redis的hash 是一个string类型的key和value的映射表,这里的value是一系列的键值对,hash特别适合用于存储对象。
哈希类型的数据操作总的思想是通过key和field操作value,key是数据标识,field是域,value是我们感
兴趣的业务数据。
1.hset
语法:hset key field value [field value …]
功能:将键值对field-value设置到哈希列表key中,如果key不存在,则新建哈希列表,然后执行赋值,如果key下的field已经存在,则value值覆盖。
返回值:返回设置成功的键值对个数。
例如:
2.hget
语法:hget key field
功能:获取哈希表 key 中给定域 field 的值。
返回值:field域的值,如果key不存在或者field不存在返回nil。
例如:
3.hmset 和 hset功能一样
语法:hmset key field value [field value…]
功能:同时将多个 field-value (域-值)设置到哈希表 key 中,此命令会覆盖已经存在的field,hash表key不存在,创建空的hash表,再执行hmset.
返回值:设置成功返回ok,如果失败返回一个错误。
例如:
4.hmget
语法:hmget key field [field…]
功能:获取哈希表 key 中一个或多个给定域的值
返回值:返回和field顺序对应的值,如果field不存在,返回nil。
例如:
当不知道hsah中的file时用:
5.hgetall
语法:hgetall key
功能:获取哈希表 key 中所有的域和值
返回值:以列表形式返回hash中域和域的值,key不存在,返回空hash.
例如:
6.hdel
语法:hdel key field [field…]
功能:删除哈希表 key 中的一个或多个指定域field,不存在field直接忽略。
返回值:成功删除的field的数量。
例如:
7.hlen
语法:hlen key
功能:获取哈希表 key 中域field的个数
返回值:数值,field的个数。key不存在返回0.
例如:
8.hexists
语法:hexists key field
功能:查看哈希表 key 中,给定域 field 是否存在
返回值:如果field存在,返回1,其他返回0。
例如:stu1002上面name已经删除了
9.hkeys
语法:hkeys key
功能:查看哈希表 key 中的所有field域列表
返回值:包含所有field的列表,key不存在返回空列表
例如:
10.hvals
语法:hvals key
功能:返回哈希表 中所有域的值列表
返回值:包含哈希表所有域值的列表,key不存在返回空列表。
例如:
11.hincrby
语法:hincrby key field int
功能:给哈希表key中的field域增加int
返回值:返回增加之后的field域的值
例如:
12.hincrbyfloat
语法:hincrbyfloat key field float
功能:给哈希表key中的field域增加float
返回值:返回增加之后的field域的值
例如:
13.hsetnx
语法:hsetnx key field value
功能:将哈希表 key 中的域 field 的值设置为 value ,当且仅当域 field 不存在的时候才设置,否则不设置。
返回值:设值成功返回1,其他返回0.
例如:
边栏推荐
- 2021 RSC | Drug–target affinity prediction using graph neural network and contact maps
- [csrf-01] basic principle and attack and defense of Cross Site Request Forgery vulnerability
- 毕业总结
- User defined path and file name of Baidu editor in laravel admin
- Reduce function under functools
- 指针数组和数组指针
- vim映射命令
- 干货!基于GAN的稀有样本生成
- Pytest multi process / multi thread execution test case
- How to telecommute more efficiently | community essay solicitation
猜你喜欢
Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..
Pytest multi process / multi thread execution test case
Pointer array and array pointer
2022-07-03: there are 0 and 1 in the array. Be sure to flip an interval. Flip: 0 becomes 1, 1 becomes 0. What is the maximum number of 1 after turning? From little red book. 3.13 written examination.
如何远程办公更有效率 | 社区征文
Restore the subtlety of window position
Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure
leetcode刷题:二叉树07(二叉树的最大深度)
还原窗口位置的微妙之处
Brief explanation of depth first search (with basic questions)
随机推荐
批处理初识
DP83848+网线热拔插
Understand the principle of bytecode enhancement technology through the jvm-sandbox source code
[paddleseg source code reading] paddleseg calculation dice
pytest多进程/多线程执行测试用例
Support the first triggered go ticker
[csrf-01] basic principle and attack and defense of Cross Site Request Forgery vulnerability
VIM mapping command
如何有效远程办公之我见 | 社区征文
【华为云IoT】读书笔记之《万物互联:物联网核心技术与安全》第3章(上)
Perf simple process for multithreaded profile
hbuildx中夜神模拟器的配置以及热更新
User defined path and file name of Baidu editor in laravel admin
[book club issue 13] multimedia processing tool ffmpeg tool set
TCP-三次握手和四次挥手简单理解
2020 Bioinformatics | TransformerCPI
VIM add interval annotation correctly
Katalon中控件的参数化
RHCSA 07 - 用户与群组管理
深度优先搜索简要讲解(附带基础题)