Skip to content

Commit

Permalink
update create redis-cluster shell script
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth More authored and Siddharth More committed Nov 28, 2023
1 parent ce20a53 commit 1023b66
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions inabox/create-redis-cluster.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
#!/bin/bash
set -e

REDIS_CLUSTER_ID="test-eigenda-redis-cluster"
REDIS_PORT="6379"
AWS_REGION="us-east-1"
# Specify the Redis Docker image version
REDIS_IMAGE="redis:latest"

# Check if the Redis cluster already exists
function redis_cluster_exists() {
aws elasticache describe-cache-clusters --region $AWS_REGION | grep -q $REDIS_CLUSTER_ID
return $?
}
# Specify the Redis container name
REDIS_CONTAINER_NAME="test-eigenda-redis-cluster"

# Start Redis service using LocalStack
function create_redis_cluster() {
aws elasticache create-cache-cluster \
--cache-cluster-id $REDIS_CLUSTER_ID \
--engine redis \
--cache-node-type cache.t2.micro \
--num-cache-nodes 1 \
--port $REDIS_PORT \
--region $AWS_REGION
}
# Specify the port to be used for Redis
REDIS_PORT="6379"

# Check if Redis cluster exists and create it if it does not
if redis_cluster_exists; then
echo "Redis cluster $REDIS_CLUSTER_ID already exists."
# Check if the Redis container is already running
if [ $(docker ps -q -f name="$REDIS_CONTAINER_NAME") ]; then
echo "Redis container ($REDIS_CONTAINER_NAME) is already running."
else
echo "Creating Redis cluster $REDIS_CLUSTER_ID."
create_redis_cluster
# Check if the Redis container exists but is stopped
if [ $(docker ps -aq -f name="$REDIS_CONTAINER_NAME") ]; then
# Start the existing Redis container
docker start "$REDIS_CONTAINER_NAME"
else
# Run a new Redis container
docker run --name "$REDIS_CONTAINER_NAME" -p "$REDIS_PORT:$REDIS_PORT" -d "$REDIS_IMAGE"
fi
echo "Redis server started and available on port $REDIS_PORT"
fi

0 comments on commit 1023b66

Please sign in to comment.