redis - Using Hashes

前端 未结 2 1304
死守一世寂寞
死守一世寂寞 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:08

    Yes, it's related to efficiency.

    We asked the always-helpful Pieter Noordhuis, one of Redis’ core developers, for input, and he suggested we use Redis hashes. Hashes in Redis are dictionaries that are can be encoded in memory very efficiently; the Redis setting ‘hash-zipmap-max-entries’ configures the maximum number of entries a hash can have while still being encoded efficiently. We found this setting was best around 1000; any higher and the HSET commands would cause noticeable CPU activity. For more details, you can check out the zipmap source file.

    Small hashes are encoded in a special way (zipmaps), that is memory efficient, but makes operations O(N) instead of O(1). So, with one zipmap with 100k fields instead of 100 zipmaps with 1k fields you gain no memory benefits, but all your operations get 100 times slower.

提交回复
热议问题