Skip to content

Commit 8cd9f23

Browse files
committed
fix python3
1 parent 1b22449 commit 8cd9f23

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

redis/client.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -242,18 +242,20 @@ def parse_script(response, **options):
242242

243243

244244
def parse_scan(response, **options):
245-
return response
245+
cursor, r = response
246+
return nativestr(cursor), r
246247

247248

248249
def parse_hscan(response, **options):
249250
cursor, r = response
250-
return cursor, r and pairs_to_dict(r) or {}
251+
return nativestr(cursor), r and pairs_to_dict(r) or {}
251252

252253

253254
def parse_zscan(response, **options):
254255
score_cast_func = options.get('score_cast_func', float)
255-
it = iter(response[1])
256-
return [response[0], list(izip(it, imap(score_cast_func, it)))]
256+
cursor, r = response
257+
it = iter(r)
258+
return nativestr(cursor), list(izip(it, imap(score_cast_func, it)))
257259

258260

259261
class StrictRedis(object):
@@ -1180,7 +1182,8 @@ def sort(self, name, start=None, num=None, by=None, get=None,
11801182
#### SCAN COMMANDS ####
11811183
def scan(self, cursor=0, match=None, count=None):
11821184
"""
1183-
Scan and return (nextcursor, keys)
1185+
Incrementally return lists of key names. Also return a cursor
1186+
indicating the scan position.
11841187
11851188
``match`` allows for filtering the keys by pattern
11861189
@@ -1195,7 +1198,8 @@ def scan(self, cursor=0, match=None, count=None):
11951198

11961199
def scan_iter(self, match=None, count=None):
11971200
"""
1198-
Make a iterator using scan.
1201+
Make an iterator using the SCAN command so that the client doesn't
1202+
need to remember the cursor position.
11991203
12001204
``match`` allows for filtering the keys by pattern
12011205
@@ -1204,12 +1208,13 @@ def scan_iter(self, match=None, count=None):
12041208
cursor = 0
12051209
while cursor != '0':
12061210
cursor, data = self.scan(cursor=cursor, match=match, count=count)
1207-
for _ in data:
1208-
yield _
1211+
for item in data:
1212+
yield item
12091213

12101214
def sscan(self, name, cursor=0, match=None, count=None):
12111215
"""
1212-
Scan and return (nextcursor, members_of_set)
1216+
Incrementally return lists of elements in a set. Also return a cursor
1217+
indicating the scan position.
12131218
12141219
``match`` allows for filtering the keys by pattern
12151220
@@ -1224,7 +1229,8 @@ def sscan(self, name, cursor=0, match=None, count=None):
12241229

12251230
def sscan_iter(self, name, match=None, count=None):
12261231
"""
1227-
Make a iterator using sscan. Iterates over set members.
1232+
Make an iterator using the SSCAN command so that the client doesn't
1233+
need to remember the cursor position.
12281234
12291235
``match`` allows for filtering the keys by pattern
12301236
@@ -1234,12 +1240,13 @@ def sscan_iter(self, name, match=None, count=None):
12341240
while cursor != '0':
12351241
cursor, data = self.sscan(name, cursor=cursor,
12361242
match=match, count=count)
1237-
for _ in data:
1238-
yield _
1243+
for item in data:
1244+
yield item
12391245

12401246
def hscan(self, name, cursor=0, match=None, count=None):
12411247
"""
1242-
Scan and return (nextcursor, dict)
1248+
Incrementally return key/value slices in a hash. Also return a cursor
1249+
indicating the scan position.
12431250
12441251
``match`` allows for filtering the keys by pattern
12451252
@@ -1254,7 +1261,8 @@ def hscan(self, name, cursor=0, match=None, count=None):
12541261

12551262
def hscan_iter(self, name, match=None, count=None):
12561263
"""
1257-
Make a iterator using hscan. Iterates over key/value pairs.
1264+
Make an iterator using the HSCAN command so that the client doesn't
1265+
need to remember the cursor position.
12581266
12591267
``match`` allows for filtering the keys by pattern
12601268
@@ -1264,13 +1272,14 @@ def hscan_iter(self, name, match=None, count=None):
12641272
while cursor != '0':
12651273
cursor, data = self.hscan(name, cursor=cursor,
12661274
match=match, count=count)
1267-
for _ in data.items():
1268-
yield _
1275+
for item in data.items():
1276+
yield item
12691277

12701278
def zscan(self, name, cursor=0, match=None, count=None,
12711279
score_cast_func=float):
12721280
"""
1273-
Scan and return (nextcursor, pairs)
1281+
Incrementally return lists of elements in a sorted set. Also return a
1282+
cursor indicating the scan position.
12741283
12751284
``match`` allows for filtering the keys by pattern
12761285
@@ -1289,7 +1298,8 @@ def zscan(self, name, cursor=0, match=None, count=None,
12891298
def zscan_iter(self, name, match=None, count=None,
12901299
score_cast_func=float):
12911300
"""
1292-
Make a iterator using zscan. Iterates over key/score pairs.
1301+
Make an iterator using the ZSCAN command so that the client doesn't
1302+
need to remember the cursor position.
12931303
12941304
``match`` allows for filtering the keys by pattern
12951305
@@ -1302,8 +1312,8 @@ def zscan_iter(self, name, match=None, count=None,
13021312
cursor, data = self.zscan(name, cursor=cursor, match=match,
13031313
count=count,
13041314
score_cast_func=score_cast_func)
1305-
for _ in data:
1306-
yield _
1315+
for item in data:
1316+
yield item
13071317

13081318
#### SET COMMANDS ####
13091319
def sadd(self, name, *values):

tests/test_commands.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ def test_scan(self, r):
642642
r.set('b', 2)
643643
r.set('c', 3)
644644
cursor, keys = r.scan()
645-
assert cursor == b('0')
645+
assert cursor == '0'
646646
assert set(keys) == set([b('a'), b('b'), b('c')])
647647
_, keys = r.scan(match='a')
648648
assert set(keys) == set([b('a')])
@@ -661,7 +661,7 @@ def test_scan_iter(self, r):
661661
def test_sscan(self, r):
662662
r.sadd('a', 1, 2, 3)
663663
cursor, members = r.sscan('a')
664-
assert cursor == b('0')
664+
assert cursor == '0'
665665
assert set(members) == set([b('1'), b('2'), b('3')])
666666
_, members = r.sscan('a', match=b('1'))
667667
assert set(members) == set([b('1')])
@@ -678,7 +678,7 @@ def test_sscan_iter(self, r):
678678
def test_hscan(self, r):
679679
r.hmset('a', {'a': 1, 'b': 2, 'c': 3})
680680
cursor, dic = r.hscan('a')
681-
assert cursor == b('0')
681+
assert cursor == '0'
682682
assert dic == {b('a'): b('1'), b('b'): b('2'), b('c'): b('3')}
683683
_, dic = r.hscan('a', match='a')
684684
assert dic == {b('a'): b('1')}
@@ -695,7 +695,7 @@ def test_hscan_iter(self, r):
695695
def test_zscan(self, r):
696696
r.zadd('a', 'a', 1, 'b', 2, 'c', 3)
697697
cursor, pairs = r.zscan('a')
698-
assert cursor == b('0')
698+
assert cursor == '0'
699699
assert set(pairs) == set([(b('a'), 1), (b('b'), 2), (b('c'), 3)])
700700
_, pairs = r.zscan('a', match='a')
701701
assert set(pairs) == set([(b('a'), 1)])

0 commit comments

Comments
 (0)