redis - Using Hashes

前端 未结 2 1306
死守一世寂寞
死守一世寂寞 2021-02-06 16:27

I\'m implementing a social stream and a notification system for my web application by using redis. I\'m new to redis and I have some doubts about hashes and their efficiency.

2条回答
  •  灰色年华
    2021-02-06 17:09

    Basically, they want the number of values stored in a single hash to not exceed 1000. Probably, they set up their Redis instance configuration to work nicely with this number (thy set hash-zipmap-max-entries).

    Every time an hash will exceed the number of elements or element size specified it will be converted into a real hash table, and the memory saving will be lost.

    -- http://redis.io/topics/memory-optimization

    As I understand, your question is "why exactly 1000 and not more?" Well, it's because they had to choose between space efficiency and speed. Space-efficient representation has operation complexity O(N), not O(1) as normal hashes - it is N times slower, but takes less memory.

    They tested different values and found that 1000 is a good compromise solution - takes not much space, yet still fast enough.

提交回复
热议问题