diff --git a/redis/connection.py b/redis/connection.py index 790997b8b4..0229d28eed 100755 --- a/redis/connection.py +++ b/redis/connection.py @@ -588,7 +588,7 @@ def encode(self, value): elif isinstance(value, float): value = b(repr(value)) elif not isinstance(value, basestring): - value = str(value) + value = unicode(value) if isinstance(value, unicode): value = value.encode(self.encoding, self.encoding_errors) return value diff --git a/tests/test_encoding.py b/tests/test_encoding.py index b1df0a56c2..f0c67bec47 100644 --- a/tests/test_encoding.py +++ b/tests/test_encoding.py @@ -23,6 +23,13 @@ def test_list_encoding(self, r): r.rpush('a', *result) assert r.lrange('a', 0, -1) == result + def test_object_value(self, r): + unicode_string = unichr(3456) + u('abcd') + unichr(3421) + r['unicode-string'] = Exception(unicode_string) + cached_val = r['unicode-string'] + assert isinstance(cached_val, unicode) + assert unicode_string == cached_val + class TestCommandsAndTokensArentEncoded(object): @pytest.fixture()