From e29752863e729d7161d1b51029fc0b451d712c52 Mon Sep 17 00:00:00 2001 From: Javier Candeira Date: Wed, 25 Nov 2015 21:15:10 +1100 Subject: [PATCH] fix getitem syntax for redis get when value is the empty string --- redis/client.py | 2 +- tests/test_commands.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/redis/client.py b/redis/client.py index c40662f90f..e426abe0b5 100755 --- a/redis/client.py +++ b/redis/client.py @@ -885,7 +885,7 @@ def __getitem__(self, name): doesn't exist. """ value = self.get(name) - if value: + if value is not None: return value raise KeyError(name) diff --git a/tests/test_commands.py b/tests/test_commands.py index 45206b2e7f..7293810321 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -341,6 +341,10 @@ def test_getitem_raises_keyerror_for_missing_key(self, r): with pytest.raises(KeyError): r['a'] + def test_getitem_does_not_raise_keyerror_for_empty_string(self, r): + r['a'] = b("") + assert r['a'] == b("") + def test_get_set_bit(self, r): # no value assert not r.getbit('a', 5)