brpoplpush empty key handling and Nonetype #322

Closed
nayfield opened this Issue Feb 25, 2013 · 2 comments

2 participants

@nayfield

When a redis list contains an empty key ("") the operation BRPOPLPUSH returns Nonetype which is indistinguishable from a timeout.

BRPOP and RPOP work as expected.

Here is a list with one item (blank). First we RPOP twice - we get the empty item ("") as well as a Nonetype.

>>> myr.lpush('fddf', "")
1L

>>> foo = myr.rpop('fddf')
>>> foo
''
>>> foo = myr.rpop('fddf')
>>> foo
>>> 

Now we BRPOP. As expected, with the list which hit and result in a tuple.

>>> myr.lpush('fddf', "")
1L

>>> foo = myr.brpop('fddf')
>>> foo
('fddf', '')
>>> foo = myr.brpop('fddf', 1)
>>> foo
>>> 

Now we use BRPOPLPUSH. Both responses are Nonetype.

>>> myr.lpush('fddf', "")
1L

>>> foo = myr.brpoplpush('fddf', 'trashbin')
>>> foo
>>> foo = myr.brpoplpush('fddf', 'trashbin', 1)
>>> foo
>>> 

redis-cli for comparison:

redis 127.0.0.1:6379> brpoplpush fddf trashbin 1
""
redis 127.0.0.1:6379> brpoplpush fddf trashbin 1
(nil)
(1.74s)
@andymccurdy andymccurdy pushed a commit that referenced this issue Feb 25, 2013
andy fix for #322 11da764
@andymccurdy
Owner

Should be fixed in master.

@nayfield

Fastest ticket ever, I was going to look at the code tomorrow and give you a pull request. You're my hero. Thanks.

@salimane salimane added a commit to salimane/redis-py that referenced this issue Apr 16, 2013
@salimane salimane Merge remote-tracking branch 'upstream/master'
* upstream/master:
  changelog
  allow client.transaction() to return the value of func based on kwarg. fix for #331
  changelog
  Added note that redis-py requires a running Redis server to connect to along with a link to installation instructions.
  Catch exception, not anything (which could be KeyboardInterrupt).
  A base class for server-side exceptions to be grouped by
  Do not discard pipeline unless in multi.
  changelog
  fix for #322
  adding docs structure and updating .gitignore file
  Switched callback for SREM from bool to int.
  Fix a typo in README
  Convert response from bytes to str for Python 3 compatibility
  Add CLIENT GETNAME/SETNAME support
  Pipelines now have a __len__() method.
  in _compat for py3k only encode if param is not bytes type in b()
724b433
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment