Does Redis only allow string representation but not numeric value

人走茶凉 提交于 2019-12-10 01:37:08

问题


I am getting mixed answers on my research here.

  • Can someone verify that the Redis Server can only store representation of any numerical values?

  • For instance, 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 to Redis?

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

Thanks


回答1:


Redis stores everything in string or in its string representation. Even functions like INCR work by first parsing it into INTEGER then performing the operation

Note: this is a string operation because Redis does not have a dedicated integer type. The string stored at the key is interpreted as a base-10 64 bit signed integer to execute the operation.

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.

And w.r.t Jedis; looking at the source i don't think it supports anything else other than strings




回答2:


Double numbers could be stored as string if you're using JSON codecs, but it also could be stored in binary format used by Kryo, CBOR, MsgPack codecs which are supported by Redis based framework for Java - Redisson.



来源:https://stackoverflow.com/questions/32389158/does-redis-only-allow-string-representation-but-not-numeric-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!