Skip to content

Commit f2f8c34

Browse files
dvora-hbellini666woutdenolfchayimshacharPash
authored
Merge master to 5.0 (#2827)
* fix: do not use asyncio's timeout lib before 3.11.2 (#2659) There's an issue in asyncio's timeout lib before 3.11.3 that causes async calls to raise `CancelledError`. This is a cpython issue that was fixed in this commit [1] and cherry-picked to previous versions, meaning 3.11.3 will work correctly. Check [2] for more info. [1] python/cpython@04adf2d [2] #2633 * UnixDomainSocketConnection missing constructor argument (#2630) * removing useless files (#2642) * Fix issue 2660: PytestUnraisableExceptionWarning from asycio client (#2669) * Fixing cancelled async futures (#2666) Co-authored-by: James R T <[email protected]> Co-authored-by: dvora-h <[email protected]> * Fix async (#2673) * Version 4.5.4 (#2674) * Really do not use asyncio's timeout lib before 3.11.2 (#2699) 4802530 made async-timeout required only on Python 3.11.2 and earlier. However, according to PEP-508, python_version marker is compared to first two numbers of Python version tuple - so it will evaluate to True also on 3.11.3, and install a package as a dependency. * asyncio: Fix memory leak caused by hiredis (#2693) (#2694) * Update example of Redisearch creating index (#2703) When creating index, fields should be passed inside an iterable (e.g. list or tuple) * Improving Vector Similarity Search Example (#2661) * update vss docs * add embeddings creation and storage examples * update based on feedback * fix version and link * include more realistic search examples and clean up indices * completely remove initial cap reference --------- Co-authored-by: Chayim <[email protected]> * Fix incorrect usage of once flag in async Sentinel (#2718) In the execute_command of the async Sentinel, the once flag was being used incorrectly, with its meaning inverted. To fix we just needed to invert the if and else bodies. This isn't being caught by the tests currently because the tests of commands that use this flag do not check their results/effects (for example the "test_ckquorum" test). * Fix topk list example. (#2724) * Improve error output for master discovery (#2720) Make MasterNotFoundError exception more precise in the case of ConnectionError and TimeoutError to help the user to identify configuration errors Co-authored-by: Marc Schöchlin <[email protected]> * return response in case of KeyError (#2628) * return response in case of KeyError * fix code linters error * fix linters 2 * fix linters 3 * Add WITHSCORES to ZREVRANK Command (#2725) * add withscores to zrevrank * change 0 -> 2 * fix errors * split test * Fix `ClusterCommandProtocol` not itself being marked as a protocol (#2729) * Fix `ClusterCommandProtocol` not itself being marked as a protocol * Update CHANGES * Fix potential race condition during disconnection (#2719) When the disconnect() function is called twice in parallel it is possible that one thread deletes the self._sock reference, while the other thread will attempt to call .close() on it, leading to an AttributeError. This situation can routinely be encountered by closing the connection in a PubSubWorkerThread error handler in a blocking thread (ie. with sleep_time==None), and then calling .close() on the PubSub object. The main thread will then run into the disconnect() function, and the listener thread is woken up by the closure and will race into the disconnect() function, too. This can be fixed easily by copying the object reference before doing the None-check, similar to what we do in the redis.client.close() function. * add "address_remap" feature to RedisCluster (#2726) * add cluster "host_port_remap" feature for asyncio.RedisCluster * Add a unittest for asyncio.RedisCluster * Add host_port_remap to _sync_ RedisCluster * add synchronous tests * rename arg to `address_remap` and take and return an address tuple. * Add class documentation * Add CHANGES * nermina changes from NRedisStack (#2736) * Updated AWS Elasticache IAM Connection Example (#2702) Co-authored-by: Nick Gerow <[email protected]> * pinning urllib3 to fix CI (#2748) * Add RedisCluster.remap_host_port, Update tests for CWE 404 (#2706) * Use provided redis address. Bind to IPv4 * Add missing "await" and perform the correct test for pipe eimpty * Wait for a send event, rather than rely on sleep time. Excpect cancel errors. * set delay to 0 except for operation we want to cancel This speeds up the unit tests considerably by eliminating unnecessary delay. * Release resources in test * Fix cluster test to use address_remap and multiple proxies. * Use context manager to manage DelayProxy * Mark failing pipeline tests * lint * Use a common "master_host" test fixture * Update redismodules.rst (#2747) Co-authored-by: dvora-h <[email protected]> * Add support for cluster myshardid (#2704) * feat: adding support for cluster myshardid * lint fix * fix: comment fix and async test * fix: adding version check * fix lint: * linters --------- Co-authored-by: Anuragkillswitch <[email protected]> Co-authored-by: dvora-h <[email protected]> Co-authored-by: dvora-h <[email protected]> * clean warnings (#2731) * fix parse_slowlog_get (#2732) * Optionally disable disconnects in read_response (#2695) * Add regression tests and fixes for issue #1128 * Fix tests for resumable read_response to use "disconnect_on_error" * undo prevision fix attempts in async client and cluster * re-enable cluster test * Suggestions from code review * Add CHANGES * Add client no-touch (#2745) * Add client no-touch * Update redis/commands/core.py Co-authored-by: dvora-h <[email protected]> * Update test_commands.py Improve test_client_no_touch * Update test_commands.py Add async version test case * Chore remove whitespace Oops --------- Co-authored-by: dvora-h <[email protected]> * fix create single_connection_client from url (#2752) * Fix `xadd` allow non negative maxlen (#2739) * Fix xadd allow non negative maxlen * Update change log --------- Co-authored-by: dvora-h <[email protected]> * Version 4.5.5 (#2753) * Kristjan/issue #2754: Add missing argument to SentinelManagedConnection.read_response() (#2756) * Increase timeout for a test which would hang completely if failing. Timeouts in virtualized CI backends can occasionally fail if too short. * add "disconnect_on_error" argument to SentinelManagedConnection * update Changes * lint * support JSON.MERGE Command (#2761) * support JSON.MERGE Command * linters * try with abc instead person * change @skip_ifmodversion_lt to latest ReJSON 2.4.7 * change version * fix test * linters * add async test * Issue #2749: Remove unnecessary __del__ handlers (#2755) * Remove unnecessary __del__ handlers There normally should be no logic attached to del. Cleanly disconnecting network resources is not needed at that time. * add CHANGES * Add WITHSCORE to ZRANK (#2758) * add withscore to zrank with tests * fix test * Fix JSON.MERGE Summary (#2786) * Fix JSON.MERGE Summary * linters * Fixed key error in parse_xinfo_stream (#2788) * insert newline to prevent sphinx from assuming code block (#2796) * Introduce OutOfMemoryError exception for Redis write command rejections due to OOM errors (#2778) * expose OutOfMemoryError as explicit exception type - handle "OOM" error code string by raising explicit exception type instance - enables callers to avoid string matching after catching ResponseError * add OutOfMemoryError exception class docstring * Provide more info in the exception docstring * Fix formatting * Again * linters --------- Co-authored-by: Chayim <[email protected]> Co-authored-by: Igor Malinovskiy <[email protected]> Co-authored-by: dvora-h <[email protected]> * Add unit tests for the `connect` method of all Redis connection classes (#2631) * tests: move certificate discovery to a separate module * tests: add 'connect' tests for all Redis connection classes --------- Co-authored-by: dvora-h <[email protected]> * Fix dead weakref in sentinel connection causing ReferenceError (#2767) (#2771) * Fix dead weakref in sentinel conn (#2767) * Update CHANGES --------- Co-authored-by: Igor Malinovskiy <[email protected]> Co-authored-by: dvora-h <[email protected]> * chore(documentation): fix redirects and some small cleanups (#2801) * Add waitaof (#2760) * Add waitaof * Update test_commands.py add test_waitaof * Update test_commands.py Add test_waitaof * Fix doc string --------- Co-authored-by: Chayim <[email protected]> Co-authored-by: Igor Malinovskiy <[email protected]> * Extract abstract async connection class (#2734) * make 'socket_timeout' and 'socket_connect_timeout' equivalent for TCP and UDS connections * abstract asynio connection in analogy with the synchronous connection --------- Co-authored-by: dvora-h <[email protected]> * Fix type hint for retry_on_error in async cluster (#2804) * fix(asyncio.cluster): fixup retry_on_error type hint This parameter accepts a list of _classes of Exceptions_, not a list of instantiated Exceptions. Fixup the type hint accordingly. * chore: update changelog --------- Co-authored-by: dvora-h <[email protected]> * Fix CI (#2809) * Support JSON.MSET Command (#2766) * support JSON.MERGE Command * linters * try with abc instead person * change @skip_ifmodversion_lt to latest ReJSON 2.4.7 * change version * fix test * linters * add async test * Support JSON.MSET command * trying to run CI * linters * add async test * reminder do delete the integration changes * delete the line from integration * fix the interface * change docstring --------- Co-authored-by: Chayim <[email protected]> Co-authored-by: dvora-h <[email protected]> * Version 4.6.0 (#2810) * master changes * linters * fix test_cwe_404 cluster test --------- Co-authored-by: Thiago Bellini Ribeiro <[email protected]> Co-authored-by: woutdenolf <[email protected]> Co-authored-by: Chayim <[email protected]> Co-authored-by: shacharPash <[email protected]> Co-authored-by: James R T <[email protected]> Co-authored-by: Mirek Długosz <[email protected]> Co-authored-by: Oran Avraham <[email protected]> Co-authored-by: mzdehbashi-github <[email protected]> Co-authored-by: Tyler Hutcherson <[email protected]> Co-authored-by: Felipe Machado <[email protected]> Co-authored-by: AYMEN Mohammed <[email protected]> Co-authored-by: Marc Schöchlin <[email protected]> Co-authored-by: Marc Schöchlin <[email protected]> Co-authored-by: Avasam <[email protected]> Co-authored-by: Markus Gerstel <[email protected]> Co-authored-by: Kristján Valur Jónsson <[email protected]> Co-authored-by: Nick Gerow <[email protected]> Co-authored-by: Nick Gerow <[email protected]> Co-authored-by: Cristian Matache <[email protected]> Co-authored-by: Anurag Bandyopadhyay <[email protected]> Co-authored-by: Anuragkillswitch <[email protected]> Co-authored-by: Seongchuel Ahn <[email protected]> Co-authored-by: Alibi <[email protected]> Co-authored-by: Smit Parmar <[email protected]> Co-authored-by: Brad MacPhee <[email protected]> Co-authored-by: Igor Malinovskiy <[email protected]> Co-authored-by: Shahar Lev <[email protected]> Co-authored-by: Vladimir Mihailenco <[email protected]> Co-authored-by: Kevin James <[email protected]>
1 parent d453665 commit f2f8c34

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2341
-1156
lines changed

CHANGES

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
* Fix incorrect redis.asyncio.Cluster type hint for `retry_on_error`
2+
* Fix dead weakref in sentinel connection causing ReferenceError (#2767)
3+
* Fix #2768, Fix KeyError: 'first-entry' in parse_xinfo_stream.
4+
* Fix #2749, remove unnecessary __del__ logic to close connections.
5+
* Fix #2754, adding a missing argument to SentinelManagedConnection
6+
* Fix `xadd` command to accept non-negative `maxlen` including 0
7+
* Revert #2104, #2673, add `disconnect_on_error` option to `read_response()` (issues #2506, #2624)
8+
* Add `address_remap` parameter to `RedisCluster`
9+
* Fix incorrect usage of once flag in async Sentinel
10+
* asyncio: Fix memory leak caused by hiredis (#2693)
111
* Allow data to drain from async PythonParser when reading during a disconnect()
212
* Use asyncio.timeout() instead of async_timeout.timeout() for python >= 3.11 (#2602)
313
* Add test and fix async HiredisParser when reading during a disconnect() (#2349)
@@ -40,6 +50,8 @@
4050
* Fix Sentinel.execute_command doesn't execute across the entire sentinel cluster bug (#2458)
4151
* Added a replacement for the default cluster node in the event of failure (#2463)
4252
* Fix for Unhandled exception related to self.host with unix socket (#2496)
53+
* Improve error output for master discovery
54+
* Make `ClusterCommandsProtocol` an actual Protocol
4355

4456
* 4.1.3 (Feb 8, 2022)
4557
* Fix flushdb and flushall (#1926)

CONTRIBUTING.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
## Introduction
44

5-
First off, thank you for considering contributing to redis-py. We value
6-
community contributions!
5+
We appreciate your interest in considering contributing to redis-py.
6+
Community contributions mean a lot to us.
77

8-
## Contributions We Need
8+
## Contributions we need
99

10-
You may already know what you want to contribute \-- a fix for a bug you
10+
You may already know how you'd like to contribute, whether it's a fix for a bug you
1111
encountered, or a new feature your team wants to use.
1212

13-
If you don't know what to contribute, keep an open mind! Improving
13+
If you don't know where to start, consider improving
1414
documentation, bug triaging, and writing tutorials are all examples of
1515
helpful contributions that mean less work for you.
1616

@@ -166,19 +166,19 @@ When filing an issue, make sure to answer these five questions:
166166
4. What did you expect to see?
167167
5. What did you see instead?
168168

169-
## How to Suggest a Feature or Enhancement
169+
## Suggest a feature or enhancement
170170

171171
If you'd like to contribute a new feature, make sure you check our
172172
issue list to see if someone has already proposed it. Work may already
173-
be under way on the feature you want -- or we may have rejected a
173+
be underway on the feature you want or we may have rejected a
174174
feature like it already.
175175

176176
If you don't see anything, open a new issue that describes the feature
177177
you would like and how it should work.
178178

179-
## Code Review Process
179+
## Code review process
180180

181-
The core team looks at Pull Requests on a regular basis. We will give
182-
feedback as as soon as possible. After feedback, we expect a response
181+
The core team regularly looks at pull requests. We will provide
182+
feedback as as soon as possible. After receiving our feedback, please respond
183183
within two weeks. After that time, we may close your PR if it isn't
184184
showing any activity.

docs/examples/connection_examples.ipynb

+44-12
Original file line numberDiff line numberDiff line change
@@ -267,28 +267,60 @@
267267
}
268268
],
269269
"source": [
270+
"from typing import Tuple, Union\n",
271+
"from urllib.parse import ParseResult, urlencode, urlunparse\n",
272+
"\n",
273+
"import botocore.session\n",
270274
"import redis\n",
271-
"import boto3\n",
272-
"import cachetools.func\n",
275+
"from botocore.model import ServiceId\n",
276+
"from botocore.signers import RequestSigner\n",
277+
"from cachetools import TTLCache, cached\n",
273278
"\n",
274279
"class ElastiCacheIAMProvider(redis.CredentialProvider):\n",
275-
" def __init__(self, user, endpoint, port=6379, region=\"us-east-1\"):\n",
276-
" self.ec_client = boto3.client('elasticache')\n",
280+
" def __init__(self, user, cluster_name, region=\"us-east-1\"):\n",
277281
" self.user = user\n",
278-
" self.endpoint = endpoint\n",
279-
" self.port = port\n",
282+
" self.cluster_name = cluster_name\n",
280283
" self.region = region\n",
281284
"\n",
285+
" session = botocore.session.get_session()\n",
286+
" self.request_signer = RequestSigner(\n",
287+
" ServiceId(\"elasticache\"),\n",
288+
" self.region,\n",
289+
" \"elasticache\",\n",
290+
" \"v4\",\n",
291+
" session.get_credentials(),\n",
292+
" session.get_component(\"event_emitter\"),\n",
293+
" )\n",
294+
"\n",
295+
" # Generated IAM tokens are valid for 15 minutes\n",
296+
" @cached(cache=TTLCache(maxsize=128, ttl=900))\n",
282297
" def get_credentials(self) -> Union[Tuple[str], Tuple[str, str]]:\n",
283-
" @cachetools.func.ttl_cache(maxsize=128, ttl=15 * 60) # 15m\n",
284-
" def get_iam_auth_token(user, endpoint, port, region):\n",
285-
" return self.ec_client.generate_iam_auth_token(user, endpoint, port, region)\n",
286-
" iam_auth_token = get_iam_auth_token(self.endpoint, self.port, self.user, self.region)\n",
287-
" return iam_auth_token\n",
298+
" query_params = {\"Action\": \"connect\", \"User\": self.user}\n",
299+
" url = urlunparse(\n",
300+
" ParseResult(\n",
301+
" scheme=\"https\",\n",
302+
" netloc=self.cluster_name,\n",
303+
" path=\"/\",\n",
304+
" query=urlencode(query_params),\n",
305+
" params=\"\",\n",
306+
" fragment=\"\",\n",
307+
" )\n",
308+
" )\n",
309+
" signed_url = self.request_signer.generate_presigned_url(\n",
310+
" {\"method\": \"GET\", \"url\": url, \"body\": {}, \"headers\": {}, \"context\": {}},\n",
311+
" operation_name=\"connect\",\n",
312+
" expires_in=900,\n",
313+
" region_name=self.region,\n",
314+
" )\n",
315+
" # RequestSigner only seems to work if the URL has a protocol, but\n",
316+
" # Elasticache only accepts the URL without a protocol\n",
317+
" # So strip it off the signed URL before returning\n",
318+
" return (self.user, signed_url.removeprefix(\"https://\"))\n",
288319
"\n",
289320
"username = \"barshaul\"\n",
321+
"cluster_name = \"test-001\"\n",
290322
"endpoint = \"test-001.use1.cache.amazonaws.com\"\n",
291-
"creds_provider = ElastiCacheIAMProvider(user=username, endpoint=endpoint)\n",
323+
"creds_provider = ElastiCacheIAMProvider(user=username, cluster_name=cluster_name)\n",
292324
"user_connection = redis.Redis(host=endpoint, port=6379, credential_provider=creds_provider)\n",
293325
"user_connection.ping()"
294326
]

docs/examples/opentelemetry/main.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
import time
44

5+
import redis
56
import uptrace
67
from opentelemetry import trace
78
from opentelemetry.instrumentation.redis import RedisInstrumentor
89

9-
import redis
10-
1110
tracer = trace.get_tracer("app_or_package_name", "1.0.0")
1211

1312

0 commit comments

Comments
 (0)