Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry pick for v5.0.2 #3159

Merged
merged 48 commits into from
Feb 26, 2024
Merged
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
db03189
Bump actions/checkout from 3 to 4 (#2969)
dependabot[bot] Oct 5, 2023
e7cc3bb
Bump rojopolis/spellcheck-github-actions from 0.33.1 to 0.34.0 (#2970)
dependabot[bot] Oct 5, 2023
0172ded
fix type hint (#2963)
d184230 Oct 9, 2023
565171c
Don't perform blocking connect inside the BlockingConnectionQueue Con…
kristjanvalur Oct 11, 2023
697da37
Creating CODEOWNERS for the examples (#2993)
chayim Oct 11, 2023
9970fb4
Close various objects created during asyncio tests (#3005)
kristjanvalur Oct 16, 2023
194d710
Linking to Redis resources (#3006)
chayim Oct 16, 2023
b5e8e55
Add GEOSHAPE field type for index creation of RediSearch (#2957)
sjpotter Oct 16, 2023
30c1686
Better deal with "lost" connections for async Redis (#2999)
kristjanvalur Oct 16, 2023
63239fa
Update client.py sleep_time typing for run_in_thread function (#2977)
danielzhangau Oct 16, 2023
e2127e4
Fix BlockingConnectionPool.from_url parsing of timeout in query args …
r0ro Nov 13, 2023
45e858a
Fix parsing resp3 dicts (#2982)
kristjanvalur Nov 13, 2023
63b562f
Update ocsp.py (#3022)
AniketP04 Nov 29, 2023
a9306e3
Bump rojopolis/spellcheck-github-actions from 0.34.0 to 0.35.0 (#3060)
dependabot[bot] Dec 3, 2023
9402c30
Use `disable_decoding` in async `read_response`. (#3042)
MrDenkoV Dec 3, 2023
ab82697
Add "sum" to DUPLICATE_POLICY documentation of TS.CREATE, TS.ADD and …
Pedram-Parsian Dec 3, 2023
f2fa734
Update advanced_features.rst (#3019)
BackflipPenguin Dec 3, 2023
c1a881e
Fix typos. (#3016)
AYMENJD Dec 3, 2023
7c13191
Fix parsing of `FT.PROFILE` result (#3063)
dvora-h Dec 4, 2023
3f4f5e3
Make the connection callback methods public again, add documentation …
kristjanvalur Dec 11, 2023
f29a7d7
Fix reported version of deprecations in asyncio.client (#2968)
zware Dec 11, 2023
7573448
Allow the parsing of the asking command to forward original options (…
tbbream Dec 11, 2023
b7dbb7e
Fix Specifying Target Nodes broken hyperlink (#3072)
enjoy-binbin Dec 11, 2023
ce6d7b4
Fix return types in json commands (#3071)
parmenashp Dec 11, 2023
6116c38
fix acl_genpass with bits (#3062)
dvora-h Jan 1, 2024
d9d3054
Bump github/codeql-action from 2 to 3 (#3096)
dependabot[bot] Jan 2, 2024
4f8c7d2
Bump actions/upload-artifact from 3 to 4 (#3097)
dependabot[bot] Jan 2, 2024
8f45068
Bump actions/setup-python from 4 to 5 (#3095)
dependabot[bot] Jan 2, 2024
813187e
Always sending codecov (#3101)
chayim Jan 9, 2024
5c94a95
filter commits for main branch (#3036)
chayim Jan 9, 2024
7b1965a
fix(docs): organize cluster mode part of lua scripting (#3073)
mattwang44 Jan 9, 2024
d63ba59
Fix typing for `HashCommand.hdel` (#3029)
dmkulazhenko Jan 9, 2024
33450d9
Adding lock_name to LockError (#3023)
TheBlusky Jan 9, 2024
a32b513
Fix objlen type hint (#2966)
trkwyk Jan 9, 2024
a0b820d
Fix type hint of arbitrary argument lists (#2908)
zxjlm Jan 9, 2024
316667e
Fix: hset unexpectedly mutates the list passed to items (#3103)
dvora-h Jan 11, 2024
4528726
Fix possible pipeline connections leak (#3104)
ING-XIAOJIAN Jan 11, 2024
8e5020e
Add modules support to async RedisCluster (#3115)
dvora-h Jan 21, 2024
3f23fff
Fix grammer in BlockingConnectionPool class documentation (#3120)
ahmedabdou14 Jan 23, 2024
101a28d
release already acquired connections on ClusterPipeline, when get_con…
zakaf Feb 4, 2024
c6dfc91
Bump actions/stale from 3 to 9 (#3132)
dependabot[bot] Feb 4, 2024
a54617c
Bump codecov/codecov-action from 3 to 4 (#3131)
dependabot[bot] Feb 4, 2024
e868a11
Allow to control the minimum SSL version (#3127)
poiuj Feb 5, 2024
87a4d8a
docs: Add timeout parameter for get_message example (#3129)
hongqn Feb 5, 2024
b3f4710
Revert stale isuue version update (#3142)
dvora-h Feb 12, 2024
7fa3bd4
Update connection.py (#3149)
wKollendorf Feb 19, 2024
5dff4ef
Fix retry logic for pubsub and pipeline (#3134)
w-miller Feb 19, 2024
3b18dc0
Update install_requires (#3109)
dvora-h Jan 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make the connection callback methods public again, add documentation (#…
  • Loading branch information
kristjanvalur authored and dvora-h committed Feb 25, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 3f4f5e31472ecc21024a70c7881d8ca3ef390316
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Connection.register_connect_callback() is made public.
* Fix async `read_response` to use `disable_decoding`.
* Add 'aclose()' methods to async classes, deprecate async close().
* Fix #2831, add auto_close_connection_pool=True arg to asyncio.Redis.from_url()
6 changes: 3 additions & 3 deletions redis/asyncio/client.py
Original file line number Diff line number Diff line change
@@ -784,7 +784,7 @@ async def __aexit__(self, exc_type, exc_value, traceback):

def __del__(self):
if self.connection:
self.connection._deregister_connect_callback(self.on_connect)
self.connection.deregister_connect_callback(self.on_connect)

async def aclose(self):
# In case a connection property does not yet exist
@@ -795,7 +795,7 @@ async def aclose(self):
async with self._lock:
if self.connection:
await self.connection.disconnect()
self.connection._deregister_connect_callback(self.on_connect)
self.connection.deregister_connect_callback(self.on_connect)
await self.connection_pool.release(self.connection)
self.connection = None
self.channels = {}
@@ -858,7 +858,7 @@ async def connect(self):
)
# register a callback that re-subscribes to any channels we
# were listening to when we were disconnected
self.connection._register_connect_callback(self.on_connect)
self.connection.register_connect_callback(self.on_connect)
else:
await self.connection.connect()
if self.push_handler_func is not None and not HIREDIS_AVAILABLE:
16 changes: 14 additions & 2 deletions redis/asyncio/connection.py
Original file line number Diff line number Diff line change
@@ -235,12 +235,24 @@ def repr_pieces(self):
def is_connected(self):
return self._reader is not None and self._writer is not None

def _register_connect_callback(self, callback):
def register_connect_callback(self, callback):
"""
Register a callback to be called when the connection is established either
initially or reconnected. This allows listeners to issue commands that
are ephemeral to the connection, for example pub/sub subscription or
key tracking. The callback must be a _method_ and will be kept as
a weak reference.
"""
wm = weakref.WeakMethod(callback)
if wm not in self._connect_callbacks:
self._connect_callbacks.append(wm)

def _deregister_connect_callback(self, callback):
def deregister_connect_callback(self, callback):
"""
De-register a previously registered callback. It will no-longer receive
notifications on connection events. Calling this is not required when the
listener goes away, since the callbacks are kept as weak methods.
"""
try:
self._connect_callbacks.remove(weakref.WeakMethod(callback))
except ValueError:
4 changes: 2 additions & 2 deletions redis/client.py
Original file line number Diff line number Diff line change
@@ -693,7 +693,7 @@ def __del__(self) -> None:
def reset(self) -> None:
if self.connection:
self.connection.disconnect()
self.connection._deregister_connect_callback(self.on_connect)
self.connection.deregister_connect_callback(self.on_connect)
self.connection_pool.release(self.connection)
self.connection = None
self.health_check_response_counter = 0
@@ -751,7 +751,7 @@ def execute_command(self, *args):
)
# register a callback that re-subscribes to any channels we
# were listening to when we were disconnected
self.connection._register_connect_callback(self.on_connect)
self.connection.register_connect_callback(self.on_connect)
if self.push_handler_func is not None and not HIREDIS_AVAILABLE:
self.connection._parser.set_push_handler(self.push_handler_func)
connection = self.connection
2 changes: 1 addition & 1 deletion redis/cluster.py
Original file line number Diff line number Diff line change
@@ -1775,7 +1775,7 @@ def execute_command(self, *args):
)
# register a callback that re-subscribes to any channels we
# were listening to when we were disconnected
self.connection._register_connect_callback(self.on_connect)
self.connection.register_connect_callback(self.on_connect)
if self.push_handler_func is not None and not HIREDIS_AVAILABLE:
self.connection._parser.set_push_handler(self.push_handler_func)
connection = self.connection
16 changes: 14 additions & 2 deletions redis/connection.py
Original file line number Diff line number Diff line change
@@ -237,12 +237,24 @@ def _construct_command_packer(self, packer):
else:
return PythonRespSerializer(self._buffer_cutoff, self.encoder.encode)

def _register_connect_callback(self, callback):
def register_connect_callback(self, callback):
"""
Register a callback to be called when the connection is established either
initially or reconnected. This allows listeners to issue commands that
are ephemeral to the connection, for example pub/sub subscription or
key tracking. The callback must be a _method_ and will be kept as
a weak reference.
"""
wm = weakref.WeakMethod(callback)
if wm not in self._connect_callbacks:
self._connect_callbacks.append(wm)

def _deregister_connect_callback(self, callback):
def deregister_connect_callback(self, callback):
"""
De-register a previously registered callback. It will no-longer receive
notifications on connection events. Calling this is not required when the
listener goes away, since the callbacks are kept as weak methods.
"""
try:
self._connect_callbacks.remove(weakref.WeakMethod(callback))
except ValueError: