Tony Han
Tony Han

Reputation: 2220

Choose between HINCRBY and INCR for redis

I have a forum and want to save and show topics' view count using redis. It seems I have two methods to do this: HINCRBY and INCR. Which should I choose? And why?( Given I have 10,000,000 topics in total )

With HINCRBY I can use one key to keep all values, but the hash is big. But with INCR I'll have many keys.

Upvotes: 2

Views: 3816

Answers (1)

Liviu Costea
Liviu Costea

Reputation: 3784

If you use hashes (so go with HINCRBY) you can reduce your memory footprint if you can use multiple hashes instead of one: http://redis.io/topics/memory-optimization#using-hashes-to-abstract-a-very-memory-efficient-plain-key-value-store-on-top-of-redis
All you have to do is find some way of distributing your keys into multiple hashes, not just one, for example these guys found a way: http://instagram-engineering.tumblr.com/post/12202313862/storing-hundreds-of-millions-of-simple-key-value

Upvotes: 8

Related Questions