diff options
author | Ionuț Arțăriși <mapleoin@lavabit.com> | 2011-04-05 14:48:57 +0200 |
---|---|---|
committer | Ionuț Arțăriși <mapleoin@lavabit.com> | 2011-04-05 14:48:57 +0200 |
commit | d63088a26aa76989c6be785ba483e402c3a1e4a8 (patch) | |
tree | 114cee309488ffc4d3a76cf5401a9da30f5bb153 /redis/client.py | |
parent | 2eb518a7c53702168f5e987c1741512ac5e9b4d7 (diff) | |
download | redis-py-d63088a26aa76989c6be785ba483e402c3a1e4a8.tar.gz |
trying to getitem on a key that doesn't exist should raise a KeyError
Diffstat (limited to 'redis/client.py')
-rw-r--r-- | redis/client.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/redis/client.py b/redis/client.py index bddb8c8..744d221 100644 --- a/redis/client.py +++ b/redis/client.py @@ -443,10 +443,20 @@ class Redis(threading.local): def get(self, name): """ - Return the value at key ``name``, or None of the key doesn't exist + Return the value at key ``name``, or None if the key doesn't exist """ return self.execute_command('GET', name) - __getitem__ = get + + def __getitem__(self, name): + """ + Return the value at key ``name``, raises a KeyError if the key + doesn't exist. + """ + _name = self.get(name) + if _name: + return _name + else: + raise KeyError(name) def getbit(self, name, offset): "Returns a boolean indicating the value of ``offset`` in ``name``" |