Get the App
SLTechnology News&Howtos  ›  Database  › 

Redis hash type

Shulou Source: shulou.com Published: 2022-06-01 12:19:22 10月04日 Update

The key value of hash type is also a dictionary structure, which stores the mapping of field and field value, but the field value can only be a character string, and other data types are not supported. In other words, hash type cannot nest other data types. A hash-type key can contain up to 2^32-1 fields. Other than hash types, Redis also does not support nesting of data types. For example, each element of a collection type can only be a string, not another collection or hash table.

Hash types are appropriate for storing objects: they use object categories and object IDs to form key names, fields to represent attributes of objects, and field values to store attribute values. For example, to store a car object with ID 2, three fields named color, name, and price could be used to store the color, name, and price of the car.

Assignment and value:HSET key field valueHGET key fieldHMSET key field value [field value...] HMGET key field [field ...] HGETALL key Determine whether the field exists:HEXISTS key field When the field does not exist Assign:HSETNX key field value Increase number:HINCRBY key field increase Delete field:HDEL key field [field...] Get field name only:HKEYS key Get field value only:HVALS key Number of fields obtained:HLEN key

Tags: Fields types objects storage data characters strings attributes cars support prices elements names dictionaries in other words numbers quantities categories structures at most Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Docker NVidia OPPO Reno vpn