Redis-php-hash table-related APIs

Source: Internet
Author: User
Tags array example

Hashes related================================hdel-Delete a hash keyhexists-check if the hash key exists Hget-get the value of a hash key hgetall-get a hash table of all keys and Valu Ehincrby-Adds an integer value to a key in the hash table hincrbyfloat-Adds a floating-point value to a key in the hash table Hkeys-Gets the number of keys in the hash table for all Keyhlen-ha tables Hmget-gets multiple keys in the hash table Value Hmset-Sets the value of multiple keys for the hash table Hset-sets a value for a key in the hash list hsetnx-sets a value for the key when there is no key in the hash table hvals-gets all the values in the hash tableHsetThe-----------------------------------sets a value for a key in the hash table. If the value already exists, return false parameter: Key Hash table name Hashkeyvalue return value: LONG If set successfully, returns 1 if key already exists, it is replaced with a new value and returns 0. Failure returns 0 Example: $redis->delete (' h ') $redis->hset (' h ', ' key1 ', ' hello '), $redis->hget (' h ', ' key1 '); $redis->hset (' h ', ' key1 ', ' plop '); $redis->hget (' h ', ' key1 ');hsetnx-----------------------------------when a key does not exist in the hash table, set a value parameter to the key: Key hashtable name Hashkeyvalue return value: BOOL: Successful return TRUE. Failed to return FALSE. Example: $redis->delete (' h ') $redis->hsetnx (' h ', ' key1 ', ' hello '), $redis->hsetnx (' h ', ' key1 ', ' world ');Hget-----------------------------------gets the value of a hash key. If the hash table does not exist or the corresponding key does not exist, return false parameter: Keyhashkey return value: STRING If the hash table does not exist or The expected key does not exist and returns false example: $redis->delete (' h ') $redis->hset (' h ', ' key1 ', ' hello '); $redis->hget (' h ', ' key1 ');Hlen-----------------------------------the number of keys in a table key: Key return value: The number of key in a LONG table. If the hash table does not exist, or if the value of the corresponding key is not a hash type, the return false example : $redis->delete (' h ') $redis->hset (' h ', ' key1 ', ' hello '), $redis->hset (' h ', ' Key2 ', ' plop '); $redis->hlen ( ' H ');Hdel-----------------------------------Delete a hash key. If the hash table does not exist or the corresponding key does not exist, return the false\ parameter: Keyhashkey return value: BOOL: TRUE returned successfully. Failed to return FALSE. Example: $redis->delete (' h ') $redis->hset (' h ', ' key1 ', ' hello '), $redis->hset (' h ', ' Key2 ', ' plop '); $redis Hset (' h ', ' Key2 ');Hkeys-----------------------------------get all key parameters in the hash table: Key:key return Value: array Example: $redis->delete (' h '), $redis->hset (' H ', ' A ', ' X '), $redis->hset (' h ', ' B ', ' Y '), $redis->hset (' H ', ' C ', ' Z '), $redis->hset (' h ', ' d ', ' t '); Var_dump ($ Redis->hkeys (' h ')); Output: Array (4) {[0]=> string (1) "A" [1]=> string (1) "B" [2]=> string (1) "C" [3]=> string (1) "D"} Order is randomhvals-----------------------------------get all the value parameters in the hash table: parameter: Key return value: array Example: $redis->delete (' h '), $redis->hset (' h ', ' a ', ' x '); $redis->hset (' h ', ' B ', ' Y '), $redis->hset (' H ', ' C ', ' Z '), $redis->hset (' h ', ' d ', ' t '); Var_dump ($redis- >hvals (' h ')); Output: Array (4) {[0]=> string (1) "X" [1]=> string (1) "Y" [2]=> string (1) "Z" [3]=> string (1) "T"} order is randomHgetall-----------------------------------get all the key and value examples in a hash table: $redis->delete (' h '); $redis->hset (' h ', ' a ', ' X '); $redis->hset (' h ', ' B ', ' Y '), $redis->hset (' H ', ' C ', ' Z '), $redis->hset (' h ', ' d ', ' t '); Var_dump ($redis, Hgetall (' h ')); Output: Array (4) {["a"]=> string (1) "X" ["B"]=> string (1) "Y" ["C"]=> string (1) "Z" ["D"]=> string (1) "T"} The order is random.hexists-----------------------------------Check the hash key for the existence of parameters: Keymemberkey return value: BOOL: There is a return true, there is no return false example: $redis->hset (' H ' A ', ' X '); $redis->hexists (' h ', ' a '); $redis->hexists (' h ', ' Nonexistingkey ');Hincrby-----------------------------------add an integer value parameter to a key in the hash table: Keymembervalue: (integer) returns the value of an integer that is incremented: an example of a value after a LONG increase: $redis- >delete (' h '); $redis->hincrby (' h ', ' X ', 2); $redis->hincrby (' h ', ' X ', 1);hincrbyfloat-----------------------------------Add a floating-point numeric parameter to a key in the hash table: Keymembervalue: (float) The value of the floating-point value to increment: an example of an increment of float: $redis- >delete (' h '); $redis->hincrbyfloat (' h ', ' X ', 1.5); $redis->hincrbyfloat (' h ', ' X ', 1.5); $redis Hincrbyfloat (' h ', ' X ',-3.0);Hmset-----------------------------------set the value parameter for multiple keys for a hash table: Keymembers:key→value array return value: BOOL Example: $redis->delete (' User : 1 '); $redis->hmset (' user:1 ', Array (' name ' = ' Joe ', ' salary ' = + 2000));Hmget-----------------------------------get an example of the value of multiple keys in a hash table: $redis->delete (' h '); $redis->hset (' h ', ' field1 ', ' value1 $redis->hset (' h ', ' field2 ', ' value2 '); $redis->hmget (' h ', Array (' field1 ', ' field2 '));

Redis-php-hash table-related APIs

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.