Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the Hash Operation of Redis by php

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how php to achieve the Hash operation of Redis, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Hash operation

/ / assign values to the fields in the hash table. Success returns 1 and failure returns 0. If the hash table does not exist, the table will be created first and then the value will be assigned. If the field already exists, the old value will be overwritten. $ret = $redis- > hSet ('user',' realname', 'jetwu'); / / gets the value of the specified field in the hash table. Returns false if the hash table does not exist. $ret = $redis- > hGet ('user',' realname'); / / check whether a field in the hash table exists, return true if it exists, return false otherwise. $ret = $redis- > hExists ('user',' realname'); / / Delete a field in the hash table. Deleting multiple fields is not supported. Returns 1 successfully, otherwise 0. $ret = $redis- > hDel ('user',' realname'); / / set multiple field values for a hash table at the same time. True was returned successfully. $ret = $redis- > hMset ('user', [' name' = > 'jet',' age' = > 18]); / / get multiple field values of a hash table at the same time. The value of the field that does not exist is false. $ret = $redis- > hMget ('user', [' name', 'age']); / / gets all the fields and values of a hash table. $ret = $redis- > hGetAll ('user'); / / get all the field names of a hash table. An empty array is returned if the hash table does not exist, and false is returned if the key is not a hash table. $ret = $redis- > hKeys ('user'); / / gets all the field values of a hash table. $ret = $redis- > hVals ('user'); / / assign values to fields that do not exist in the hash table. If the hash table does not exist, create it first, and do nothing if the field already exists. True is returned if the setting is successful, otherwise false is returned. $ret = $redis- > hSetNx ('user',' realname', 'jetwu'); / / gets the number of fields in a hash table. Returns 0 if the hash table does not exist, and returns false if the key is not a hash table. $ret = $redis- > hLen ('user'); / / add the specified incremental value to the specified field in the hash table, which is equivalent to a subtraction operation if the incremental value is negative. If the hash table does not exist, create it first. If the field does not exist, initialize the value to 0 before performing the operation. If the field value is a string, return false. Set the new value of the returned field successfully. $ret = $redis- > hIncrBy ('user',' age', 10); / / add the specified floating point increment value to the specified field in the hash table. Ret = $redis- > hIncrBy ('user',' age', 1.5). This is all the content of the article "how php implements the Hash operation of Redis". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report