Skip to content

Commit 36de04a

Browse files
committed
Simplify Redis Cluster mode implementation
1 parent e16ab84 commit 36de04a

File tree

4 files changed

+10
-67
lines changed

4 files changed

+10
-67
lines changed

Dockerfile

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,8 @@ COPY . /app
1111
RUN pip install --upgrade pip \
1212
&& pip install .
1313

14-
# Default environment variables
15-
ENV REDIS_HOST=127.0.0.1 \
16-
REDIS_PORT=6379 \
17-
REDIS_CLUSTER_MODE=false \
18-
REDIS_CLUSTER_NODES=""
19-
20-
# Expose the MCP server port
21-
EXPOSE 3333
14+
# Expose necessary port if any (MCP typically uses stdio, but if needed, uncomment below)
15+
# EXPOSE 8000
2216

2317
# Run the MCP Server
2418
CMD ["python", "src/main.py"]

README.md

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -74,37 +74,6 @@ To configure this Redis MCP Server, consider the following environment variables
7474
| `REDIS_CERT_REQS` | Whether the client should verify the server's certificate | `"required"` |
7575
| `REDIS_CA_CERTS` | Path to the trusted CA certificates file | None |
7676
| `REDIS_CLUSTER_MODE` | Enable Redis Cluster mode | `False` |
77-
| `REDIS_CLUSTER_NODES` | Comma-separated list of cluster nodes (host:port) | "" |
78-
79-
## Docker Deployment
80-
81-
You can run the Redis MCP Server in a Docker container:
82-
83-
```bash
84-
# Build the Docker image
85-
docker build -t mcp-redis .
86-
87-
# Run in standalone mode
88-
docker run --rm -it \
89-
-e REDIS_HOST=<your-redis-host> \
90-
-e REDIS_PORT=<your-redis-port> \
91-
-p 3333:3333 \
92-
mcp-redis
93-
94-
# Run in cluster mode (only one node needed, others will be auto-discovered)
95-
docker run --rm -it \
96-
-e REDIS_CLUSTER_MODE=true \
97-
-e REDIS_HOST=<your-cluster-node-host> \
98-
-p 3333:3333 \
99-
mcp-redis
100-
101-
# Or specify one or more cluster nodes explicitly
102-
docker run --rm -it \
103-
-e REDIS_CLUSTER_MODE=true \
104-
-e REDIS_CLUSTER_NODES="<node1:port>" \
105-
-p 3333:3333 \
106-
mcp-redis
107-
```
10877

10978
## Integration with OpenAI Agents SDK
11079

@@ -155,8 +124,7 @@ You can configure Claude Desktop to use this MCP Server.
155124
"REDIS_PSW": "<your_redis_database_password>",
156125
"REDIS_SSL": True|False,
157126
"REDIS_CA_PATH": "<your_redis_ca_path>",
158-
"REDIS_CLUSTER_MODE": True|False,
159-
"REDIS_CLUSTER_NODES": "<single_node:port>" // Optional, uses REDIS_HOST if not specified
127+
"REDIS_CLUSTER_MODE": True|False
160128
}
161129
}
162130
}

src/common/config.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
# Add cluster mode flag
1010
REDIS_CLUSTER_MODE = os.getenv('REDIS_CLUSTER_MODE', 'false').lower() in ('true', '1', 't')
1111

12-
# Add cluster nodes configuration - only one node is required, others will be auto-discovered
13-
# If not specified, REDIS_HOST and REDIS_PORT will be used as the initial node
14-
REDIS_CLUSTER_NODES = os.getenv('REDIS_CLUSTER_NODES', '').split(',') if os.getenv('REDIS_CLUSTER_NODES') else []
15-
1612
REDIS_CFG = {"host": os.getenv('REDIS_HOST', '127.0.0.1'),
1713
"port": int(os.getenv('REDIS_PORT',6379)),
1814
"username": os.getenv('REDIS_USERNAME', None),

src/common/connection.py

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,24 @@
33
import redis
44
from redis import Redis
55
from redis.cluster import RedisCluster
6-
from typing import Optional, Union, List, Dict, Any, Tuple
7-
from common.config import REDIS_CFG, REDIS_CLUSTER_MODE, REDIS_CLUSTER_NODES
6+
from typing import Optional
7+
from common.config import REDIS_CFG, REDIS_CLUSTER_MODE
88

99
from common.config import generate_redis_uri
1010

1111

1212
class RedisConnectionManager:
13-
_instance: Optional[Union[Redis, RedisCluster]] = None
13+
_instance: Optional[Redis] = None
1414

1515
@classmethod
16-
def get_connection(cls, decode_responses=True) -> Union[Redis, RedisCluster]:
16+
def get_connection(cls, decode_responses=True) -> Redis:
1717
if cls._instance is None:
1818
try:
1919
if REDIS_CLUSTER_MODE:
20-
# In cluster mode, we can connect to one node and the client will discover the rest
21-
# If specific cluster nodes are provided, use the first one as the startup node
22-
if REDIS_CLUSTER_NODES and REDIS_CLUSTER_NODES[0]:
23-
node = REDIS_CLUSTER_NODES[0]
24-
if ':' in node:
25-
host, port = node.split(':')
26-
port = int(port)
27-
else:
28-
# Default to the configured port if only host is provided
29-
host = node
30-
port = REDIS_CFG["port"]
31-
else:
32-
# Use the primary node from REDIS_CFG as the startup node
33-
host = REDIS_CFG["host"]
34-
port = REDIS_CFG["port"]
35-
20+
# In cluster mode, connect to the host and port from REDIS_CFG
3621
cls._instance = RedisCluster(
37-
host=host,
38-
port=port,
22+
host=REDIS_CFG["host"],
23+
port=REDIS_CFG["port"],
3924
username=REDIS_CFG["username"],
4025
password=REDIS_CFG["password"],
4126
ssl=REDIS_CFG["ssl"],

0 commit comments

Comments
 (0)