I am using redis to store some numeric values using HSET
. Here is an example command I am using
HSET "abc" "field" 123
I'm expecting this to store an integer, but when I do HGETALL
, it turns out to be a string:
1) "field"
2) "123"
My two questions are:
HSET
?From http://redis.io/topics/protocol#integer-reply:
The following commands will reply with an integer reply: SETNX, DEL, EXISTS, INCR, INCRBY, DECR, DECRBY, DBSIZE, LASTSAVE, RENAMENX, MOVE, LLEN, SADD, SREM, SISMEMBER, SCARD.
The reply for HSET
is a string, but it doesn't mean that Redis stored your info as such.
From http://redis.io/topics/memory-optimization
Since Redis 2.2 many data types are optimized to use less space up to a certain size. Hashes, Lists, Sets composed of just integers, and Sorted Sets, when smaller than a given number of elements, and up to a maximum element size, are encoded in a very memory efficient way that uses up to 10 times less memory (with 5 time less memory used being the average saving).
Also in this page there are commands to configure Redis to set threshold for that optimization.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With