-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
hset for key=0 raises redis.exceptions.DataError #1337
Comments
It appears that your first suggestion (comparing In [3]: r.hset('my-hash', mapping={'foo': 'bar'})
Out[3]: 1
# manually sending commands to a connection to avoid the `hset` checks
In [5]: conn = r.connection_pool.get_connection('_')
In [6]: conn.send_command('HSET', 'my-hash', '', 'empty value')
In [7]: conn.read_response()
Out[7]: 1
# notice the empty string key...
In [8]: r.hgetall('my-hash')
Out[8]: {b'foo': b'bar', b'': b'empty value'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
In the new
redis-py
version3.5.0
I have noticed some additional checks inRedis.hset
method. Because of these checks the following corner case now fails:raising an error
redis.exceptions.DataError: 'hset' with no key value pairs
.The problem is in this line where
not key
check is made.Potential solutions:
not key
intokey is None
check. This covers casekey=0
but it doesn't raise an error ifkey=''
where it probably should?not key
intokey is None or not str(key)
. I think this should cover all cases but it's an additional casting operation.Let me know if any of these options makes sense. I would be happy to submit a PR for this.
For now, I'll just make sure that I always cast
key
argument into string in my code to avoid this issue.The text was updated successfully, but these errors were encountered: