From 81f6f0a54be266f2f4be9088c22d56c092160648 Mon Sep 17 00:00:00 2001 From: Shoham Elias Date: Thu, 4 Jul 2024 13:10:38 +0000 Subject: [PATCH] Python: Rename ClusterClientConfiguration to GlideClusterClientConfiguration --- CHANGELOG.md | 1 + examples/python/client_example.py | 4 +- python/README.md | 4 +- python/python/glide/__init__.py | 4 +- python/python/glide/config.py | 8 +- python/python/tests/conftest.py | 6 +- python/python/tests/test_async_client.py | 2 +- python/python/tests/test_config.py | 4 +- python/python/tests/test_pubsub.py | 94 ++++++++++++++---------- 9 files changed, 74 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d595d5328..94cd88286a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -85,6 +85,7 @@ * Node: Update XREAD to return a Map of Map ([#1494](https://github.com/aws/glide-for-redis/pull/1494)) * Node: Rename RedisClient to GlideClient and RedisClusterClient to GlideClusterClient ([#1670](https://github.com/aws/glide-for-redis/pull/1670)) * Python: Rename RedisClient to GlideClient, RedisClusterClient to GlideClusterClient and BaseRedisClient to BaseClient([#1669](https://github.com/aws/glide-for-redis/pull/1669)) +* Python: Rename ClusterClientConfiguration to GlideClusterClientConfiguration ([#1806](https://github.com/aws/glide-for-redis/pull/1806)) ## 0.4.1 (2024-02-06) diff --git a/examples/python/client_example.py b/examples/python/client_example.py index bcc52be8e8..35d9ea5a8b 100755 --- a/examples/python/client_example.py +++ b/examples/python/client_example.py @@ -39,7 +39,7 @@ async def test_standalone_client(host: str = "localhost", port: int = 6379): # When in Redis is in standalone mode, add address of the primary node, # and any replicas you'd like to be able to read from. addresses = [NodeAddress(host, port)] - # Check `GlideClientConfiguration/ClusterClientConfiguration` for additional options. + # Check `GlideClientConfiguration/GlideClusterClientConfiguration` for additional options. config = BaseClientConfiguration( addresses=addresses, client_name="test_standalone_client", @@ -59,7 +59,7 @@ async def test_standalone_client(host: str = "localhost", port: int = 6379): async def test_cluster_client(host: str = "localhost", port: int = 6379): # When in Redis is cluster mode, add address of any nodes, and the client will find all nodes in the cluster. addresses = [NodeAddress(host, port)] - # Check `GlideClientConfiguration/ClusterClientConfiguration` for additional options. + # Check `GlideClientConfiguration/GlideClusterClientConfiguration` for additional options. config = BaseClientConfiguration( addresses=addresses, client_name="test_cluster_client", diff --git a/python/README.md b/python/README.md index 22c01d75ce..f857b69789 100644 --- a/python/README.md +++ b/python/README.md @@ -51,10 +51,10 @@ To install GLIDE for Redis using `pip`, follow these steps: ```python: >>> import asyncio ->>> from glide import ClusterClientConfiguration, NodeAddress, GlideClusterClient +>>> from glide import GlideClusterClientConfiguration, NodeAddress, GlideClusterClient >>> async def test_cluster_client(): ... addresses = [NodeAddress("redis.example.com", 6379)] -... config = ClusterClientConfiguration(addresses) +... config = GlideClusterClientConfiguration(addresses) ... client = await GlideClusterClient.create(config) ... set_result = await client.set("foo", "bar") ... print(f"Set response is {set_result}") diff --git a/python/python/glide/__init__.py b/python/python/glide/__init__.py index 61a0137275..c755f201f3 100644 --- a/python/python/glide/__init__.py +++ b/python/python/glide/__init__.py @@ -67,8 +67,8 @@ from glide.config import ( BackoffStrategy, BaseClientConfiguration, - ClusterClientConfiguration, GlideClientConfiguration, + GlideClusterClientConfiguration, NodeAddress, PeriodicChecksManualInterval, PeriodicChecksStatus, @@ -110,7 +110,7 @@ # Config "BaseClientConfiguration", "GlideClientConfiguration", - "ClusterClientConfiguration", + "GlideClusterClientConfiguration", "BackoffStrategy", "ReadFrom", "ServerCredentials", diff --git a/python/python/glide/config.py b/python/python/glide/config.py index e4ad281b76..662bffd889 100644 --- a/python/python/glide/config.py +++ b/python/python/glide/config.py @@ -345,7 +345,7 @@ def _get_pubsub_callback_and_context( return None, None -class ClusterClientConfiguration(BaseClientConfiguration): +class GlideClusterClientConfiguration(BaseClientConfiguration): """ Represents the configuration settings for a Cluster Glide client. @@ -369,7 +369,7 @@ class ClusterClientConfiguration(BaseClientConfiguration): These checks evaluate changes in the cluster's topology, triggering a slot refresh when detected. Periodic checks ensure a quick and efficient process by querying a limited number of nodes. Defaults to PeriodicChecksStatus.ENABLED_DEFAULT_CONFIGS. - pubsub_subscriptions (Optional[ClusterClientConfiguration.PubSubSubscriptions]): Pubsub subscriptions to be used for the client. + pubsub_subscriptions (Optional[GlideClusterClientConfiguration.PubSubSubscriptions]): Pubsub subscriptions to be used for the client. Will be applied via SUBSCRIBE/PSUBSCRIBE/SSUBSCRIBE commands during connection establishment. Notes: @@ -395,7 +395,7 @@ class PubSubSubscriptions: """Describes pubsub configuration for cluster mode client. Attributes: - channels_and_patterns (Dict[ClusterClientConfiguration.PubSubChannelModes, Set[str]]): + channels_and_patterns (Dict[GlideClusterClientConfiguration.PubSubChannelModes, Set[str]]): Channels and patterns by modes. callback (Optional[Callable[[CoreCommands.PubSubMsg, Any], None]]): Optional callback to accept the incoming messages. @@ -404,7 +404,7 @@ class PubSubSubscriptions: """ channels_and_patterns: Dict[ - ClusterClientConfiguration.PubSubChannelModes, Set[str] + GlideClusterClientConfiguration.PubSubChannelModes, Set[str] ] callback: Optional[Callable[[CoreCommands.PubSubMsg, Any], None]] context: Any diff --git a/python/python/tests/conftest.py b/python/python/tests/conftest.py index b10b0eadcf..4fab580098 100644 --- a/python/python/tests/conftest.py +++ b/python/python/tests/conftest.py @@ -5,8 +5,8 @@ import pytest from glide.config import ( - ClusterClientConfiguration, GlideClientConfiguration, + GlideClusterClientConfiguration, NodeAddress, ProtocolVersion, ServerCredentials, @@ -224,7 +224,7 @@ async def create_client( protocol: ProtocolVersion = ProtocolVersion.RESP3, timeout: Optional[int] = None, cluster_mode_pubsub: Optional[ - ClusterClientConfiguration.PubSubSubscriptions + GlideClusterClientConfiguration.PubSubSubscriptions ] = None, standalone_mode_pubsub: Optional[ GlideClientConfiguration.PubSubSubscriptions @@ -237,7 +237,7 @@ async def create_client( assert database_id == 0 k = min(3, len(pytest.redis_cluster.nodes_addr)) seed_nodes = random.sample(pytest.redis_cluster.nodes_addr, k=k) - cluster_config = ClusterClientConfiguration( + cluster_config = GlideClusterClientConfiguration( addresses=seed_nodes if addresses is None else addresses, use_tls=use_tls, credentials=credentials, diff --git a/python/python/tests/test_async_client.py b/python/python/tests/test_async_client.py index 58b3113d14..9ef669f54b 100644 --- a/python/python/tests/test_async_client.py +++ b/python/python/tests/test_async_client.py @@ -71,8 +71,8 @@ ) from glide.async_commands.transaction import ClusterTransaction, Transaction from glide.config import ( - ClusterClientConfiguration, GlideClientConfiguration, + GlideClusterClientConfiguration, ProtocolVersion, ServerCredentials, ) diff --git a/python/python/tests/test_config.py b/python/python/tests/test_config.py index 9c05db1199..93c280245f 100644 --- a/python/python/tests/test_config.py +++ b/python/python/tests/test_config.py @@ -2,7 +2,7 @@ from glide.config import ( BaseClientConfiguration, - ClusterClientConfiguration, + GlideClusterClientConfiguration, NodeAddress, PeriodicChecksManualInterval, PeriodicChecksStatus, @@ -38,7 +38,7 @@ def test_convert_to_protobuf(): def test_periodic_checks_interval_to_protobuf(): - config = ClusterClientConfiguration( + config = GlideClusterClientConfiguration( [NodeAddress("127.0.0.1")], ) request = config._create_a_protobuf_conn_request(cluster_mode=True) diff --git a/python/python/tests/test_pubsub.py b/python/python/tests/test_pubsub.py index f447ed9fe9..ae33e5ae0e 100644 --- a/python/python/tests/test_pubsub.py +++ b/python/python/tests/test_pubsub.py @@ -9,8 +9,8 @@ import pytest from glide.async_commands.core import CoreCommands from glide.config import ( - ClusterClientConfiguration, GlideClientConfiguration, + GlideClusterClientConfiguration, ProtocolVersion, ) from glide.constants import OK @@ -122,7 +122,7 @@ async def check_no_messages_left( def create_pubsub_subscription( cluster_mode, cluster_channels_and_patterns: Dict[ - ClusterClientConfiguration.PubSubChannelModes, Set[str] + GlideClusterClientConfiguration.PubSubChannelModes, Set[str] ], standalone_channels_and_patterns: Dict[ GlideClientConfiguration.PubSubChannelModes, Set[str] @@ -131,7 +131,7 @@ def create_pubsub_subscription( context=None, ): if cluster_mode: - return ClusterClientConfiguration.PubSubSubscriptions( + return GlideClusterClientConfiguration.PubSubSubscriptions( channels_and_patterns=cluster_channels_and_patterns, callback=callback, context=context, @@ -178,7 +178,7 @@ async def test_pubsub_exact_happy_path( pub_sub = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Exact: {channel}}, + {GlideClusterClientConfiguration.PubSubChannelModes.Exact: {channel}}, {GlideClientConfiguration.PubSubChannelModes.Exact: {channel}}, callback=callback, context=context, @@ -228,7 +228,7 @@ async def test_pubsub_exact_happy_path_coexistence( pub_sub = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Exact: {channel}}, + {GlideClusterClientConfiguration.PubSubChannelModes.Exact: {channel}}, {GlideClientConfiguration.PubSubChannelModes.Exact: {channel}}, ) @@ -305,7 +305,7 @@ async def test_pubsub_exact_happy_path_many_channels( pub_sub = create_pubsub_subscription( cluster_mode, { - ClusterClientConfiguration.PubSubChannelModes.Exact: set( + GlideClusterClientConfiguration.PubSubChannelModes.Exact: set( channels_and_messages.keys() ) }, @@ -380,7 +380,7 @@ async def test_pubsub_exact_happy_path_many_channels_co_existence( pub_sub = create_pubsub_subscription( cluster_mode, { - ClusterClientConfiguration.PubSubChannelModes.Exact: set( + GlideClusterClientConfiguration.PubSubChannelModes.Exact: set( channels_and_messages.keys() ) }, @@ -458,7 +458,7 @@ async def test_sharded_pubsub( pub_sub = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Sharded: {channel}}, + {GlideClusterClientConfiguration.PubSubChannelModes.Sharded: {channel}}, {}, callback=callback, context=context, @@ -517,7 +517,7 @@ async def test_sharded_pubsub_co_existence(self, request, cluster_mode: bool): pub_sub = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Sharded: {channel}}, + {GlideClusterClientConfiguration.PubSubChannelModes.Sharded: {channel}}, {}, ) @@ -606,7 +606,7 @@ async def test_sharded_pubsub_many_channels( pub_sub = create_pubsub_subscription( cluster_mode, { - ClusterClientConfiguration.PubSubChannelModes.Sharded: set( + GlideClusterClientConfiguration.PubSubChannelModes.Sharded: set( channels_and_messages.keys() ) }, @@ -690,7 +690,7 @@ async def test_pubsub_pattern( pub_sub = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Pattern: {PATTERN}}, + {GlideClusterClientConfiguration.PubSubChannelModes.Pattern: {PATTERN}}, {GlideClientConfiguration.PubSubChannelModes.Pattern: {PATTERN}}, callback=callback, context=context, @@ -747,7 +747,7 @@ async def test_pubsub_pattern_co_existence(self, request, cluster_mode: bool): pub_sub = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Pattern: {PATTERN}}, + {GlideClusterClientConfiguration.PubSubChannelModes.Pattern: {PATTERN}}, {GlideClientConfiguration.PubSubChannelModes.Pattern: {PATTERN}}, ) @@ -819,7 +819,7 @@ async def test_pubsub_pattern_many_channels( pub_sub = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Pattern: {PATTERN}}, + {GlideClusterClientConfiguration.PubSubChannelModes.Pattern: {PATTERN}}, {GlideClientConfiguration.PubSubChannelModes.Pattern: {PATTERN}}, callback=callback, context=context, @@ -906,10 +906,10 @@ async def test_pubsub_combined_exact_and_pattern_one_client( pub_sub_exact = create_pubsub_subscription( cluster_mode, { - ClusterClientConfiguration.PubSubChannelModes.Exact: set( + GlideClusterClientConfiguration.PubSubChannelModes.Exact: set( exact_channels_and_messages.keys() ), - ClusterClientConfiguration.PubSubChannelModes.Pattern: {PATTERN}, + GlideClusterClientConfiguration.PubSubChannelModes.Pattern: {PATTERN}, }, { GlideClientConfiguration.PubSubChannelModes.Exact: set( @@ -1017,7 +1017,7 @@ async def test_pubsub_combined_exact_and_pattern_multiple_clients( pub_sub_exact = create_pubsub_subscription( cluster_mode, { - ClusterClientConfiguration.PubSubChannelModes.Exact: set( + GlideClusterClientConfiguration.PubSubChannelModes.Exact: set( exact_channels_and_messages.keys() ) }, @@ -1044,7 +1044,7 @@ async def test_pubsub_combined_exact_and_pattern_multiple_clients( # Setup PUBSUB for pattern channels pub_sub_pattern = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Pattern: {PATTERN}}, + {GlideClusterClientConfiguration.PubSubChannelModes.Pattern: {PATTERN}}, {GlideClientConfiguration.PubSubChannelModes.Pattern: {PATTERN}}, callback=callback, context=context, @@ -1164,11 +1164,11 @@ async def test_pubsub_combined_exact_pattern_and_sharded_one_client( pub_sub_exact = create_pubsub_subscription( cluster_mode, { - ClusterClientConfiguration.PubSubChannelModes.Exact: set( + GlideClusterClientConfiguration.PubSubChannelModes.Exact: set( exact_channels_and_messages.keys() ), - ClusterClientConfiguration.PubSubChannelModes.Pattern: {PATTERN}, - ClusterClientConfiguration.PubSubChannelModes.Sharded: set( + GlideClusterClientConfiguration.PubSubChannelModes.Pattern: {PATTERN}, + GlideClusterClientConfiguration.PubSubChannelModes.Sharded: set( sharded_channels_and_messages.keys() ), }, @@ -1304,7 +1304,7 @@ async def test_pubsub_combined_exact_pattern_and_sharded_multi_client( pub_sub_exact = create_pubsub_subscription( cluster_mode, { - ClusterClientConfiguration.PubSubChannelModes.Exact: set( + GlideClusterClientConfiguration.PubSubChannelModes.Exact: set( exact_channels_and_messages.keys() ) }, @@ -1333,7 +1333,7 @@ async def test_pubsub_combined_exact_pattern_and_sharded_multi_client( # Setup PUBSUB for pattern channels pub_sub_pattern = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Pattern: {PATTERN}}, + {GlideClusterClientConfiguration.PubSubChannelModes.Pattern: {PATTERN}}, {GlideClientConfiguration.PubSubChannelModes.Pattern: {PATTERN}}, callback=callback, context=context, @@ -1345,7 +1345,7 @@ async def test_pubsub_combined_exact_pattern_and_sharded_multi_client( pub_sub_sharded = create_pubsub_subscription( cluster_mode, { - ClusterClientConfiguration.PubSubChannelModes.Sharded: set( + GlideClusterClientConfiguration.PubSubChannelModes.Sharded: set( sharded_channels_and_messages.keys() ) }, @@ -1495,7 +1495,7 @@ async def test_pubsub_combined_different_channels_with_same_name( # Setup PUBSUB for exact channel pub_sub_exact = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Exact: {CHANNEL_NAME}}, + {GlideClusterClientConfiguration.PubSubChannelModes.Exact: {CHANNEL_NAME}}, {GlideClientConfiguration.PubSubChannelModes.Exact: {CHANNEL_NAME}}, callback=callback, context=context, @@ -1518,7 +1518,11 @@ async def test_pubsub_combined_different_channels_with_same_name( # Setup PUBSUB for pattern channels pub_sub_pattern = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Pattern: {CHANNEL_NAME}}, + { + GlideClusterClientConfiguration.PubSubChannelModes.Pattern: { + CHANNEL_NAME + } + }, {GlideClientConfiguration.PubSubChannelModes.Pattern: {CHANNEL_NAME}}, callback=callback, context=context, @@ -1529,7 +1533,11 @@ async def test_pubsub_combined_different_channels_with_same_name( pub_sub_sharded = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Sharded: {CHANNEL_NAME}}, + { + GlideClusterClientConfiguration.PubSubChannelModes.Sharded: { + CHANNEL_NAME + } + }, {}, callback=callback, context=context, @@ -1635,7 +1643,7 @@ async def test_pubsub_two_publishing_clients_same_name( # Setup PUBSUB for exact channel pub_sub_exact = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Exact: {CHANNEL_NAME}}, + {GlideClusterClientConfiguration.PubSubChannelModes.Exact: {CHANNEL_NAME}}, {GlideClientConfiguration.PubSubChannelModes.Exact: {CHANNEL_NAME}}, callback=callback, context=context_exact, @@ -1643,7 +1651,11 @@ async def test_pubsub_two_publishing_clients_same_name( # Setup PUBSUB for pattern channels pub_sub_pattern = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Pattern: {CHANNEL_NAME}}, + { + GlideClusterClientConfiguration.PubSubChannelModes.Pattern: { + CHANNEL_NAME + } + }, {GlideClientConfiguration.PubSubChannelModes.Pattern: {CHANNEL_NAME}}, callback=callback, context=context_pattern, @@ -1736,7 +1748,7 @@ async def test_pubsub_three_publishing_clients_same_name_with_sharded( # Setup PUBSUB for exact channel pub_sub_exact = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Exact: {CHANNEL_NAME}}, + {GlideClusterClientConfiguration.PubSubChannelModes.Exact: {CHANNEL_NAME}}, {GlideClientConfiguration.PubSubChannelModes.Exact: {CHANNEL_NAME}}, callback=callback, context=context_exact, @@ -1744,7 +1756,11 @@ async def test_pubsub_three_publishing_clients_same_name_with_sharded( # Setup PUBSUB for pattern channels pub_sub_pattern = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Pattern: {CHANNEL_NAME}}, + { + GlideClusterClientConfiguration.PubSubChannelModes.Pattern: { + CHANNEL_NAME + } + }, {GlideClientConfiguration.PubSubChannelModes.Pattern: {CHANNEL_NAME}}, callback=callback, context=context_pattern, @@ -1752,7 +1768,11 @@ async def test_pubsub_three_publishing_clients_same_name_with_sharded( # Setup PUBSUB for pattern channels pub_sub_sharded = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Sharded: {CHANNEL_NAME}}, + { + GlideClusterClientConfiguration.PubSubChannelModes.Sharded: { + CHANNEL_NAME + } + }, {}, callback=callback, context=context_sharded, @@ -1854,7 +1874,7 @@ async def test_pubsub_exact_max_size_message(self, request, cluster_mode: bool): pub_sub = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Exact: {channel}}, + {GlideClusterClientConfiguration.PubSubChannelModes.Exact: {channel}}, {GlideClientConfiguration.PubSubChannelModes.Exact: {channel}}, ) @@ -1921,7 +1941,7 @@ async def test_pubsub_sharded_max_size_message(self, request, cluster_mode: bool pub_sub = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Sharded: {channel}}, + {GlideClusterClientConfiguration.PubSubChannelModes.Sharded: {channel}}, {}, ) @@ -2000,7 +2020,7 @@ async def test_pubsub_exact_max_size_message_callback( pub_sub = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Exact: {channel}}, + {GlideClusterClientConfiguration.PubSubChannelModes.Exact: {channel}}, {GlideClientConfiguration.PubSubChannelModes.Exact: {channel}}, callback=callback, context=context, @@ -2057,7 +2077,7 @@ async def test_pubsub_sharded_max_size_message_callback( pub_sub = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Sharded: {channel}}, + {GlideClusterClientConfiguration.PubSubChannelModes.Sharded: {channel}}, {}, callback=callback, context=context, @@ -2101,7 +2121,7 @@ async def test_pubsub_resp2_raise_an_error(self, request, cluster_mode: bool): pub_sub_exact = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Exact: {channel}}, + {GlideClusterClientConfiguration.PubSubChannelModes.Exact: {channel}}, {GlideClientConfiguration.PubSubChannelModes.Exact: {channel}}, ) @@ -2119,7 +2139,7 @@ async def test_pubsub_context_with_no_callback_raise_error( context: List[CoreCommands.PubSubMsg] = [] pub_sub_exact = create_pubsub_subscription( cluster_mode, - {ClusterClientConfiguration.PubSubChannelModes.Exact: {channel}}, + {GlideClusterClientConfiguration.PubSubChannelModes.Exact: {channel}}, {GlideClientConfiguration.PubSubChannelModes.Exact: {channel}}, context=context, )