Get the App
SLTechnology News&Howtos  ›  Database  › 

Redis Notes-Hash data Type (3)

Shulou Source: shulou.com Published: 2022-06-01 12:30:37 11月15日 Update

Hash is a mapping table for field and value of type string. Its add and delete operations are both 0 (1) (average). Hash is particularly suitable for storing objects. Compared to storing each field of an object as a single string type, storing an object in a hash type takes up less memory and makes it easier to access the entire object.

Hset

Set hash field to the specified value. If key does not exist, create it first.

127.0.0.1 lijie 6379 > hset user:001 name lijie (integer) 1127.0.0.1 hget user:001 name "lijie" hsetnx

Set hash field to the specified value, and create it first if key does not exist. Returns 0 if it exists

127.0.0.1 hset user:001 name lijie (integer) 1127.0.0.1 hget user:001 name "lijie" 127.0.0.1 hget user:001 name 6379 > hset user:001 sex men (integer) 1127.0.0.1 hget user:001 name 6379 > hset user:001 sex women (integer)

Set multiple field of hash simultaneously

Hmget user:002 name1) "chenxl" 127.0.0.1 sex menOK127.0.0.1:6379 > hmget user:002 name age sex1) "chenxl" 2) "30" 3) "men" hget

Get a field in the hash table

127.0.0.1 hmget 6379 > hget user:002 name "chenxl"

Gets the values of all specified multiple hash field

127.0.0.1 men 6379 > hmget user:002 name age sex1) "chenxl" 2) "30" 3) "men" hincrby

Specified hash field plus specified value

127.0.0.1 25hexists 6379 > hincrby user:002 age-5 (integer)

Test whether the specified field exists

127.0.0.1 hexists user:002 sex 6379 > hexists user:002 wang (integer) 0127.0.0.1 hexists user:002 sex (integer) 1hlen

Returns the number of field of the specified hash

127.0.0.1 3hdel 6379 > hlen user:002 (integer)

Delete the field of the specified hash

127.0.0.1 hget user:002 age 6379 > hget user:002 age "25" 127.0.0.1 integer 6379 > hget user:002 age (nil) hkeys

Returns all field of hash

127.0.1 sex 6379 > hkeys user:0021) "name" 2) "sex" hvals

Returns all value of hash

127.0.1 men 6379 > hvals user:0021) "chenxl" 2) "men" hgetall

Get all the field and value of a hash

127.0.1 chenxl 6379 > hgetall user:0021) "name" 2) "chenxl" 3) "sex" 4) "men"

Tags: Objects types multiple fields storage memory single simultaneous quantity table access testing data notes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Information Docker Linux Huawei