Issue #58 resolved

Redis backend raises exception when calling get/set_multi with empty iterable/mapping

greggg
created an issue

Calling get_multi with an empty iterable:

from dogpile.cache import make_region

region = make_region().configure(
    'dogpile.cache.redis',
    arguments={
        'host': 'localhost',
        'port': 6379,
        'db': 0,
        'distributed_lock': True
    }
)
region.get_multi([])

Results in:

  File "/home/gg/dev/sandbox/dogpile.cache/dogpile/cache/region.py", line 509, in get_multi
    backend_values = self.backend.get_multi(keys)
  File "/home/gg/dev/sandbox/dogpile.cache/dogpile/cache/backends/redis.py", line 122, in get_multi
    values = self.client.mget(keys)
  File "/home/gg/.virtualenvs/dogpile/lib/python2.7/site-packages/redis/client.py", line 768, in mget
    return self.execute_command('MGET', *args)
  File "/home/gg/.virtualenvs/dogpile/lib/python2.7/site-packages/redis/client.py", line 461, in execute_command
    return self.parse_response(connection, command_name, **options)
  File "/home/gg/.virtualenvs/dogpile/lib/python2.7/site-packages/redis/client.py", line 471, in parse_response
    response = connection.read_response()
  File "/home/gg/.virtualenvs/dogpile/lib/python2.7/site-packages/redis/connection.py", line 339, in read_response
    raise response
ResponseError: wrong number of arguments for 'mget' command

Calling set_multi with an empty mapping:

from dogpile.cache import make_region

region = make_region().configure(
    'dogpile.cache.redis',
    arguments={
        'host': 'localhost',
        'port': 6379,
        'db': 0,
        'distributed_lock': True
    }
)
region.set_multi({})

Results in:

  File "/home/gg/dev/sandbox/dogpile.cache/dogpile/cache/region.py", line 790, in set_multi
    self.backend.set_multi(mapping)
  File "/home/gg/dev/sandbox/dogpile.cache/dogpile/cache/backends/redis.py", line 142, in set_multi
    self.client.mset(mapping)
  File "/home/gg/.virtualenvs/dogpile/lib/python2.7/site-packages/redis/client.py", line 782, in mset
    return self.execute_command('MSET', *items)
  File "/home/gg/.virtualenvs/dogpile/lib/python2.7/site-packages/redis/client.py", line 461, in execute_command
    return self.parse_response(connection, command_name, **options)
  File "/home/gg/.virtualenvs/dogpile/lib/python2.7/site-packages/redis/client.py", line 471, in parse_response
    response = connection.read_response()
  File "/home/gg/.virtualenvs/dogpile/lib/python2.7/site-packages/redis/connection.py", line 339, in read_response
    raise response
redis.exceptions.ResponseError: wrong number of arguments for 'mset' command

The other backends do not raise an exception in these cases, so for consistency, the Redis backend should not either.

Comments (2)

  1. Log in to comment