Redis:HGETALL的排序问题

HGETALL 介绍

Returns all fields and values of the hash stored at key. In the returned value, every field name is followed by its value, so the length of the reply is twice the size of the hash.

Time complexity:
O(N) where N is the size of the hash.

Return
Array reply: list of fields and their values stored in the hash, or an empty list when key does not exist.

Hash有两种存储格式:ziplist、hashtable

默认情况下,Redis的Hash是使用ziplist进行存储的,当超出一定限制后,再改为hashtable进行存储。

ziplist是双向链表,存储顺序和数据插入顺序一致。查询结果顺序和存储顺序一致。

hashtable是字典结构,查询结果顺序和插入顺序不一致。

两种情况都满足时,Hash会使用 ziplist 进行存储:

否则,改为hashtable存储。

查询数据存储结构:OBJECT ENCODING key

结论:

  • HGETALL 没有顺序性。如果需要顺序,业务上层排序。
  • Hash会根据数据量进行数据结构调整。目的:提高性能。

Original: https://www.cnblogs.com/txtp/p/16743010.html
Author: 天下太平
Title: Redis:HGETALL的排序问题

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/584077/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球