From ba7af102ba76bb56210e05f53d99818783caca59 Mon Sep 17 00:00:00 2001 From: jonathanl-bq <72158117+jonathanl-bq@users.noreply.github.com> Date: Wed, 11 Sep 2024 15:37:45 -0700 Subject: [PATCH] Python: Replace instances of Redis with Valkey (#2266) * Replace instances of Redis with Valkey Signed-off-by: Jonathan Louie * Update CHANGELOG.md Signed-off-by: Jonathan Louie * Revert doc change for lolwut Signed-off-by: Jonathan Louie --------- Signed-off-by: Jonathan Louie Signed-off-by: jonathanl-bq <72158117+jonathanl-bq@users.noreply.github.com> Signed-off-by: Andrew Carbonetto Co-authored-by: Andrew Carbonetto --- CHANGELOG.md | 1 + python/DEVELOPER.md | 4 ++-- python/python/glide/glide_client.py | 2 +- python/python/tests/conftest.py | 26 ++++++++++++------------ python/python/tests/test_async_client.py | 14 ++++++------- python/python/tests/test_pubsub.py | 10 ++++----- python/python/tests/utils/cluster.py | 2 +- python/src/lib.rs | 12 +++++------ 8 files changed, 36 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a36a7f60fb..d07844d752 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ #### Changes +* Python: Replace instances of Redis with Valkey ([#2266](https://github.com/valkey-io/valkey-glide/pull/2266)) * Java: Replace instances of Redis with Valkey ([#2268](https://github.com/valkey-io/valkey-glide/pull/2268)) * Node: Replace instances of Redis with Valkey ([#2260](https://github.com/valkey-io/valkey-glide/pull/2260)) * Java: Fetch server version using info command ([#2258](https://github.com/valkey-io/valkey-glide/pull/2258)) diff --git a/python/DEVELOPER.md b/python/DEVELOPER.md index 2f71c6e27c..083ccda616 100644 --- a/python/DEVELOPER.md +++ b/python/DEVELOPER.md @@ -117,13 +117,13 @@ Before starting this step, make sure you've installed all software requirments. ``` > **Note:** To build the wrapper binary with debug symbols remove the --strip flag. 8. Run tests: - 1. Ensure that you have installed redis-server and redis-cli on your host. You can find the Redis installation guide at the following link: [Redis Installation Guide](https://redis.io/docs/install/install-redis/install-redis-on-linux/). + 1. Ensure that you have installed redis-server or valkey-server and redis-cli or valkey-cli on your host. You can find the Redis installation guide at the following link: [Redis Installation Guide](https://redis.io/docs/install/install-redis/install-redis-on-linux/). You can get Valkey from the following link: [Valkey Download](https://valkey.io/download/). 2. Validate the activation of the virtual environment from step 4 by ensuring its name (`.env`) is displayed next to your command prompt. 3. Execute the following command from the python folder: ```bash pytest --asyncio-mode=auto ``` - > **Note:** To run redis modules tests, add -k "test_server_modules.py". + > **Note:** To run Valkey modules tests, add -k "test_server_modules.py". - Install Python development requirements with: diff --git a/python/python/glide/glide_client.py b/python/python/glide/glide_client.py index 1e6d2a5b63..d2bc355542 100644 --- a/python/python/glide/glide_client.py +++ b/python/python/glide/glide_client.py @@ -570,7 +570,7 @@ class GlideClient(BaseClient, StandaloneCommands): """ Client used for connection to standalone servers. For full documentation, see - https://github.com/valkey-io/valkey-glide/wiki/Python-wrapper#redis-standalone + https://github.com/valkey-io/valkey-glide/wiki/Python-wrapper#standalone """ diff --git a/python/python/tests/conftest.py b/python/python/tests/conftest.py index 4fab580098..cb8125476a 100644 --- a/python/python/tests/conftest.py +++ b/python/python/tests/conftest.py @@ -14,7 +14,7 @@ from glide.glide_client import GlideClient, GlideClusterClient, TGlideClient from glide.logger import Level as logLevel from glide.logger import Logger -from tests.utils.cluster import RedisCluster +from tests.utils.cluster import ValkeyCluster DEFAULT_HOST = "localhost" DEFAULT_PORT = 6379 @@ -55,7 +55,7 @@ def pytest_addoption(parser): parser.addoption( "--load-module", action="append", - help="""Load additional Redis modules (provide full path for the module's shared library). + help="""Load additional Valkey modules (provide full path for the module's shared library). Use multiple times for multiple modules. Example: pytest --load-module=/path/to/module1.so --load-module=/path/to/module2.so""", @@ -110,27 +110,27 @@ def parse_endpoints(endpoints_str: str) -> List[List[str]]: def create_clusters(tls, load_module, cluster_endpoints, standalone_endpoints): """ - Create Redis clusters based on the provided options. + Create Valkey clusters based on the provided options. """ if cluster_endpoints or standalone_endpoints: # Endpoints were passed by the caller, not creating clusters internally if cluster_endpoints: cluster_endpoints = parse_endpoints(cluster_endpoints) - pytest.redis_cluster = RedisCluster(tls=tls, addresses=cluster_endpoints) + pytest.valkey_cluster = ValkeyCluster(tls=tls, addresses=cluster_endpoints) if standalone_endpoints: standalone_endpoints = parse_endpoints(standalone_endpoints) - pytest.standalone_cluster = RedisCluster( + pytest.standalone_cluster = ValkeyCluster( tls=tls, addresses=standalone_endpoints ) else: # No endpoints were provided, create new clusters - pytest.redis_cluster = RedisCluster( + pytest.valkey_cluster = ValkeyCluster( tls=tls, cluster_mode=True, load_module=load_module, addresses=cluster_endpoints, ) - pytest.standalone_cluster = RedisCluster( + pytest.standalone_cluster = ValkeyCluster( tls=tls, cluster_mode=False, shard_count=1, @@ -160,9 +160,9 @@ def pytest_sessionfinish(session, exitstatus): returning the exit status to the system. """ try: - del pytest.redis_cluster + del pytest.valkey_cluster except AttributeError: - # redis_cluster was not set, skip deletion + # valkey_cluster was not set, skip deletion pass try: @@ -233,10 +233,10 @@ async def create_client( # Create async socket client use_tls = request.config.getoption("--tls") if cluster_mode: - assert type(pytest.redis_cluster) is RedisCluster + assert type(pytest.valkey_cluster) is ValkeyCluster assert database_id == 0 - k = min(3, len(pytest.redis_cluster.nodes_addr)) - seed_nodes = random.sample(pytest.redis_cluster.nodes_addr, k=k) + k = min(3, len(pytest.valkey_cluster.nodes_addr)) + seed_nodes = random.sample(pytest.valkey_cluster.nodes_addr, k=k) cluster_config = GlideClusterClientConfiguration( addresses=seed_nodes if addresses is None else addresses, use_tls=use_tls, @@ -248,7 +248,7 @@ async def create_client( ) return await GlideClusterClient.create(cluster_config) else: - assert type(pytest.standalone_cluster) is RedisCluster + assert type(pytest.standalone_cluster) is ValkeyCluster config = GlideClientConfiguration( addresses=( pytest.standalone_cluster.nodes_addr if addresses is None else addresses diff --git a/python/python/tests/test_async_client.py b/python/python/tests/test_async_client.py index bfd227dcea..47655d5526 100644 --- a/python/python/tests/test_async_client.py +++ b/python/python/tests/test_async_client.py @@ -578,7 +578,7 @@ async def test_config_rewrite(self, glide_client: TGlideClient): if len(info_server["config_file"]) > 0: assert await glide_client.config_rewrite() == OK else: - # We expect Redis to return an error since the test cluster doesn't use redis.conf file + # We expect Valkey to return an error since the test cluster doesn't use valkey.conf file with pytest.raises(RequestError) as e: await glide_client.config_rewrite() assert "The server is running without a config file" in str(e) @@ -6951,7 +6951,7 @@ async def test_xgroup_set_id( ) # reset the last delivered ID for the consumer group to "1-1" - # ENTRIESREAD is only supported in Redis version 7.0.0 and above + # ENTRIESREAD is only supported in Valkey version 7.0.0 and above if await check_if_server_version_lt(glide_client, "7.0.0"): assert await glide_client.xgroup_set_id(key, group_name, stream_id1_1) == OK else: @@ -8206,7 +8206,7 @@ async def test_function_delete_with_routing( async def test_function_stats(self, glide_client: TGlideClient): min_version = "7.0.0" if await check_if_server_version_lt(glide_client, min_version): - return pytest.mark.skip(reason=f"Redis version required >= {min_version}") + return pytest.mark.skip(reason=f"Valkey version required >= {min_version}") lib_name = "functionStats_without_route" func_name = lib_name @@ -8252,7 +8252,7 @@ async def test_function_stats_running_script( ): min_version = "7.0.0" if await check_if_server_version_lt(glide_client, min_version): - return pytest.mark.skip(reason=f"Redis version required >= {min_version}") + return pytest.mark.skip(reason=f"Valkey version required >= {min_version}") lib_name = f"mylib1C{get_random_string(5)}" func_name = f"myfunc1c{get_random_string(5)}" @@ -8309,7 +8309,7 @@ async def test_function_stats_with_routing( ): min_version = "7.0.0" if await check_if_server_version_lt(glide_client, min_version): - return pytest.mark.skip(reason=f"Redis version required >= {min_version}") + return pytest.mark.skip(reason=f"Valkey version required >= {min_version}") route = ( SlotKeyRoute(SlotType.PRIMARY, get_random_string(10)) @@ -8376,7 +8376,7 @@ async def test_function_kill_no_write( ): min_version = "7.0.0" if await check_if_server_version_lt(glide_client, min_version): - return pytest.mark.skip(reason=f"Redis version required >= {min_version}") + return pytest.mark.skip(reason=f"Valkey version required >= {min_version}") lib_name = f"mylib1C{get_random_string(5)}" func_name = f"myfunc1c{get_random_string(5)}" @@ -8435,7 +8435,7 @@ async def test_function_kill_write_is_unkillable( ): min_version = "7.0.0" if await check_if_server_version_lt(glide_client, min_version): - return pytest.mark.skip(reason=f"Redis version required >= {min_version}") + return pytest.mark.skip(reason=f"Valkey version required >= {min_version}") lib_name = f"mylib1C{get_random_string(5)}" func_name = f"myfunc1c{get_random_string(5)}" diff --git a/python/python/tests/test_pubsub.py b/python/python/tests/test_pubsub.py index fd30c4ff70..4d1d344c0e 100644 --- a/python/python/tests/test_pubsub.py +++ b/python/python/tests/test_pubsub.py @@ -658,7 +658,7 @@ async def test_sharded_pubsub_many_channels( min_version = "7.0.0" if await check_if_server_version_lt(publishing_client, min_version): - pytest.skip(reason=f"Redis version required >= {min_version}") + pytest.skip(reason=f"Valkey version required >= {min_version}") # Publish messages to each channel for channel, message in channels_and_messages.items(): @@ -1247,9 +1247,9 @@ async def test_pubsub_combined_exact_pattern_and_sharded_one_client( pub_sub_exact, ) - # Setup PUBSUB for sharded channels (Redis version > 7) + # Setup PUBSUB for sharded channels (Valkey version > 7) if await check_if_server_version_lt(publishing_client, "7.0.0"): - pytest.skip("Redis version required >= 7.0.0") + pytest.skip("Valkey version required >= 7.0.0") # Publish messages to all channels for channel, message in { @@ -2062,9 +2062,9 @@ async def test_pubsub_sharded_max_size_message(self, request, cluster_mode: bool timeout=10000, ) - # (Redis version > 7) + # (Valkey version > 7) if await check_if_server_version_lt(publishing_client, "7.0.0"): - pytest.skip("Redis version required >= 7.0.0") + pytest.skip("Valkey version required >= 7.0.0") assert ( await cast(GlideClusterClient, publishing_client).publish( diff --git a/python/python/tests/utils/cluster.py b/python/python/tests/utils/cluster.py index a00ec2d625..e0bfb231ae 100644 --- a/python/python/tests/utils/cluster.py +++ b/python/python/tests/utils/cluster.py @@ -10,7 +10,7 @@ SCRIPT_FILE = os.path.abspath(f"{__file__}/../../../../../utils/cluster_manager.py") -class RedisCluster: +class ValkeyCluster: def __init__( self, tls, diff --git a/python/src/lib.rs b/python/src/lib.rs index b37ff1def8..6209a5b894 100644 --- a/python/src/lib.rs +++ b/python/src/lib.rs @@ -150,12 +150,12 @@ fn glide(_py: Python, m: &PyModule) -> PyResult<()> { let len = iterator.len(); iterator.try_fold(Vec::with_capacity(len), |mut acc, val| { - acc.push(redis_value_to_py(py, val)?); + acc.push(resp_value_to_py(py, val)?); Ok(acc) }) } - fn redis_value_to_py(py: Python, val: Value) -> PyResult { + fn resp_value_to_py(py: Python, val: Value) -> PyResult { match val { Value::Nil => Ok(py.None()), Value::SimpleString(str) => { @@ -175,14 +175,14 @@ fn glide(_py: Python, m: &PyModule) -> PyResult<()> { Value::Map(map) => { let dict = PyDict::new(py); for (key, value) in map { - dict.set_item(redis_value_to_py(py, key)?, redis_value_to_py(py, value)?)?; + dict.set_item(resp_value_to_py(py, key)?, resp_value_to_py(py, value)?)?; } Ok(dict.into_py(py)) } Value::Attribute { data, attributes } => { let dict = PyDict::new(py); - let value = redis_value_to_py(py, *data)?; - let attributes = redis_value_to_py(py, Value::Map(attributes))?; + let value = resp_value_to_py(py, *data)?; + let attributes = resp_value_to_py(py, Value::Map(attributes))?; dict.set_item("value", value)?; dict.set_item("attributes", attributes)?; Ok(dict.into_py(py)) @@ -213,7 +213,7 @@ fn glide(_py: Python, m: &PyModule) -> PyResult<()> { #[pyfn(m)] pub fn value_from_pointer(py: Python, pointer: u64) -> PyResult { let value = unsafe { Box::from_raw(pointer as *mut Value) }; - redis_value_to_py(py, *value) + resp_value_to_py(py, *value) } #[pyfn(m)]