Initial redis skill implementation

This commit is contained in:
Azat
2026-02-02 23:44:22 +01:00
commit 007c151a1c
3 changed files with 259 additions and 0 deletions

64
scripts/run.sh Normal file
View File

@@ -0,0 +1,64 @@
#!/bin/bash
set -e
REDIS_PORT="${REDIS_PORT:-6379}"
REDIS_PASSWORD="${REDIS_PASSWORD:-}"
REDIS_MAXMEMORY="${REDIS_MAXMEMORY:-100mb}"
REDIS_MAXMEMORY_POLICY="${REDIS_MAXMEMORY_POLICY:-allkeys-lru}"
REDIS_DATA_DIR="${REDIS_DATA_DIR:-/data/redis}"
REDIS_APPENDONLY="${REDIS_APPENDONLY:-yes}"
REDIS_SAVE="${REDIS_SAVE:-900 1 300 10 60 10000}"
# Build REDIS_URL
if [ -n "$REDIS_PASSWORD" ]; then
export REDIS_URL="redis://:${REDIS_PASSWORD}@localhost:${REDIS_PORT}"
else
export REDIS_URL="redis://localhost:${REDIS_PORT}"
fi
echo "REDIS_URL=$REDIS_URL"
# Write to shared env file for other skills
mkdir -p /run/vibestack
echo "REDIS_URL=$REDIS_URL" > /run/vibestack/redis.env
# Build command arguments
args=()
args+=("--port" "$REDIS_PORT")
args+=("--dir" "$REDIS_DATA_DIR")
args+=("--maxmemory" "$REDIS_MAXMEMORY")
args+=("--maxmemory-policy" "$REDIS_MAXMEMORY_POLICY")
args+=("--appendonly" "$REDIS_APPENDONLY")
# Add authentication if set
if [ -n "$REDIS_PASSWORD" ]; then
args+=("--requirepass" "$REDIS_PASSWORD")
fi
# Configure RDB persistence
# REDIS_SAVE format: "seconds changes [seconds changes ...]"
if [ -n "$REDIS_SAVE" ]; then
# Parse save intervals (e.g., "900 1 300 10 60 10000")
read -ra save_args <<< "$REDIS_SAVE"
for ((i=0; i<${#save_args[@]}; i+=2)); do
if [ $((i+1)) -lt ${#save_args[@]} ]; then
args+=("--save" "${save_args[i]} ${save_args[i+1]}")
fi
done
fi
# Bind to all interfaces
args+=("--bind" "0.0.0.0")
# Enable protected mode only if no password
if [ -z "$REDIS_PASSWORD" ]; then
args+=("--protected-mode" "yes")
else
args+=("--protected-mode" "no")
fi
echo "Starting Redis on port $REDIS_PORT..."
echo "Max memory: $REDIS_MAXMEMORY"
echo "Eviction policy: $REDIS_MAXMEMORY_POLICY"
echo "Persistence: AOF=$REDIS_APPENDONLY"
exec redis-server "${args[@]}"