Does Redis provide only a string representation but not a numeric value

I get mixed answers to my research here.

  • Can anyone verify that the Redis server can only store data of any numerical values?

  • For example, if I use a Java client (Jedis) with a double type in lpush, do I need to convert it to the equivalent of a string type before sending it to Redis?

  • Or is there a way I can send a real numeric type, like double? If so, is there any code example on how to do this?

thanks

+6
source share
2 answers

Redis stores everything in a string or in a string representation. Even functions like INCR first process it in INTEGER and then perform the operation

Note: this is a string operation because Redis does not have a special integer type. The string stored in the key is interpreted as a signed integer based on 10 bits, which is performed to perform the operation.

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

And wrt jedis; looking at the source, I donโ€™t think it supports anything other than strings

+10
source

Duplicate numbers can be saved as a string if you use JSON codecs, but can also be stored in the binary format used by the Kryo, CBOR, MsgPack codecs, which are supported by the Redis platform for Java - Redisson .

0
source

All Articles