redis hashmap数据结构,使用散列来组织数据。对于一条有多个属性的数据可以通过hashmap来存储数据。
A hash with a few fields (where few means up to one hundred or so) is stored in a way that takes very little space, so you can store millions of objects in a small Redis instance.
While Hashes are used mainly to represent objects, they are capable of storing many elements, so you can use Hashes for many other tasks as well.
Every hash can store up to 232 - 1 field-value pairs (more than 4 billion).
根据redis官网介绍,redis一个hashmap可以存储(2的32次方-1)个属性。对于一条拥有属性(fields)数量在100左右的数据,redis官网推荐使用hashmap进行数据存储。
当每个hashmap属性数量小于hash-max-ziplist-entries设置值,且每fields的字节量小于hash-max-ziplist-value设置值时。redis对hashmap进行优化使用zipList数据结构进行存储,可以降低redis对hashmap的存储的空间消耗,提升存储性能,但是基于zipList结构的hashmap相比于基于Hash结构的HashMap来说,频繁的更新数据会造成更多的内存交换,因为当类似数组结构的zipList其中某个节点值改变后,后续的节点数据会根据更新数据的大小在链表中向前向后移动,更新性能会相对降低。