summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBo Bayles <bbayles@gmail.com>2018-11-21 19:55:56 -0600
committerBo Bayles <bbayles@gmail.com>2018-11-21 19:55:56 -0600
commit683675530cbdad2a96a2b88d60102cce649876bd (patch)
treedc4ec1499cd29a3f651094f53c2be5cde74c7384
parent1df87fc82348a26cd638bd82b431bf902522a8c4 (diff)
downloadredis-py-683675530cbdad2a96a2b88d60102cce649876bd.tar.gz
Remove decoding from georadius
-rwxr-xr-xredis/client.py15
-rw-r--r--tests/test_commands.py22
2 files changed, 13 insertions, 24 deletions
diff --git a/redis/client.py b/redis/client.py
index a357368..957081c 100755
--- a/redis/client.py
+++ b/redis/client.py
@@ -378,17 +378,6 @@ def parse_cluster_nodes(response, **options):
return dict(_parse_node_line(line) for line in raw_lines)
-def text_or_binary(response):
- """
- Return the response as text data if possible (decoded as utf-8), otherwise
- return it unmodified.
- """
- try:
- return response.decode('utf-8')
- except UnicodeDecodeError:
- return response
-
-
def parse_georadius_generic(response, **options):
if options['store'] or options['store_dist']:
# `store` and `store_diff` cant be combined
@@ -403,7 +392,7 @@ def parse_georadius_generic(response, **options):
if not options['withdist'] and not options['withcoord']\
and not options['withhash']:
# just a bunch of places
- return [text_or_binary(r) for r in response_list]
+ return response_list
cast = {
'withdist': float,
@@ -413,7 +402,7 @@ def parse_georadius_generic(response, **options):
# zip all output results with each casting functino to get
# the properly native Python value.
- f = [text_or_binary]
+ f = [lambda x: x]
f += [cast[o] for o in ['withdist', 'withhash', 'withcoord'] if options[o]]
return [
list(map(lambda fv: fv[0](fv[1]), zip(f, r))) for r in response_list
diff --git a/tests/test_commands.py b/tests/test_commands.py
index 4e72466..733ec4f 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -1656,7 +1656,7 @@ class TestRedisCommands(object):
(2.1873744593677, 41.406342043777, b'\x80place2')
r.geoadd('barcelona', *values)
- assert r.georadius('barcelona', 2.191, 41.433, 1000) == ['place1']
+ assert r.georadius('barcelona', 2.191, 41.433, 1000) == [b'place1']
assert r.georadius('barcelona', 2.187, 41.406, 1000) == [b'\x80place2']
@skip_if_server_version_lt('3.2.0')
@@ -1674,7 +1674,7 @@ class TestRedisCommands(object):
r.geoadd('barcelona', *values)
assert r.georadius('barcelona', 2.191, 41.433, 1, unit='km') ==\
- ['place1']
+ [b'place1']
@skip_if_server_version_lt('3.2.0')
def test_georadius_with(self, r):
@@ -1687,17 +1687,17 @@ class TestRedisCommands(object):
# function.
assert r.georadius('barcelona', 2.191, 41.433, 1, unit='km',
withdist=True, withcoord=True, withhash=True) ==\
- [['place1', 0.0881, 3471609698139488,
+ [[b'place1', 0.0881, 3471609698139488,
(2.19093829393386841, 41.43379028184083523)]]
assert r.georadius('barcelona', 2.191, 41.433, 1, unit='km',
withdist=True, withcoord=True) ==\
- [['place1', 0.0881,
+ [[b'place1', 0.0881,
(2.19093829393386841, 41.43379028184083523)]]
assert r.georadius('barcelona', 2.191, 41.433, 1, unit='km',
withhash=True, withcoord=True) ==\
- [['place1', 3471609698139488,
+ [[b'place1', 3471609698139488,
(2.19093829393386841, 41.43379028184083523)]]
# test no values.
@@ -1711,7 +1711,7 @@ class TestRedisCommands(object):
r.geoadd('barcelona', *values)
assert r.georadius('barcelona', 2.191, 41.433, 3000, count=1) ==\
- ['place1']
+ [b'place1']
@skip_if_server_version_lt('3.2.0')
def test_georadius_sort(self, r):
@@ -1720,9 +1720,9 @@ class TestRedisCommands(object):
r.geoadd('barcelona', *values)
assert r.georadius('barcelona', 2.191, 41.433, 3000, sort='ASC') ==\
- ['place1', 'place2']
+ [b'place1', b'place2']
assert r.georadius('barcelona', 2.191, 41.433, 3000, sort='DESC') ==\
- ['place2', 'place1']
+ [b'place2', b'place1']
@skip_if_server_version_lt('3.2.0')
def test_georadius_store(self, r):
@@ -1751,15 +1751,15 @@ class TestRedisCommands(object):
r.geoadd('barcelona', *values)
assert r.georadiusbymember('barcelona', 'place1', 4000) ==\
- [b'\x80place2', 'place1']
- assert r.georadiusbymember('barcelona', 'place1', 10) == ['place1']
+ [b'\x80place2', b'place1']
+ assert r.georadiusbymember('barcelona', 'place1', 10) == [b'place1']
assert r.georadiusbymember('barcelona', 'place1', 4000,
withdist=True, withcoord=True,
withhash=True) ==\
[[b'\x80place2', 3067.4157, 3471609625421029,
(2.187376320362091, 41.40634178640635)],
- ['place1', 0.0, 3471609698139488,
+ [b'place1', 0.0, 3471609698139488,
(2.1909382939338684, 41.433790281840835)]]
@skip_if_server_version_lt('5.0.0')