Skip to content

Commit

Permalink
Python: Rename RedisClient, RedisClusterClient to GlideClient, GlideC…
Browse files Browse the repository at this point in the history
…lusterClient (#1669)
  • Loading branch information
shohamazon authored Jun 27, 2024
1 parent b1924a6 commit 7b6b220
Show file tree
Hide file tree
Showing 14 changed files with 340 additions and 339 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
### Breaking Changes
* 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))

## 0.4.1 (2024-02-06)

Expand Down
6 changes: 3 additions & 3 deletions benchmarks/python/python_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import redis.asyncio as redispy # type: ignore
from glide import (
BaseClientConfiguration,
GlideClient,
GlideClusterClient,
Logger,
LogLevel,
NodeAddress,
RedisClient,
RedisClusterClient,
)


Expand Down Expand Up @@ -288,7 +288,7 @@ async def main(

if clients_to_run == "all" or clients_to_run == "glide":
# Glide Socket
client_class = RedisClusterClient if is_cluster else RedisClient
client_class = GlideClusterClient if is_cluster else GlideClient
config = BaseClientConfiguration(
[NodeAddress(host=host, port=port)], use_tls=use_tls
)
Expand Down
14 changes: 7 additions & 7 deletions examples/python/client_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from glide import (
AllNodes,
BaseClientConfiguration,
GlideClient,
GlideClusterClient,
Logger,
LogLevel,
NodeAddress,
RedisClient,
RedisClusterClient,
)


Expand All @@ -28,7 +28,7 @@ def set_file_logger(level: LogLevel = LogLevel.WARN, file: Optional[str] = None)
Logger.set_logger_config(level, file)


async def send_set_and_get(client: Union[RedisClient, RedisClusterClient]):
async def send_set_and_get(client: Union[GlideClient, GlideClusterClient]):
set_response = await client.set("foo", "bar")
print(f"Set response is = {set_response}")
get_response = await client.get("foo")
Expand All @@ -39,14 +39,14 @@ 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 `RedisClientConfiguration/ClusterClientConfiguration` for additional options.
# Check `GlideClientConfiguration/ClusterClientConfiguration` for additional options.
config = BaseClientConfiguration(
addresses=addresses,
client_name="test_standalone_client",
# if the server use TLS, you'll need to enable it. Otherwise the connection attempt will time out silently.
# use_tls=True
)
client = await RedisClient.create(config)
client = await GlideClient.create(config)

# Send SET and GET
await send_set_and_get(client)
Expand All @@ -58,14 +58,14 @@ 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 `RedisClientConfiguration/ClusterClientConfiguration` for additional options.
# Check `GlideClientConfiguration/ClusterClientConfiguration` for additional options.
config = BaseClientConfiguration(
addresses=addresses,
client_name="test_cluster_client",
# if the cluster nodes use TLS, you'll need to enable it. Otherwise the connection attempt will time out silently.
# use_tls=True
)
client = await RedisClusterClient.create(config)
client = await GlideClusterClient.create(config)

# Send SET and GET
await send_set_and_get(client)
Expand Down
14 changes: 7 additions & 7 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ To install GLIDE for Redis using `pip`, follow these steps:

```python:
>>> import asyncio
>>> from glide import ClusterClientConfiguration, NodeAddress, RedisClusterClient
>>> from glide import ClusterClientConfiguration, NodeAddress, GlideClusterClient
>>> async def test_cluster_client():
... addresses = [NodeAddress("redis.example.com", 6379)]
... config = ClusterClientConfiguration(addresses)
... client = await RedisClusterClient.create(config)
... client = await GlideClusterClient.create(config)
... set_result = await client.set("foo", "bar")
... print(f"Set response is {set_result}")
... get_result = await client.get("foo")
Expand All @@ -64,14 +64,14 @@ Get response is bar

```python:
>>> import asyncio
>>> from glide import RedisClientConfiguration, NodeAddress, RedisClient
>>> from glide import GlideClientConfiguration, NodeAddress, GlideClient
>>> async def test_standalone_client():
... addresses = [
... NodeAddress("redis_primary.example.com", 6379),
... NodeAddress("redis_replica.example.com", 6379)
... NodeAddress("server_primary.example.com", 6379),
... NodeAddress("server_replica.example.com", 6379)
... ]
... config = RedisClientConfiguration(addresses)
... client = await RedisClient.create(config)
... config = GlideClientConfiguration(addresses)
... client = await GlideClient.create(config)
... set_result = await client.set("foo", "bar")
... print(f"Set response is {set_result}")
... get_result = await client.get("foo")
Expand Down
10 changes: 5 additions & 5 deletions python/python/glide/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@
BackoffStrategy,
BaseClientConfiguration,
ClusterClientConfiguration,
GlideClientConfiguration,
NodeAddress,
PeriodicChecksManualInterval,
PeriodicChecksStatus,
ProtocolVersion,
ReadFrom,
RedisClientConfiguration,
RedisCredentials,
)
from glide.constants import OK
Expand All @@ -83,9 +83,9 @@
RequestError,
TimeoutError,
)
from glide.glide_client import GlideClient, GlideClusterClient
from glide.logger import Level as LogLevel
from glide.logger import Logger
from glide.redis_client import RedisClient, RedisClusterClient
from glide.routes import (
AllNodes,
AllPrimaries,
Expand All @@ -100,13 +100,13 @@

__all__ = [
# Client
"RedisClient",
"RedisClusterClient",
"GlideClient",
"GlideClusterClient",
"Transaction",
"ClusterTransaction",
# Config
"BaseClientConfiguration",
"RedisClientConfiguration",
"GlideClientConfiguration",
"ClusterClientConfiguration",
"BackoffStrategy",
"ReadFrom",
Expand Down
22 changes: 11 additions & 11 deletions python/python/glide/async_commands/redis_modules/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

from glide.async_commands.core import ConditionalChange
from glide.constants import TOK, TJsonResponse
from glide.glide_client import TGlideClient
from glide.protobuf.redis_request_pb2 import RequestType
from glide.redis_client import TRedisClient


class JsonGetOptions:
Expand Down Expand Up @@ -55,7 +55,7 @@ def get_options(self) -> List[str]:


async def set(
client: TRedisClient,
client: TGlideClient,
key: str,
path: str,
value: str,
Expand All @@ -67,7 +67,7 @@ async def set(
See https://redis.io/commands/json.set/ for more details.
Args:
client (TRedisClient): The Redis client to execute the command.
client (TGlideClient): The Redis client to execute the command.
key (str): The key of the JSON document.
path (str): Represents the path within the JSON document where the value will be set.
The key will be modified only if `value` is added as the last child in the specified `path`, or if the specified `path` acts as the parent of a new child being added.
Expand Down Expand Up @@ -95,7 +95,7 @@ async def set(


async def get(
client: TRedisClient,
client: TGlideClient,
key: str,
paths: Optional[Union[str, List[str]]] = None,
options: Optional[JsonGetOptions] = None,
Expand All @@ -106,7 +106,7 @@ async def get(
See https://redis.io/commands/json.get/ for more details.
Args:
client (TRedisClient): The Redis client to execute the command.
client (TGlideClient): The Redis client to execute the command.
key (str): The key of the JSON document.
paths (Optional[Union[str, List[str]]]): The path or list of paths within the JSON document. Default is root `$`.
options (Optional[JsonGetOptions]): Options for formatting the string representation of the JSON data. See `JsonGetOptions`.
Expand Down Expand Up @@ -140,7 +140,7 @@ async def get(


async def delete(
client: TRedisClient,
client: TGlideClient,
key: str,
path: Optional[str] = None,
) -> int:
Expand All @@ -150,7 +150,7 @@ async def delete(
See https://redis.io/commands/json.del/ for more details.
Args:
client (TRedisClient): The Redis client to execute the command.
client (TGlideClient): The Redis client to execute the command.
key (str): The key of the JSON document.
path (Optional[str]): Represents the path within the JSON document where the value will be deleted.
If None, deletes the entire JSON document at `key`. Defaults to None.
Expand All @@ -177,7 +177,7 @@ async def delete(


async def forget(
client: TRedisClient,
client: TGlideClient,
key: str,
path: Optional[str] = None,
) -> Optional[int]:
Expand All @@ -187,7 +187,7 @@ async def forget(
See https://redis.io/commands/json.forget/ for more details.
Args:
client (TRedisClient): The Redis client to execute the command.
client (TGlideClient): The Redis client to execute the command.
key (str): The key of the JSON document.
path (Optional[str]): Represents the path within the JSON document where the value will be deleted.
If None, deletes the entire JSON document at `key`. Defaults to None.
Expand Down Expand Up @@ -215,7 +215,7 @@ async def forget(


async def toggle(
client: TRedisClient,
client: TGlideClient,
key: str,
path: str,
) -> TJsonResponse[bool]:
Expand All @@ -225,7 +225,7 @@ async def toggle(
See https://redis.io/commands/json.toggle/ for more details.
Args:
client (TRedisClient): The Redis client to execute the command.
client (TGlideClient): The Redis client to execute the command.
key (str): The key of the JSON document.
path (str): The JSONPath to specify.
Expand Down
14 changes: 7 additions & 7 deletions python/python/glide/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def __init__(
protocol: ProtocolVersion = ProtocolVersion.RESP3,
):
"""
Represents the configuration settings for a Redis client.
Represents the configuration settings for a Glide client.
Args:
addresses (List[NodeAddress]): DNS Addresses and ports of known nodes in the cluster.
Expand Down Expand Up @@ -208,9 +208,9 @@ def _get_pubsub_callback_and_context(
return None, None


class RedisClientConfiguration(BaseClientConfiguration):
class GlideClientConfiguration(BaseClientConfiguration):
"""
Represents the configuration settings for a Standalone Redis client.
Represents the configuration settings for a Standalone Glide client.
Args:
addresses (List[NodeAddress]): DNS Addresses and ports of known nodes in the cluster.
Expand All @@ -234,7 +234,7 @@ class RedisClientConfiguration(BaseClientConfiguration):
database_id (Optional[int]): index of the logical database to connect to.
client_name (Optional[str]): Client name to be used for the client. Will be used with CLIENT SETNAME command during connection establishment.
protocol (ProtocolVersion): The version of the Redis RESP protocol to communicate with the server.
pubsub_subscriptions (Optional[RedisClientConfiguration.PubSubSubscriptions]): Pubsub subscriptions to be used for the client.
pubsub_subscriptions (Optional[GlideClientConfiguration.PubSubSubscriptions]): Pubsub subscriptions to be used for the client.
Will be applied via SUBSCRIBE/PSUBSCRIBE commands during connection establishment.
"""

Expand All @@ -254,7 +254,7 @@ class PubSubSubscriptions:
"""Describes pubsub configuration for standalone mode client.
Attributes:
channels_and_patterns (Dict[RedisClientConfiguration.PubSubChannelModes, Set[str]]):
channels_and_patterns (Dict[GlideClientConfiguration.PubSubChannelModes, Set[str]]):
Channels and patterns by modes.
callback (Optional[Callable[[CoreCommands.PubSubMsg, Any], None]]):
Optional callback to accept the incomming messages.
Expand All @@ -263,7 +263,7 @@ class PubSubSubscriptions:
"""

channels_and_patterns: Dict[
RedisClientConfiguration.PubSubChannelModes, Set[str]
GlideClientConfiguration.PubSubChannelModes, Set[str]
]
callback: Optional[Callable[[CoreCommands.PubSubMsg, Any], None]]
context: Any
Expand Down Expand Up @@ -347,7 +347,7 @@ def _get_pubsub_callback_and_context(

class ClusterClientConfiguration(BaseClientConfiguration):
"""
Represents the configuration settings for a Cluster Redis client.
Represents the configuration settings for a Cluster Glide client.
Args:
addresses (List[NodeAddress]): DNS Addresses and ports of known nodes in the cluster.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_request_error_class(
return RequestError


class BaseRedisClient(CoreCommands):
class BaseClient(CoreCommands):
def __init__(self, config: BaseClientConfiguration):
"""
To create a new client, use the `create` classmethod
Expand All @@ -70,14 +70,14 @@ def __init__(self, config: BaseClientConfiguration):

@classmethod
async def create(cls, config: BaseClientConfiguration) -> Self:
"""Creates a Redis client.
"""Creates a Glide client.
Args:
config (ClientConfiguration): The client configurations.
If no configuration is provided, a default client to "localhost":6379 will be created.
Returns:
Self: a Redis Client instance.
Self: a Glide Client instance.
"""
config = config
self = cls(config)
Expand Down Expand Up @@ -387,11 +387,11 @@ def _notification_to_pubsub_message_safe(
):
values: List = push_notification["values"]
if message_kind == "PMessage":
pubsub_message = BaseRedisClient.PubSubMsg(
pubsub_message = BaseClient.PubSubMsg(
message=values[2], channel=values[1], pattern=values[0]
)
else:
pubsub_message = BaseRedisClient.PubSubMsg(
pubsub_message = BaseClient.PubSubMsg(
message=values[1], channel=values[0], pattern=None
)
elif (
Expand Down Expand Up @@ -509,9 +509,9 @@ async def _reader_loop(self) -> None:
await self._process_response(response=response)


class RedisClusterClient(BaseRedisClient, ClusterCommands):
class GlideClusterClient(BaseClient, ClusterCommands):
"""
Client used for connection to cluster Redis servers.
Client used for connection to cluster servers.
For full documentation, see
https://github.com/aws/babushka/wiki/Python-wrapper#redis-cluster
"""
Expand All @@ -520,12 +520,12 @@ def _get_protobuf_conn_request(self) -> ConnectionRequest:
return self.config._create_a_protobuf_conn_request(cluster_mode=True)


class RedisClient(BaseRedisClient, StandaloneCommands):
class GlideClient(BaseClient, StandaloneCommands):
"""
Client used for connection to standalone Redis servers.
Client used for connection to standalone servers.
For full documentation, see
https://github.com/aws/babushka/wiki/Python-wrapper#redis-standalone
"""


TRedisClient = Union[RedisClient, RedisClusterClient]
TGlideClient = Union[GlideClient, GlideClusterClient]
Loading

0 comments on commit 7b6b220

Please sign in to comment.