Skip to content

Commit 3106032

Browse files
committed
Merge branch 'master' of github.com:redis/redis-py into vv-test-8.0
2 parents 23dbb0d + 7a6b412 commit 3106032

File tree

10 files changed

+134
-60
lines changed

10 files changed

+134
-60
lines changed

redis/commands/search/aggregation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from typing import List, Union
22

3+
from redis.commands.search.dialect import DEFAULT_DIALECT
4+
35
FIELDNAME = object()
46

57

@@ -110,7 +112,7 @@ def __init__(self, query: str = "*") -> None:
110112
self._with_schema = False
111113
self._verbatim = False
112114
self._cursor = []
113-
self._dialect = None
115+
self._dialect = DEFAULT_DIALECT
114116
self._add_scores = False
115117
self._scorer = "TFIDF"
116118

redis/commands/search/dialect.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Value for the default dialect to be used as a part of
2+
# Search or Aggregate query.
3+
DEFAULT_DIALECT = 2

redis/commands/search/query.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from typing import List, Optional, Union
22

3+
from redis.commands.search.dialect import DEFAULT_DIALECT
4+
35

46
class Query:
57
"""
@@ -40,7 +42,7 @@ def __init__(self, query_string: str) -> None:
4042
self._highlight_fields: List = []
4143
self._language: Optional[str] = None
4244
self._expander: Optional[str] = None
43-
self._dialect: Optional[int] = None
45+
self._dialect: int = DEFAULT_DIALECT
4446

4547
def query_string(self) -> str:
4648
"""Return the query string of this query only."""

redis/connection.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,9 +904,11 @@ def read_response(
904904
and self._cache.get(self._current_command_cache_key).status
905905
!= CacheEntryStatus.IN_PROGRESS
906906
):
907-
return copy.deepcopy(
907+
res = copy.deepcopy(
908908
self._cache.get(self._current_command_cache_key).cache_value
909909
)
910+
self._current_command_cache_key = None
911+
return res
910912

911913
response = self._conn.read_response(
912914
disable_decoding=disable_decoding,
@@ -932,6 +934,8 @@ def read_response(
932934
cache_entry.cache_value = response
933935
self._cache.set(cache_entry)
934936

937+
self._current_command_cache_key = None
938+
935939
return response
936940

937941
def pack_command(self, *args):
@@ -1374,6 +1378,7 @@ def __init__(
13741378
# will notice the first thread already did the work and simply
13751379
# release the lock.
13761380
self._fork_lock = threading.Lock()
1381+
self._lock = threading.Lock()
13771382
self.reset()
13781383

13791384
def __repr__(self) -> (str, str):
@@ -1391,7 +1396,6 @@ def get_protocol(self):
13911396
return self.connection_kwargs.get("protocol", None)
13921397

13931398
def reset(self) -> None:
1394-
self._lock = threading.Lock()
13951399
self._created_connections = 0
13961400
self._available_connections = []
13971401
self._in_use_connections = set()

redis/typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
Number = Union[int, float]
23-
EncodedT = Union[bytes, memoryview]
23+
EncodedT = Union[bytes, bytearray, memoryview]
2424
DecodedT = Union[str, int, float]
2525
EncodableT = Union[EncodedT, DecodedT]
2626
AbsExpiryT = Union[int, datetime]

tests/test_asyncio/test_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,7 @@ async def test_search_commands_in_pipeline(decoded_r: redis.Redis):
16461646
@pytest.mark.redismod
16471647
async def test_query_timeout(decoded_r: redis.Redis):
16481648
q1 = Query("foo").timeout(5000)
1649-
assert q1.get_args() == ["foo", "TIMEOUT", 5000, "LIMIT", 0, 10]
1649+
assert q1.get_args() == ["foo", "TIMEOUT", 5000, "DIALECT", 2, "LIMIT", 0, 10]
16501650
q2 = Query("foo").timeout("not_a_number")
16511651
with pytest.raises(redis.ResponseError):
16521652
await decoded_r.ft().search(q2)

tests/test_auth/test_token_manager.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,18 @@ def on_next(token):
7373
assert len(tokens) > 0
7474

7575
@pytest.mark.parametrize(
76-
"exp_refresh_ratio,tokens_refreshed",
76+
"exp_refresh_ratio",
7777
[
78-
(0.9, 2),
79-
(0.28, 4),
78+
(0.9),
79+
(0.28),
8080
],
8181
ids=[
82-
"Refresh ratio = 0.9, 2 tokens in 0,1 second",
83-
"Refresh ratio = 0.28, 4 tokens in 0,1 second",
82+
"Refresh ratio = 0.9",
83+
"Refresh ratio = 0.28",
8484
],
8585
)
8686
@pytest.mark.asyncio
87-
async def test_async_success_token_renewal(
88-
self, exp_refresh_ratio, tokens_refreshed
89-
):
87+
async def test_async_success_token_renewal(self, exp_refresh_ratio):
9088
tokens = []
9189
mock_provider = Mock(spec=IdentityProviderInterface)
9290
mock_provider.request_token.side_effect = [
@@ -129,7 +127,7 @@ async def on_next(token):
129127
await mgr.start_async(mock_listener, block_for_initial=True)
130128
await asyncio.sleep(0.1)
131129

132-
assert len(tokens) == tokens_refreshed
130+
assert len(tokens) > 0
133131

134132
@pytest.mark.parametrize(
135133
"block_for_initial,tokens_acquired",
@@ -203,7 +201,7 @@ def on_next(token):
203201
# additional token renewal.
204202
sleep(0.1)
205203

206-
assert len(tokens) == 1
204+
assert len(tokens) > 0
207205

208206
@pytest.mark.asyncio
209207
async def test_async_token_renewal_with_skip_initial(self):
@@ -245,7 +243,7 @@ async def on_next(token):
245243
# due to additional token renewal.
246244
await asyncio.sleep(0.2)
247245

248-
assert len(tokens) == 2
246+
assert len(tokens) > 0
249247

250248
def test_success_token_renewal_with_retry(self):
251249
tokens = []

tests/test_connection.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,9 @@ def test_read_response_returns_cached_reply(self, mock_cache, mock_connection):
501501
)
502502
proxy_connection.send_command(*["GET", "foo"], **{"keys": ["foo"]})
503503
assert proxy_connection.read_response() == b"bar"
504+
assert proxy_connection._current_command_cache_key is None
504505
assert proxy_connection.read_response() == b"bar"
505506

506-
mock_connection.read_response.assert_called_once()
507507
mock_cache.set.assert_has_calls(
508508
[
509509
call(
@@ -530,9 +530,6 @@ def test_read_response_returns_cached_reply(self, mock_cache, mock_connection):
530530
call(CacheKey(command="GET", redis_keys=("foo",))),
531531
call(CacheKey(command="GET", redis_keys=("foo",))),
532532
call(CacheKey(command="GET", redis_keys=("foo",))),
533-
call(CacheKey(command="GET", redis_keys=("foo",))),
534-
call(CacheKey(command="GET", redis_keys=("foo",))),
535-
call(CacheKey(command="GET", redis_keys=("foo",))),
536533
]
537534
)
538535

tests/test_connection_pool.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77

88
import pytest
99
import redis
10-
from redis.connection import to_bool
11-
from redis.utils import SSL_AVAILABLE
12-
13-
from .conftest import _get_client, skip_if_redis_enterprise, skip_if_server_version_lt
10+
from redis.cache import CacheConfig
11+
from redis.connection import CacheProxyConnection, Connection, to_bool
12+
from redis.utils import HIREDIS_AVAILABLE, SSL_AVAILABLE
13+
14+
from .conftest import (
15+
_get_client,
16+
skip_if_redis_enterprise,
17+
skip_if_resp_version,
18+
skip_if_server_version_lt,
19+
)
1420
from .test_pubsub import wait_for_message
1521

1622

@@ -196,6 +202,20 @@ def test_repr_contains_db_info_unix(self):
196202
expected = "path=abc,db=0,client_name=test-client"
197203
assert expected in repr(pool)
198204

205+
@pytest.mark.skipif(HIREDIS_AVAILABLE, reason="PythonParser only")
206+
@pytest.mark.onlynoncluster
207+
@skip_if_resp_version(2)
208+
@skip_if_server_version_lt("7.4.0")
209+
def test_initialise_pool_with_cache(self, master_host):
210+
pool = redis.BlockingConnectionPool(
211+
connection_class=Connection,
212+
host=master_host[0],
213+
port=master_host[1],
214+
protocol=3,
215+
cache_config=CacheConfig(),
216+
)
217+
assert isinstance(pool.get_connection("_"), CacheProxyConnection)
218+
199219

200220
class TestConnectionPoolURLParsing:
201221
def test_hostname(self):

0 commit comments

Comments
 (0)