Skip to content

Commit e4408a9

Browse files
authored
style fix (#13)
1 parent 1856a34 commit e4408a9

File tree

5 files changed

+141
-67
lines changed

5 files changed

+141
-67
lines changed

redis/cluster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from redis.backoff import default_backoff
1010
from redis.client import CaseInsensitiveDict, PubSub, Redis, parse_scan
1111
from redis.commands import READ_COMMANDS, CommandsParser, RedisClusterCommands
12-
from redis.connection import ConnectionPool, DefaultParser, Encoder, parse_url
1312
from redis.commands.helpers import list_or_args
13+
from redis.connection import ConnectionPool, DefaultParser, Encoder, parse_url
1414
from redis.crc import REDIS_CLUSTER_HASH_SLOTS, key_slot
1515
from redis.exceptions import (
1616
AskError,

redis/connection.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,14 @@ def pack_command(self, *args):
883883
# server. If you need to send `COMMAND GETKEYS` to the server, please reach out
884884
# to Doogie and Zach to discuss the use case.
885885
# ref: https://github.com/redis/redis/pull/12380
886-
if len(args) > 1 and args[0].lower() == b'command' and args[1].lower().startswith(b'getkeys'):
887-
raise Exception(f'Redis command "{args[0].decode()} {args[1].decode()}" is not supported')
886+
if (
887+
len(args) > 1
888+
and args[0].lower() == b"command"
889+
and args[1].lower().startswith(b"getkeys")
890+
):
891+
raise Exception(
892+
f'Redis command "command {args[1].decode()}" is not supported'
893+
)
888894

889895
buff = SYM_EMPTY.join((SYM_STAR, str(len(args)).encode(), SYM_CRLF))
890896

tests/test_cluster.py

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,9 @@ def test_cluster_zinter(self, r):
17571757
assert r.zinter(["{foo}a", "{foo}b", "{foo}c"]) == [b"a3", b"a1"]
17581758
# invalid aggregation
17591759
with pytest.raises(DataError):
1760-
r.zinter(["{foo}a", "{foo}b", "{foo}c"], aggregate="foo", withscores=True)
1760+
r.zinter(
1761+
["{foo}a", "{foo}b", "{foo}c"], aggregate="foo", withscores=True
1762+
)
17611763
# aggregate with SUM
17621764
assert r.zinter(["{foo}a", "{foo}b", "{foo}c"], withscores=True) == [
17631765
(b"a3", 8),
@@ -1772,18 +1774,20 @@ def test_cluster_zinter(self, r):
17721774
["{foo}a", "{foo}b", "{foo}c"], aggregate="MIN", withscores=True
17731775
) == [(b"a1", 1), (b"a3", 1)]
17741776
# with weights
1775-
assert r.zinter({"{foo}a": 1, "{foo}b": 2, "{foo}c": 3}, withscores=True) == [
1776-
(b"a3", 20),
1777-
(b"a1", 23),
1778-
]
1777+
assert r.zinter(
1778+
{"{foo}a": 1, "{foo}b": 2, "{foo}c": 3}, withscores=True
1779+
) == [(b"a3", 20), (b"a1", 23)]
17791780

17801781
def test_cluster_zinterstore_sum(self, r):
17811782
with pytest.raises(Exception):
17821783
r.zadd("{foo}a", {"a1": 1, "a2": 1, "a3": 1})
17831784
r.zadd("{foo}b", {"a1": 2, "a2": 2, "a3": 2})
17841785
r.zadd("{foo}c", {"a1": 6, "a3": 5, "a4": 4})
17851786
assert r.zinterstore("{foo}d", ["{foo}a", "{foo}b", "{foo}c"]) == 2
1786-
assert r.zrange("{foo}d", 0, -1, withscores=True) == [(b"a3", 8), (b"a1", 9)]
1787+
assert r.zrange("{foo}d", 0, -1, withscores=True) == [
1788+
(b"a3", 8),
1789+
(b"a1", 9),
1790+
]
17871791

17881792
def test_cluster_zinterstore_max(self, r):
17891793
with pytest.raises(Exception):
@@ -1794,7 +1798,10 @@ def test_cluster_zinterstore_max(self, r):
17941798
r.zinterstore("{foo}d", ["{foo}a", "{foo}b", "{foo}c"], aggregate="MAX")
17951799
== 2
17961800
)
1797-
assert r.zrange("{foo}d", 0, -1, withscores=True) == [(b"a3", 5), (b"a1", 6)]
1801+
assert r.zrange("{foo}d", 0, -1, withscores=True) == [
1802+
(b"a3", 5),
1803+
(b"a1", 6),
1804+
]
17981805

17991806
def test_cluster_zinterstore_min(self, r):
18001807
with pytest.raises(Exception):
@@ -1805,15 +1812,21 @@ def test_cluster_zinterstore_min(self, r):
18051812
r.zinterstore("{foo}d", ["{foo}a", "{foo}b", "{foo}c"], aggregate="MIN")
18061813
== 2
18071814
)
1808-
assert r.zrange("{foo}d", 0, -1, withscores=True) == [(b"a1", 1), (b"a3", 3)]
1815+
assert r.zrange("{foo}d", 0, -1, withscores=True) == [
1816+
(b"a1", 1),
1817+
(b"a3", 3),
1818+
]
18091819

18101820
def test_cluster_zinterstore_with_weight(self, r):
18111821
with pytest.raises(Exception):
18121822
r.zadd("{foo}a", {"a1": 1, "a2": 1, "a3": 1})
18131823
r.zadd("{foo}b", {"a1": 2, "a2": 2, "a3": 2})
18141824
r.zadd("{foo}c", {"a1": 6, "a3": 5, "a4": 4})
18151825
assert r.zinterstore("{foo}d", {"{foo}a": 1, "{foo}b": 2, "{foo}c": 3}) == 2
1816-
assert r.zrange("{foo}d", 0, -1, withscores=True) == [(b"a3", 20), (b"a1", 23)]
1826+
assert r.zrange("{foo}d", 0, -1, withscores=True) == [
1827+
(b"a3", 20),
1828+
(b"a1", 23),
1829+
]
18171830

18181831
@skip_if_server_version_lt("4.9.0")
18191832
def test_cluster_bzpopmax(self, r):
@@ -1868,7 +1881,12 @@ def test_cluster_zunion(self, r):
18681881
r.zadd("{foo}b", {"a1": 2, "a2": 2, "a3": 2})
18691882
r.zadd("{foo}c", {"a1": 6, "a3": 5, "a4": 4})
18701883
# sum
1871-
assert r.zunion(["{foo}a", "{foo}b", "{foo}c"]) == [b"a2", b"a4", b"a3", b"a1"]
1884+
assert r.zunion(["{foo}a", "{foo}b", "{foo}c"]) == [
1885+
b"a2",
1886+
b"a4",
1887+
b"a3",
1888+
b"a1",
1889+
]
18721890
assert r.zunion(["{foo}a", "{foo}b", "{foo}c"], withscores=True) == [
18731891
(b"a2", 3),
18741892
(b"a4", 4),
@@ -1884,12 +1902,9 @@ def test_cluster_zunion(self, r):
18841902
["{foo}a", "{foo}b", "{foo}c"], aggregate="MIN", withscores=True
18851903
) == [(b"a1", 1), (b"a2", 1), (b"a3", 1), (b"a4", 4)]
18861904
# with weight
1887-
assert r.zunion({"{foo}a": 1, "{foo}b": 2, "{foo}c": 3}, withscores=True) == [
1888-
(b"a2", 5),
1889-
(b"a4", 12),
1890-
(b"a3", 20),
1891-
(b"a1", 23),
1892-
]
1905+
assert r.zunion(
1906+
{"{foo}a": 1, "{foo}b": 2, "{foo}c": 3}, withscores=True
1907+
) == [(b"a2", 5), (b"a4", 12), (b"a3", 20), (b"a1", 23)]
18931908

18941909
def test_cluster_zunionstore_sum(self, r):
18951910
assert r.zunionstore("{foo}d", ["{foo}" + str(i) for i in range(0, 256)]) == 0
@@ -2061,7 +2076,11 @@ def test_cluster_georadius_store_dist(self, r):
20612076

20622077
r.geoadd("{foo}barcelona", values)
20632078
r.georadius(
2064-
"{foo}barcelona", 2.191, 41.433, 1000, store_dist="{foo}places_barcelona"
2079+
"{foo}barcelona",
2080+
2.191,
2081+
41.433,
2082+
1000,
2083+
store_dist="{foo}places_barcelona",
20652084
)
20662085
# instead of save the geo score, the distance is saved.
20672086
assert r.zscore("{foo}places_barcelona", "place1") == 88.05060698409301

tests/test_command_parser.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,17 @@ def test_get_moveable_keys(self, r):
3636
]
3737
args2 = ["XREAD", "COUNT", 2, b"STREAMS", "mystream", "writers", 0, 0]
3838
args3 = ["ZUNIONSTORE", "out", 2, "zset1", "zset2", "WEIGHTS", 2, 3]
39-
args4 = ["GEORADIUS", "Sicily", 15, 37, 200, "km", "WITHCOORD", b"STORE", "out"]
39+
args4 = [
40+
"GEORADIUS",
41+
"Sicily",
42+
15,
43+
37,
44+
200,
45+
"km",
46+
"WITHCOORD",
47+
b"STORE",
48+
"out",
49+
]
4050
args5 = ["MEMORY USAGE", "foo"]
4151
args6 = [
4252
"MIGRATE",
@@ -53,11 +63,22 @@ def test_get_moveable_keys(self, r):
5363
args7 = ["MIGRATE", "192.168.1.34", 6379, "key1", 0, 5000]
5464

5565
assert sorted(commands_parser.get_keys(r, *args1)) == ["key1", "key2"]
56-
assert sorted(commands_parser.get_keys(r, *args2)) == ["mystream", "writers"]
57-
assert sorted(commands_parser.get_keys(r, *args3)) == ["out", "zset1", "zset2"]
66+
assert sorted(commands_parser.get_keys(r, *args2)) == [
67+
"mystream",
68+
"writers",
69+
]
70+
assert sorted(commands_parser.get_keys(r, *args3)) == [
71+
"out",
72+
"zset1",
73+
"zset2",
74+
]
5875
assert sorted(commands_parser.get_keys(r, *args4)) == ["Sicily", "out"]
5976
assert sorted(commands_parser.get_keys(r, *args5)) == ["foo"]
60-
assert sorted(commands_parser.get_keys(r, *args6)) == ["key1", "key2", "key3"]
77+
assert sorted(commands_parser.get_keys(r, *args6)) == [
78+
"key1",
79+
"key2",
80+
"key3",
81+
]
6182
assert sorted(commands_parser.get_keys(r, *args7)) == ["key1"]
6283

6384
# A bug in redis<7.0 causes this to fail: https://github.com/redis/redis/issues/9493

tests/test_commands.py

Lines changed: 71 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3026,38 +3026,37 @@ def test_sort_store(self, r):
30263026

30273027
@pytest.mark.onlynoncluster
30283028
def test_sort_all_options(self, r):
3029-
with pytest.raises(Exception):
3030-
r["user:1:username"] = "zeus"
3031-
r["user:2:username"] = "titan"
3032-
r["user:3:username"] = "hermes"
3033-
r["user:4:username"] = "hercules"
3034-
r["user:5:username"] = "apollo"
3035-
r["user:6:username"] = "athena"
3036-
r["user:7:username"] = "hades"
3037-
r["user:8:username"] = "dionysus"
3038-
3039-
r["user:1:favorite_drink"] = "yuengling"
3040-
r["user:2:favorite_drink"] = "rum"
3041-
r["user:3:favorite_drink"] = "vodka"
3042-
r["user:4:favorite_drink"] = "milk"
3043-
r["user:5:favorite_drink"] = "pinot noir"
3044-
r["user:6:favorite_drink"] = "water"
3045-
r["user:7:favorite_drink"] = "gin"
3046-
r["user:8:favorite_drink"] = "apple juice"
3047-
3048-
r.rpush("gods", "5", "8", "3", "1", "2", "7", "6", "4")
3049-
num = r.sort(
3050-
"gods",
3051-
start=2,
3052-
num=4,
3053-
by="user:*:username",
3054-
get="user:*:favorite_drink",
3055-
desc=True,
3056-
alpha=True,
3057-
store="sorted",
3058-
)
3059-
assert num == 4
3060-
assert r.lrange("sorted", 0, 10) == [b"vodka", b"milk", b"gin", b"apple juice"]
3029+
r["user:1:username"] = "zeus"
3030+
r["user:2:username"] = "titan"
3031+
r["user:3:username"] = "hermes"
3032+
r["user:4:username"] = "hercules"
3033+
r["user:5:username"] = "apollo"
3034+
r["user:6:username"] = "athena"
3035+
r["user:7:username"] = "hades"
3036+
r["user:8:username"] = "dionysus"
3037+
3038+
r["user:1:favorite_drink"] = "yuengling"
3039+
r["user:2:favorite_drink"] = "rum"
3040+
r["user:3:favorite_drink"] = "vodka"
3041+
r["user:4:favorite_drink"] = "milk"
3042+
r["user:5:favorite_drink"] = "pinot noir"
3043+
r["user:6:favorite_drink"] = "water"
3044+
r["user:7:favorite_drink"] = "gin"
3045+
r["user:8:favorite_drink"] = "apple juice"
3046+
3047+
r.rpush("gods", "5", "8", "3", "1", "2", "7", "6", "4")
3048+
num = r.sort(
3049+
"gods",
3050+
start=2,
3051+
num=4,
3052+
by="user:*:username",
3053+
get="user:*:favorite_drink",
3054+
desc=True,
3055+
alpha=True,
3056+
store="sorted",
3057+
)
3058+
assert num == 4
3059+
assert r.lrange("sorted", 0, 10) == [b"vodka", b"milk", b"gin", b"apple juice"]
30613060

30623061
@skip_if_server_version_lt("7.0.0")
30633062
@pytest.mark.onlynoncluster
@@ -3604,7 +3603,11 @@ def test_georadius_with(self, r):
36043603
assert r.georadius(
36053604
"barcelona", 2.191, 41.433, 1, unit="km", withhash=True, withcoord=True
36063605
) == [
3607-
[b"place1", 3471609698139488, (2.19093829393386841, 41.43379028184083523)]
3606+
[
3607+
b"place1",
3608+
3471609698139488,
3609+
(2.19093829393386841, 41.43379028184083523),
3610+
]
36083611
]
36093612

36103613
# test no values.
@@ -3704,7 +3707,12 @@ def test_georadiusmember(self, r):
37043707
assert r.georadiusbymember("barcelona", "place1", 10) == [b"place1"]
37053708

37063709
assert r.georadiusbymember(
3707-
"barcelona", "place1", 4000, withdist=True, withcoord=True, withhash=True
3710+
"barcelona",
3711+
"place1",
3712+
4000,
3713+
withdist=True,
3714+
withcoord=True,
3715+
withhash=True,
37083716
) == [
37093717
[
37103718
b"\x80place2",
@@ -3729,9 +3737,9 @@ def test_georadiusmember_count(self, r):
37293737
b"\x80place2",
37303738
)
37313739
r.geoadd("barcelona", values)
3732-
assert r.georadiusbymember("barcelona", "place1", 4000, count=1, any=True) == [
3733-
b"\x80place2"
3734-
]
3740+
assert r.georadiusbymember(
3741+
"barcelona", "place1", 4000, count=1, any=True
3742+
) == [b"\x80place2"]
37353743

37363744
@skip_if_server_version_lt("5.0.0")
37373745
def test_xack(self, r):
@@ -3863,7 +3871,12 @@ def test_xautoclaim(self, r):
38633871
stream, group, consumer1, min_idle_time=0, start_id=0, justid=True
38643872
) == [message_id1, message_id2]
38653873
assert r.xautoclaim(
3866-
stream, group, consumer1, min_idle_time=0, start_id=message_id2, justid=True
3874+
stream,
3875+
group,
3876+
consumer1,
3877+
min_idle_time=0,
3878+
start_id=message_id2,
3879+
justid=True,
38673880
) == [message_id2]
38683881

38693882
@skip_if_server_version_lt("6.2.0")
@@ -4234,7 +4247,9 @@ def test_xpending_range_idle(self, r):
42344247

42354248
response = r.xpending_range(stream, group, min="-", max="+", count=5)
42364249
assert len(response) == 2
4237-
response = r.xpending_range(stream, group, min="-", max="+", count=5, idle=1000)
4250+
response = r.xpending_range(
4251+
stream, group, min="-", max="+", count=5, idle=1000
4252+
)
42384253
assert len(response) == 0
42394254

42404255
def test_xpending_range_negative(self, r):
@@ -4292,7 +4307,10 @@ def test_xread(self, r):
42924307
expected = [
42934308
[
42944309
stream.encode(),
4295-
[get_stream_message(r, stream, m1), get_stream_message(r, stream, m2)],
4310+
[
4311+
get_stream_message(r, stream, m1),
4312+
get_stream_message(r, stream, m2),
4313+
],
42964314
]
42974315
]
42984316
# xread starting at 0 returns both messages
@@ -4322,7 +4340,10 @@ def test_xreadgroup(self, r):
43224340
expected = [
43234341
[
43244342
stream.encode(),
4325-
[get_stream_message(r, stream, m1), get_stream_message(r, stream, m2)],
4343+
[
4344+
get_stream_message(r, stream, m1),
4345+
get_stream_message(r, stream, m2),
4346+
],
43264347
]
43274348
]
43284349
# xread starting at 0 returns both messages
@@ -4333,7 +4354,10 @@ def test_xreadgroup(self, r):
43334354

43344355
expected = [[stream.encode(), [get_stream_message(r, stream, m1)]]]
43354356
# xread with count=1 returns only the first message
4336-
assert r.xreadgroup(group, consumer, streams={stream: ">"}, count=1) == expected
4357+
assert (
4358+
r.xreadgroup(group, consumer, streams={stream: ">"}, count=1)
4359+
== expected
4360+
)
43374361

43384362
r.xgroup_destroy(stream, group)
43394363

@@ -4349,7 +4373,11 @@ def test_xreadgroup(self, r):
43494373
r.xgroup_destroy(stream, group)
43504374
r.xgroup_create(stream, group, "0")
43514375
assert (
4352-
len(r.xreadgroup(group, consumer, streams={stream: ">"}, noack=True)[0][1])
4376+
len(
4377+
r.xreadgroup(group, consumer, streams={stream: ">"}, noack=True)[0][
4378+
1
4379+
]
4380+
)
43534381
== 2
43544382
)
43554383
# now there should be nothing pending

0 commit comments

Comments
 (0)