diff options
-rw-r--r-- | redis/__init__.py | 15 | ||||
-rw-r--r-- | redis/client.py | 13 | ||||
-rw-r--r-- | redis/exceptions.py | 2 | ||||
-rw-r--r-- | tests/server_commands.py | 2 |
4 files changed, 24 insertions, 8 deletions
diff --git a/redis/__init__.py b/redis/__init__.py index 894f8e1..499f658 100644 --- a/redis/__init__.py +++ b/redis/__init__.py @@ -1,12 +1,19 @@ # legacy imports from redis.client import Redis, ConnectionPool -from redis.exceptions import RedisError, ConnectionError, AuthenticationError -from redis.exceptions import ResponseError, InvalidResponse, InvalidData +from redis.exceptions import ( + AuthenticationError, + ConnectionError, + DataError, + InvalidResponse, + RedisError, + ResponseError, + ) + __version__ = '2.2.3' __all__ = [ 'Redis', 'ConnectionPool', - 'RedisError', 'ConnectionError', 'ResponseError', 'AuthenticationError' - 'InvalidResponse', 'InvalidData', + 'RedisError', 'ConnectionError', 'ResponseError', 'AuthenticationError', + 'InvalidResponse', 'DataError', ] diff --git a/redis/client.py b/redis/client.py index 2c7e404..8e85a90 100644 --- a/redis/client.py +++ b/redis/client.py @@ -4,8 +4,15 @@ import time import warnings from itertools import chain, imap, islice, izip from redis.connection import ConnectionPool, Connection -from redis.exceptions import ConnectionError, ResponseError, WatchError -from redis.exceptions import RedisError, AuthenticationError +from redis.exceptions import ( + AuthenticationError, + ConnectionError, + DataError, + RedisError, + ResponseError, + WatchError, +) + def list_or_args(command, keys, args): # returns a single list combining keys and args @@ -1145,6 +1152,8 @@ class Redis(threading.local): in the hash ``name`` """ items = [] + if len(mapping) == 0: + raise DataError for pair in mapping.iteritems(): items.extend(pair) return self.execute_command('HMSET', name, *items) diff --git a/redis/exceptions.py b/redis/exceptions.py index b3257ac..193016e 100644 --- a/redis/exceptions.py +++ b/redis/exceptions.py @@ -15,7 +15,7 @@ class ResponseError(RedisError): class InvalidResponse(RedisError): pass -class InvalidData(RedisError): +class DataError(RedisError): pass class WatchError(RedisError): diff --git a/tests/server_commands.py b/tests/server_commands.py index 8cae871..fb5f3f5 100644 --- a/tests/server_commands.py +++ b/tests/server_commands.py @@ -994,7 +994,7 @@ class ServerCommandsTestCase(unittest.TestCase): d = {'a': '1', 'b': '2', 'c': '3'} self.assert_(self.client.hmset('foo', d)) self.assertEqual(self.client.hgetall('foo'), d) - self.assertRaises(redis.ResponseError, self.client.hmset, 'foo', {}) + self.assertRaises(redis.DataError, self.client.hmset, 'foo', {}) def test_hmget(self): d = {'a': 1, 'b': 2, 'c': 3} |