Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the reidis hash type hash

Shulou Source: shulou.com Published: 2022-06-03 06:02:45 09月18日 Update

This article mainly introduces "how to use reidis hash type hash". In daily operation, I believe many people have doubts about how to use reidis hash type hash. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use reidis hash type hash"! Next, please follow the editor to study!

Redis's hash is a mapping table of key and value of type string, where value is a series of key-value pairs, and hash is particularly suitable for storing objects. The general idea of hash-type data operations is to operate through key and field value,key is the data identity, field is the domain, and value is the business data. Hset

Syntax: hset key field value [field value...]

Function: set the key value pair field-value to the hash list key, if the key does not exist, create a new hash list, and then perform the assignment. If the field under key already exists, the value is overwritten.

Return value: returns the number of key-value pairs successfully set.

Hget

Syntax: hget key field

Function: gets the value of the given field field in the hash table key.

Return value: the value of the field field, which returns nil if key does not exist or field does not exist.

Hgetall

Syntax: hgetall key

Function: get all the fields and values in the hash table key

Return value: returns the values of fields and fields in hash in the form of a list. Key does not exist and returns empty hash.

Hdel

Syntax: hdel key field [field...]

Function: delete one or more specified domain field in the hash table key, and no field directly ignores it.

Return value: the number of field successfully deleted.

Hlen

Syntax: hlen key

Function: get the number of domain field in the hash table key

Return value: numeric value, number of field. Key does not exist and returns 0.

Hexists

Syntax: hexists key field

Function: check whether the given domain field exists in the hash table key

Return value: if field exists, it returns 1, and the other returns 0.

Hkeys

Syntax: hkeys key

Function: view a list of all field fields in the hash table key

Return value: contains a list of all field. There is no empty list returned for key.

Hvals

Syntax: hvals key

Function: returns a list of values for all fields in the hash table

Return value: contains a list of all field values in the hash table. There is no empty list returned in key.

Hsetnx

Syntax: hsetnx key field value

Function: set the value of the field field in the hash table key to value, and set it only if the domain field does not exist, otherwise it will not be set.

Return value: if the value is successful, it returns 1, and the other returns 0.

At this point, the study on "how to use the reidis hash type hash" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Hash function grammar type learning success number data more help utility next business multiple object form idea numerical value quantity article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Redmi Microsoft NVidia MySQL