Skip to content

Commit

Permalink
Fixed Python example to properly work with python cli
Browse files Browse the repository at this point in the history
  • Loading branch information
barshaul committed Feb 14, 2024
1 parent 25e8565 commit b832476
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,39 +44,42 @@ To install GLIDE for Redis using `pip`, follow these steps:
#### Cluster Redis:

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

#### Standalone Redis:

```python:
>>> from glide import (
... NodeAddress,
... RedisClientConfiguration,
... RedisClient,
... )
>>> addresses = [NodeAddress("redis_primary.example.com", 6379), NodeAddress("redis_replica.example.com", 6379)]
>>> config = RedisClientConfiguration(
... addresses=addresses
... )
>>> client = await RedisClient.create(config)
>>> await client.set("foo", "bar")
'OK'
>>> await client.get("foo")
'bar'
>>> import asyncio
>>> from glide import RedisClientConfiguration, NodeAddress, RedisClient
>>> async def test_standalone_client():
... addresses = [
... NodeAddress("redis_primary.example.com", 6379),
... NodeAddress("redis_replica.example.com", 6379)
... ]
... config = RedisClientConfiguration(addresses)
... client = await RedisClient.create(config)
... set_result = await client.set("foo", "bar")
... print(f"Set response is {set_result}")
... get_result = await client.get("foo")
... print(f"Get response is {get_result}")
...
>>> asyncio.run(test_standalone_client())
Set response is OK
Get response is bar
```

## Documentation
Expand Down

0 comments on commit b832476

Please sign in to comment.