parent
aed11b1a74
commit
de9cf95c59
3 changed files with 59 additions and 17 deletions
@ -0,0 +1,7 @@ |
||||
REDIS_VERSION=7.4-alpine |
||||
REDIS_PASSWORD="1qaz2wsxA@" |
||||
REDIS_MAXMEMORY=512mb |
||||
REDIS_EVICTION_POLICY=allkeys-lru |
||||
NETWORK_NAME=gk.internal |
||||
ENABLE_PERSIST=NO |
||||
EXPOSE_PORT=6379 |
||||
@ -1,21 +1,24 @@ |
||||
version: '3.3' |
||||
version: "3.9" |
||||
|
||||
services: |
||||
redis-service: |
||||
image: redis:latest |
||||
container_name: redis-service |
||||
restart: always |
||||
ports: |
||||
- "6379:6379" |
||||
volumes: |
||||
- ./:/root/redis |
||||
- ./redis.conf:/usr/local/etc/redis/redis.conf |
||||
redis: |
||||
image: redis:${REDIS_VERSION} |
||||
container_name: redis |
||||
restart: unless-stopped |
||||
entrypoint: ["/usr/local/bin/redis-entrypoint.sh"] |
||||
environment: |
||||
- REDIS_PASSWORD=A@1qaz2wsxA@ |
||||
- REDIS_PORT=6379 |
||||
- REDIS_DATABASES=16 |
||||
networks: |
||||
app-network: |
||||
name: gk.sunday.redis |
||||
driver: bridge |
||||
REDIS_PASSWORD: ${REDIS_PASSWORD} |
||||
REDIS_MAXMEMORY: ${REDIS_MAXMEMORY} |
||||
REDIS_EVICTION_POLICY: ${REDIS_EVICTION_POLICY} |
||||
ENABLE_PERSIST: ${ENABLE_PERSIST} |
||||
volumes: |
||||
- ./scripts/redis-entrypoint.sh:/usr/local/bin/redis-entrypoint.sh:ro |
||||
- ./data:/data |
||||
ports: |
||||
- "${EXPOSE_PORT}:6379" |
||||
networks: [default] |
||||
|
||||
networks: |
||||
default: |
||||
external: true |
||||
name: ${NETWORK_NAME} |
||||
|
||||
@ -0,0 +1,32 @@ |
||||
#!/usr/bin/env sh |
||||
set -eu |
||||
|
||||
# Đọc biến môi trường (có default hợp lý) |
||||
REDIS_PASSWORD="${REDIS_PASSWORD:?REDIS_PASSWORD is required}" |
||||
REDIS_MAXMEMORY="${REDIS_MAXMEMORY:-512mb}" |
||||
REDIS_EVICTION_POLICY="${REDIS_EVICTION_POLICY:-allkeys-lru}" |
||||
ENABLE_PERSIST="${ENABLE_PERSIST:-NO}" |
||||
|
||||
# Thư mục dữ liệu |
||||
mkdir -p /data |
||||
|
||||
CMD="redis-server \ |
||||
--requirepass '${REDIS_PASSWORD}' \ |
||||
--maxmemory ${REDIS_MAXMEMORY} \ |
||||
--maxmemory-policy ${REDIS_EVICTION_POLICY} \ |
||||
--bind 0.0.0.0 \ |
||||
--port 6379 \ |
||||
--loglevel notice \ |
||||
--dir /data \ |
||||
--protected-mode yes" |
||||
|
||||
if [ "${ENABLE_PERSIST}" = "YES" ]; then |
||||
# Snapshot nhẹ (RDB): 900s nếu >=1 key đổi; 300s nếu >=10 key |
||||
CMD="$CMD --save 900 1 --save 300 10 --appendonly no" |
||||
else |
||||
# Cache thuần: tắt persist để giảm I/O |
||||
CMD="$CMD --save '' --appendonly no" |
||||
fi |
||||
|
||||
echo "[entrypoint] Starting: $CMD" |
||||
exec sh -c "$CMD" |
||||
Loading…
Reference in new issue