Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HINCRBYFLOAT changes hash value type to float #90

Closed
vitawasalreadytaken opened this issue Aug 24, 2015 · 4 comments
Closed

HINCRBYFLOAT changes hash value type to float #90

vitawasalreadytaken opened this issue Aug 24, 2015 · 4 comments

Comments

@vitawasalreadytaken
Copy link

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
@vitawasalreadytaken
Copy link
Author

I started fixing this here: https://github.com/ze-phyr-us/fakeredis/commit/859e0e5edaf82e1e95ce57d8444ea1e0d233a4ee

It seems that incr, decr and friends have the same problem. I'm happy to fix them too and submit a PR later this week when I have more time.

@ikreymer
Copy link
Contributor

ikreymer commented Apr 3, 2016

I just ran into this issue as well with hincrby.. Are you still interesting in submitting this PR?

@bmerry
Copy link
Collaborator

bmerry commented Nov 10, 2017

This is fixed in fakenewredis, a fork of fakeredis.

@bmerry
Copy link
Collaborator

bmerry commented Mar 22, 2018

Fixed in 0.10.1.

@bmerry bmerry closed this as completed Mar 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants