Skip to content

Commit

Permalink
Codestyle changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vladvildanov committed Sep 13, 2024
1 parent 97abacd commit 20f3851
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 68 deletions.
3 changes: 2 additions & 1 deletion redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@
HIREDIS_PACK_AVAILABLE,
SSL_AVAILABLE,
compare_versions,
ensure_string,
format_error_message,
get_lib_version,
str_if_bytes, ensure_string,
str_if_bytes,
)

if HIREDIS_AVAILABLE:
Expand Down
134 changes: 67 additions & 67 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ def test_get_from_given_cache(self, r, r2):
# get key from redis and save in local cache
assert r.get("foo") in [b"bar", "bar"]
# get key from local cache
assert (
cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value
in [b"bar", "bar"]
)
assert cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value in [
b"bar",
"bar",
]
# change key in redis (cause invalidation)
r2.set("foo", "barbar")
# Retrieves a new value from server and cache it
assert r.get("foo") in [b"barbar", "barbar"]
# Make sure that new value was cached
assert (
cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value
in [b"barbar", "barbar"]
)
assert cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value in [
b"barbar",
"barbar",
]

@pytest.mark.parametrize(
"r",
Expand Down Expand Up @@ -117,19 +117,19 @@ def test_get_from_default_cache(self, r, r2):
# get key from redis and save in local cache
assert r.get("foo") in [b"bar", "bar"]
# get key from local cache
assert (
cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value
in [b"bar", "bar"]
)
assert cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value in [
b"bar",
"bar",
]
# change key in redis (cause invalidation)
r2.set("foo", "barbar")
# Retrieves a new value from server and cache it
assert r.get("foo") in [b"barbar", "barbar"]
# Make sure that new value was cached
assert (
cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value
in [b"barbar", "barbar"]
)
assert cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value in [
b"barbar",
"barbar",
]

@pytest.mark.parametrize(
"r",
Expand Down Expand Up @@ -379,19 +379,19 @@ def test_get_from_cache(self, r):
# get key from redis and save in local cache
assert r.get("foo") in [b"bar", "bar"]
# get key from local cache
assert (
cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value
in [b"bar", "bar"]
)
assert cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value in [
b"bar",
"bar",
]
# change key in redis (cause invalidation)
r.set("foo", "barbar")
# Retrieves a new value from server and cache it
assert r.get("foo") in [b"barbar", "barbar"]
# Make sure that new value was cached
assert (
cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value
in [b"barbar", "barbar"]
)
assert cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value in [
b"barbar",
"barbar",
]
# Make sure that cache is shared between nodes.
assert (
cache == r.nodes_manager.get_node_from_slot(1).redis_connection.get_cache()
Expand Down Expand Up @@ -420,19 +420,19 @@ def test_get_from_custom_cache(self, r, r2):
# get key from redis and save in local cache
assert r.get("foo") in [b"bar", "bar"]
# get key from local cache
assert (
cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value
in [b"bar", "bar"]
)
assert cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value in [
b"bar",
"bar",
]
# change key in redis (cause invalidation)
r2.set("foo", "barbar")
# Retrieves a new value from server and cache it
assert r.get("foo") in [b"barbar", "barbar"]
# Make sure that new value was cached
assert (
cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value
in [b"barbar", "barbar"]
)
assert cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value in [
b"barbar",
"barbar",
]

@pytest.mark.parametrize(
"r",
Expand Down Expand Up @@ -640,7 +640,7 @@ class TestSentinelCache:
"cache": DefaultCache(CacheConfig(max_size=128)),
"force_master_ip": "localhost",
"decode_responses": True,
}
},
],
indirect=True,
)
Expand All @@ -651,19 +651,19 @@ def test_get_from_cache(self, master):
# get key from redis and save in local cache_data
assert master.get("foo") in [b"bar", "bar"]
# get key from local cache_data
assert (
cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value
in [b"bar", "bar"]
)
assert cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value in [
b"bar",
"bar",
]
# change key in redis (cause invalidation)
master.set("foo", "barbar")
# get key from redis
assert master.get("foo") in [b"barbar", "barbar"]
# Make sure that new value was cached
assert (
cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value
in [b"barbar", "barbar"]
)
assert cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value in [
b"barbar",
"barbar",
]

@pytest.mark.parametrize(
"r",
Expand All @@ -687,19 +687,19 @@ def test_get_from_default_cache(self, r, r2):
# get key from redis and save in local cache_data
assert r.get("foo") in [b"bar", "bar"]
# get key from local cache_data
assert (
cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value
in [b"bar", "bar"]
)
assert cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value in [
b"bar",
"bar",
]
# change key in redis (cause invalidation)
r2.set("foo", "barbar")
# Retrieves a new value from server and cache_data it
assert r.get("foo") in [b"barbar", "barbar"]
# Make sure that new value was cached
assert (
cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value
in [b"barbar", "barbar"]
)
assert cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value in [
b"barbar",
"barbar",
]

@pytest.mark.parametrize(
"sentinel_setup",
Expand Down Expand Up @@ -760,7 +760,7 @@ def test_cache_clears_on_disconnect(self, master, cache):

@pytest.mark.skipif(HIREDIS_AVAILABLE, reason="PythonParser only")
@pytest.mark.onlynoncluster
#@skip_if_resp_version(2)
# @skip_if_resp_version(2)
@skip_if_server_version_lt("7.4.0")
class TestSSLCache:
@pytest.mark.parametrize(
Expand All @@ -774,7 +774,7 @@ class TestSSLCache:
"cache": DefaultCache(CacheConfig(max_size=128)),
"ssl": True,
"decode_responses": True,
}
},
],
indirect=True,
)
Expand All @@ -786,10 +786,10 @@ def test_get_from_cache(self, r, r2, cache):
# get key from redis and save in local cache_data
assert r.get("foo") in [b"bar", "bar"]
# get key from local cache_data
assert (
cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value
in [b"bar", "bar"]
)
assert cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value in [
b"bar",
"bar",
]
# change key in redis (cause invalidation)
assert r2.set("foo", "barbar")
# Timeout needed for SSL connection because there's timeout
Expand All @@ -798,10 +798,10 @@ def test_get_from_cache(self, r, r2, cache):
# Retrieves a new value from server and cache_data it
assert r.get("foo") in [b"barbar", "barbar"]
# Make sure that new value was cached
assert (
cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value
in [b"barbar", "barbar"]
)
assert cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value in [
b"barbar",
"barbar",
]

@pytest.mark.parametrize(
"r",
Expand All @@ -827,10 +827,10 @@ def test_get_from_custom_cache(self, r, r2):
# get key from redis and save in local cache_data
assert r.get("foo") in [b"bar", "bar"]
# get key from local cache_data
assert (
cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value
in [b"bar", "bar"]
)
assert cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value in [
b"bar",
"bar",
]
# change key in redis (cause invalidation)
r2.set("foo", "barbar")
# Timeout needed for SSL connection because there's timeout
Expand All @@ -839,10 +839,10 @@ def test_get_from_custom_cache(self, r, r2):
# Retrieves a new value from server and cache_data it
assert r.get("foo") in [b"barbar", "barbar"]
# Make sure that new value was cached
assert (
cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value
in [b"barbar", "barbar"]
)
assert cache.get(CacheKey(command="GET", redis_keys=("foo",))).cache_value in [
b"barbar",
"barbar",
]

@pytest.mark.parametrize(
"r",
Expand Down

0 comments on commit 20f3851

Please sign in to comment.