Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REDIS: Numeric keys (1,2,3..) vs compressed keys (A9z3,A9z4..)?

We are having fun with Redis on a Nodejs server - great combo btw. The question is out of curiosity and should be treated as "in theory".

Is there any performance difference between storing your values on numeric keys (1,2,3,4...) over compressed keys (A9z3,A9z4,A9z5...). I'm thinking select speed only in a database with 2 million keys.

I hope the question is not too damn stupid, best regards ;)

like image 924
Ulrik M Avatar asked Feb 05 '11 02:02

Ulrik M


People also ask

How many keys can Redis hold?

Redis can handle up to 2^32 keys, and was tested in practice to handle at least 250 million keys per instance. Every hash, list, set, and sorted set, can hold 2^32 elements. In other words your limit is likely the available memory in your system.

What are keys in Redis?

Redis Keys are Ideal for Keeping Track of Lots of Strings. For the (simple string) key-value data type Redis allows you to set, get, delete, and increment arbitrary string <key, value> pairs. You can only have 1 value at a time for each key (i.e. set is destructive assignment). You can also delete keys.

How do I count keys in Redis?

The first command you can use to get the total number of keys in a Redis database is the DBSIZE command. This simple command should return the total number of keys in a selected database as an integer value. The above example command shows that there are 203 keys in the database at index 10.

Can Redis store numbers?

Redis stores integers in their integer representation, so for string values that actually hold an integer, there is no overhead for storing the string representation of the integer.


2 Answers

This was answered by antirez on the Google Group. And the answer is no for 2.0 and 2.2:

http://groups.google.com/group/redis-db/browse_thread/thread/305238470e337eb9/c92ae11089541925?lnk=gst#c92ae11089541925

like image 66
seppo0010 Avatar answered Sep 28 '22 16:09

seppo0010


If you are storing the keys as a list or a string, there should be no performance difference, as the integers are stored the same way as strings in memory. So, there would be no noticeable performance difference when selecting a string or an integer.

Memory wise, the compressed keys would have less overhead in memory "because with small keys and values there is a lot of overhead." But we are talking bytes here. (http://redis.io/topics/faq)

like image 44
Colum Avatar answered Sep 28 '22 14:09

Colum