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

Hashes type and operation of redis

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Hashes type and operation

Redis hash is a mapping table of field and value of type string. Its add and delete operations are all O (1) (average). Hash is particularly suitable for storing objects. Instead of 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. The reason for provincial memory is that when you create a new hash object, it starts with zipmap (also known as small hash). This zipmap is not really a hash table, but zipmap can save a lot of metadata storage overhead that hash itself needs compared to a normal hash implementation. Although the addition, deletion and lookup of zipmap are all O (n), the number of field of general objects is not too large. So using zipmap is also fast, that is to say, the average of adding and deleting is still O (1). If the size of field or value exceeds a certain limit, Redis will automatically replace zipmap internally with a normal hash implementation. This limit can be specified in the configuration file

Hash-max-zipmap-entries 64 # configuration fields up to 64

Hash-max-zipmap-value 512 # configure value with a maximum of 512 bytes

Hset

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

Such as: hset person name david

Hsetnx

Set hash field to the specified value, and create it first if key does not exist. If field already exists, returning 0menthnx means not exist.

Hmset

Set multiple field of hash at the same time.

Hget

Gets the specified hash field.

Hmget

Gets all the specified hash filed.

Such as: hmget person name age

Hincrby

The specified hash filed plus the given value.

Hexists

Tests whether the specified field exists.

Such as: hexists person age

Hlen

Returns the number of field of the specified hash.

Hdel

Delete field from an object

Such as: hdel person name

Hkeys

Returns all field of hash.

Such as: hkeys person

Hvals

Returns all value of hash.

Such as: hvals person

Hgetall

Get all the filed and value in a hash.

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

Wechat

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

12
Report