Skip to content

Commit

Permalink
Merge pull request #1083 from bbayles/georad-decode
Browse files Browse the repository at this point in the history
Don't destroy data in GEORADIUS commands
  • Loading branch information
andymccurdy committed Nov 22, 2018
2 parents dcb135c + 6836755 commit fdd40a5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions redis/client.py
Expand Up @@ -392,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 [nativestr(r) for r in response_list]
return response_list

cast = {
'withdist': float,
Expand All @@ -402,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 = [nativestr]
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
Expand Down
29 changes: 15 additions & 14 deletions tests/test_commands.py
Expand Up @@ -1653,10 +1653,11 @@ def test_old_geopos_no_value(self, r):
@skip_if_server_version_lt('3.2.0')
def test_georadius(self, r):
values = (2.1909389952632, 41.433791470673, 'place1') +\
(2.1873744593677, 41.406342043777, 'place2')
(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')
def test_georadius_no_values(self, r):
Expand All @@ -1673,7 +1674,7 @@ def test_georadius_units(self, r):

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):
Expand All @@ -1686,17 +1687,17 @@ def test_georadius_with(self, r):
# 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.
Expand All @@ -1710,7 +1711,7 @@ def test_georadius_count(self, r):

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):
Expand All @@ -1719,9 +1720,9 @@ def test_georadius_sort(self, r):

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):
Expand All @@ -1746,19 +1747,19 @@ def test_georadius_store_dist(self, r):
@skip_if_server_version_lt('3.2.0')
def test_georadiusmember(self, r):
values = (2.1909389952632, 41.433791470673, 'place1') +\
(2.1873744593677, 41.406342043777, 'place2')
(2.1873744593677, 41.406342043777, b'\x80place2')

r.geoadd('barcelona', *values)
assert r.georadiusbymember('barcelona', 'place1', 4000) ==\
['place2', '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) ==\
[['place2', 3067.4157, 3471609625421029,
[[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')
Expand Down

0 comments on commit fdd40a5

Please sign in to comment.