-
Notifications
You must be signed in to change notification settings - Fork 180
Closed
Labels
Description
redis-py always returns hash values as bytes, even when they are valid floating point numbers. fakeredis is consistent with that when you set the value with HSET:
In [1]: import redis, fakeredis
In [2]: real = redis.StrictRedis()
In [3]: real.hset('h', 'x', 1.5)
Out[3]: 1
In [4]: real.hgetall('h')
Out[4]: {b'x': b'1.5'}
In [5]: fake = fakeredis.FakeStrictRedis()
In [6]: fake.hset('h', 'x', 1.5)
Out[6]: 1
In [7]: fake.hgetall('h')
Out[7]: {b'x': b'1.5'}
However, it breaks when you use HINCRBYFLOAT:
# Standard behavior
In [8]: real.hincrbyfloat('h2', 'x', 1.5)
Out[8]: 1.5
In [9]: real.hgetall('h2')
Out[9]: {b'x': b'1.5'}
# Incompatible behavior
In [10]: fake.hincrbyfloat('h2', 'x', 1.5)
Out[10]: 1.5
In [11]: fake.hgetall('h2')
Out[11]: {b'x': 1.5}
In [12]: fake.hget('h2', 'x')
Out[12]: 1.5
HINCRBY has the same problem, it changes the type to int:
In [13]: real.hincrby('h3', 'x', 15)
Out[13]: 15
In [14]: real.hgetall('h3')
Out[14]: {b'x': b'15'}
In [15]: fake.hincrby('h3', 'x', 15)
Out[15]: 15
In [16]: fake.hgetall('h3')
Out[16]: {b'x': 15}
In [17]: fake.hget('h3', 'x')
Out[17]: 15