Skip to content

Commit 9cada36

Browse files
committed
Added missing methods
1 parent 96aeb68 commit 9cada36

File tree

13 files changed

+47
-41
lines changed

13 files changed

+47
-41
lines changed

redis/asyncio/cluster.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import random
44
import socket
55
import ssl
6-
import threading
76
import warnings
87
from typing import (
98
Any,
@@ -49,7 +48,6 @@
4948
from redis.credentials import CredentialProvider
5049
from redis.event import (
5150
AfterAsyncClusterInstantiationEvent,
52-
AsyncAfterConnectionReleasedEvent,
5351
EventDispatcher,
5452
)
5553
from redis.exceptions import (

redis/asyncio/connection.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import socket
66
import ssl
77
import sys
8-
import threading
98
import warnings
109
import weakref
1110
from abc import abstractmethod
@@ -44,7 +43,6 @@
4443
from redis.connection import DEFAULT_RESP_VERSION
4544
from redis.credentials import (
4645
CredentialProvider,
47-
StreamingCredentialProvider,
4846
UsernamePasswordCredentialProvider,
4947
)
5048
from redis.exceptions import (

redis/auth/idp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
class IdentityProviderInterface(ABC):
1111
"""
12-
Receive a token from the identity provider. Receiving a token only works when being authenticated.
12+
Receive a token from the identity provider.
13+
Receiving a token only works when being authenticated.
1314
"""
1415

1516
@abstractmethod

redis/auth/token_manager.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import threading
44
from datetime import datetime, timezone
55
from time import sleep
6-
from typing import Any, Awaitable, Callable, Coroutine, Union
6+
from typing import Any, Awaitable, Callable, Union
77

88
from redis.auth.err import RequestTokenErr, TokenRenewalErr
99
from redis.auth.idp import IdentityProviderInterface
@@ -78,9 +78,9 @@ def __init__(
7878

7979
def get_expiration_refresh_ratio(self) -> float:
8080
"""
81-
Represents the ratio of a token's lifetime at which a refresh should be triggered.
82-
For example, a value of 0.75 means the token should be refreshed when 75% of its
83-
lifetime has elapsed (or when 25% of its lifetime remains).
81+
Represents the ratio of a token's lifetime at which a refresh should be triggered. # noqa: E501
82+
For example, a value of 0.75 means the token should be refreshed
83+
when 75% of its lifetime has elapsed (or when 25% of its lifetime remains).
8484
8585
:return: float
8686
"""
@@ -89,9 +89,10 @@ def get_expiration_refresh_ratio(self) -> float:
8989

9090
def get_lower_refresh_bound_millis(self) -> int:
9191
"""
92-
Represents the minimum time in milliseconds before token expiration to trigger a refresh, in milliseconds.
93-
This value sets a fixed lower bound for when a token refresh should occur, regardless
94-
of the token's total lifetime.
92+
Represents the minimum time in milliseconds before token expiration
93+
to trigger a refresh, in milliseconds.
94+
This value sets a fixed lower bound for when a token refresh should occur,
95+
regardless of the token's total lifetime.
9596
If set to 0 there will be no lower bound and the refresh will be triggered
9697
based on the expirationRefreshRatio only.
9798
@@ -101,7 +102,8 @@ def get_lower_refresh_bound_millis(self) -> int:
101102

102103
def get_token_request_execution_timeout_in_ms(self) -> int:
103104
"""
104-
Represents the maximum time in milliseconds to wait for a token request to complete.
105+
Represents the maximum time in milliseconds to wait
106+
for a token request to complete.
105107
106108
:return: int
107109
"""

redis/client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import copy
32
import re
43
import threading

redis/cluster.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
AfterPubSubConnectionInstantiationEvent,
2121
ClientType,
2222
EventDispatcher,
23-
EventDispatcherInterface,
2423
)
2524
from redis.exceptions import (
2625
AskError,

redis/connection.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@
2626
from .backoff import NoBackoff
2727
from .credentials import (
2828
CredentialProvider,
29-
StreamingCredentialProvider,
3029
UsernamePasswordCredentialProvider,
3130
)
3231
from .event import (
3332
AfterConnectionReleasedEvent,
3433
EventDispatcher,
35-
EventDispatcherInterface,
3634
)
3735
from .exceptions import (
3836
AuthenticationError,
@@ -790,6 +788,7 @@ def __init__(
790788
self.retry = self._conn.retry
791789
self.host = self._conn.host
792790
self.port = self._conn.port
791+
self.credential_provider = conn.credential_provider
793792
self._pool_lock = pool_lock
794793
self._cache = cache
795794
self._cache_lock = threading.Lock()
@@ -973,6 +972,17 @@ def _on_invalidation_callback(self, data: List[Union[str, Optional[List[bytes]]]
973972
else:
974973
self._cache.delete_by_redis_keys(data[1])
975974

975+
def get_protocol(self):
976+
return self._conn.get_protocol()
977+
978+
@property
979+
def set_re_auth_token(self, token: TokenInterface):
980+
self._conn.set_re_auth_token(token)
981+
982+
@property
983+
def re_auth(self):
984+
self._conn.re_auth()
985+
976986

977987
class SSLConnection(Connection):
978988
"""Manages SSL connections to and from the Redis server(s).

redis/credentials.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ def get_credentials(self) -> Union[Tuple[str], Tuple[str, str]]:
1515

1616
async def get_credentials_async(self) -> Union[Tuple[str], Tuple[str, str]]:
1717
logger.warning(
18-
"This method is added for backward compatability. Please override it in your implementation."
18+
"This method is added for backward compatability. "
19+
"Please override it in your implementation."
1920
)
2021
return self.get_credentials()
2122

@@ -28,7 +29,8 @@ class StreamingCredentialProvider(CredentialProvider, ABC):
2829
@abstractmethod
2930
def on_next(self, callback: Callable[[Any], None]):
3031
"""
31-
Specifies the callback that should be invoked when the next credentials will be retrieved.
32+
Specifies the callback that should be invoked
33+
when the next credentials will be retrieved.
3234
3335
:param callback: Callback with
3436
:return:

redis/event.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ async def listen(self, event: object):
3030

3131
class EventDispatcherInterface(ABC):
3232
"""
33-
Represents a dispatcher that dispatches events to listeners associated with given event.
33+
Represents a dispatcher that dispatches events to listeners
34+
associated with given event.
3435
"""
3536

3637
@abstractmethod
@@ -132,7 +133,8 @@ class AfterSingleConnectionInstantiationEvent:
132133
"""
133134
Event that will be fired after single connection instances was created.
134135
135-
:param connection_lock: For sync client thread-lock should be provided, for async asyncio.Lock
136+
:param connection_lock: For sync client thread-lock should be provided,
137+
for async asyncio.Lock
136138
"""
137139

138140
def __init__(
@@ -192,7 +194,8 @@ class AfterAsyncClusterInstantiationEvent:
192194
"""
193195
Event that will be fired after async cluster instance was created.
194196
195-
Async cluster doesn't use connection pools, instead ClusterNode object manages connections.
197+
Async cluster doesn't use connection pools,
198+
instead ClusterNode object manages connections.
196199
"""
197200

198201
def __init__(

tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from redis import Sentinel
1818
from redis.auth.idp import IdentityProviderInterface
1919
from redis.auth.token import JWToken
20-
from redis.auth.token_manager import TokenManager
2120
from redis.backoff import NoBackoff
2221
from redis.cache import (
2322
CacheConfig,
@@ -27,7 +26,7 @@
2726
EvictionPolicy,
2827
)
2928
from redis.connection import Connection, ConnectionInterface, SSLConnection, parse_url
30-
from redis.credentials import CredentialProvider, StreamingCredentialProvider
29+
from redis.credentials import CredentialProvider
3130
from redis.exceptions import RedisClusterException
3231
from redis.retry import Retry
3332
from redis_entraid.cred_provider import EntraIdCredentialsProvider, TokenAuthConfig
@@ -329,7 +328,8 @@ def skip_if_nocryptography() -> _TestDecorator:
329328
#
330329
# return pytest.mark.skipif(False, reason="Cryptography dependency found")
331330
# except ImportError:
332-
# TODO: Because JWT library depends on cryptography, now it's always true and tests should be fixed
331+
# TODO: Because JWT library depends on cryptography,
332+
# now it's always true and tests should be fixed
333333
return pytest.mark.skipif(True, reason="No cryptography dependency")
334334

335335

0 commit comments

Comments
 (0)