Skip to content

Commit 176baa8

Browse files
committed
Fixing linters(almost all errors). Fixing hiredis parser for invalidation messages when using connection pool.
1 parent fa1f654 commit 176baa8

File tree

7 files changed

+32
-7
lines changed

7 files changed

+32
-7
lines changed

redis/_parsers/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
from .base import AsyncPushNotificationsParser, BaseParser, PushNotificationsParser, _AsyncRESPBase
1+
from .base import (
2+
AsyncPushNotificationsParser,
3+
BaseParser,
4+
PushNotificationsParser,
5+
_AsyncRESPBase,
6+
)
27
from .commands import AsyncCommandsParser, CommandsParser
38
from .encoders import Encoder
49
from .hiredis import _AsyncHiredisParser, _HiredisParser

redis/_parsers/hiredis.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
from ..utils import HIREDIS_AVAILABLE
1515
from .base import (
1616
AsyncBaseParser,
17+
AsyncPushNotificationsParser,
1718
BaseParser,
1819
PushNotificationsParser,
19-
AsyncPushNotificationsParser,
2020
)
2121
from .socket import (
2222
NONBLOCKING_EXCEPTION_ERROR_NUMBERS,
@@ -137,6 +137,16 @@ def read_response(self, disable_decoding=False, push_request=False):
137137
if self._next_response is not NOT_ENOUGH_DATA:
138138
response = self._next_response
139139
self._next_response = NOT_ENOUGH_DATA
140+
if self._hiredis_PushNotificationType is not None and isinstance(
141+
response, self._hiredis_PushNotificationType
142+
):
143+
response = self.handle_push_response(response)
144+
if not push_request:
145+
return self.read_response(
146+
disable_decoding=disable_decoding, push_request=push_request
147+
)
148+
else:
149+
return response
140150
return response
141151

142152
if disable_decoding:
@@ -174,7 +184,7 @@ def read_response(self, disable_decoding=False, push_request=False):
174184
return response
175185

176186

177-
class _AsyncHiredisParser(AsyncBaseParser):
187+
class _AsyncHiredisParser(AsyncBaseParser, AsyncPushNotificationsParser):
178188
"""Async implementation of parser class for connections using Hiredis"""
179189

180190
__slots__ = ("_reader",)

tests/test_asyncio/test_search.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import numpy as np
88
import pytest
99
import pytest_asyncio
10+
from redis import ResponseError
1011
import redis.asyncio as redis
1112
import redis.commands.search.aggregation as aggregations
1213
import redis.commands.search.reducers as reducers
@@ -60,6 +61,10 @@ async def waitForIndex(env, idx, timeout=None):
6061
break
6162
except ValueError:
6263
break
64+
except ResponseError:
65+
# index doesn't exist yet
66+
# continue to sleep and try again
67+
pass
6368

6469
await asyncio.sleep(delay)
6570
if timeout is not None:

tests/test_cache.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
EvictionPolicyType,
1414
LRUPolicy,
1515
)
16-
from redis.utils import HIREDIS_AVAILABLE
1716
from tests.conftest import _get_client, skip_if_resp_version, skip_if_server_version_lt
1817

1918

tests/test_connection_pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import redis
1010
from redis.cache import CacheConfig
1111
from redis.connection import CacheProxyConnection, Connection, to_bool
12-
from redis.utils import HIREDIS_AVAILABLE, SSL_AVAILABLE
12+
from redis.utils import SSL_AVAILABLE
1313

1414
from .conftest import (
1515
_get_client,

tests/test_pubsub.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import pytest
1111
import redis
1212
from redis.exceptions import ConnectionError
13-
from redis.utils import HIREDIS_AVAILABLE
1413

1514
from .conftest import (
1615
_get_client,

tests/test_search.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import numpy as np
88
import pytest
9+
from redis import ResponseError
910
import redis
1011
import redis.commands.search
1112
import redis.commands.search.aggregation as aggregations
@@ -47,8 +48,8 @@
4748
def waitForIndex(env, idx, timeout=None):
4849
delay = 0.1
4950
while True:
50-
res = env.execute_command("FT.INFO", idx)
5151
try:
52+
res = env.execute_command("FT.INFO", idx)
5253
if int(res[res.index("indexing") + 1]) == 0:
5354
break
5455
except ValueError:
@@ -59,6 +60,10 @@ def waitForIndex(env, idx, timeout=None):
5960
break
6061
except ValueError:
6162
break
63+
except ResponseError:
64+
# index doesn't exist yet
65+
# continue to sleep and try again
66+
pass
6267

6368
time.sleep(delay)
6469
if timeout is not None:
@@ -1909,6 +1914,8 @@ def test_binary_and_text_fields(client):
19091914
),
19101915
)
19111916

1917+
waitForIndex(client, index_name)
1918+
19121919
query = (
19131920
Query("*")
19141921
.return_field("vector_emb", decode_field=False)

0 commit comments

Comments
 (0)