Get the App
SLTechnology News&Howtos  ›  Database  › 

REDIS HGETALL outputs the results sequentially

Shulou Source: shulou.com Published: 2022-06-01 09:38:06 10月27日 Update

Today, in the project, we use the hash structure of Redis to save some commodity data, which is put in according to the commodity id from small to large. Then now if you want to hgetAll it out, you can also take it out in id order, but it is found that the result is not like this, and the output is out of order.

With the decision to see why in the end, found something fishy.

It is pointed out in Design and implementation of REDIS

When creating a blank hash table, the program uses REDIS_ENCODING_ZIPLIST encoding by default, and the program changes the encoding from REDIS_ENCODING_ZIPLIST to REDIS_ENCODING_HT when any of the following conditions are met:

The length of a key or value in the hash table is greater than server.hash_max_ziplist_value (the default is 64).

The number of nodes in the compressed list is greater than server.hash_max_ziplist_entries (default is 512).

Then I looked at my own data and found that the length of the value was greater than 64, so I adopted the coding format of hashtable. It's disordered.

Tags: Code commodity data program length hash result output from small to large middle finger small quantity time condition format fishy blank structure node project Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL vpn Shulou Information Redmi Microsoft