pangu-user-platform/scripts/clear-h5-captcha-cache.sh

37 lines
1.3 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# 清理 H5 图形验证码、短信验证码、限流与黑名单等 Redis 缓存
# 使用场景:验证码异常、发送过于频繁、需要重置限流时,在生产服务器执行
#
# 用法(在生产服务器 192.168.71.56 上执行):
# cd /opt/pangu-user-platform && bash scripts/clear-h5-captcha-cache.sh
# REDIS_PASSWORD=你的密码 bash scripts/clear-h5-captcha-cache.sh
# 若后端使用 application-test.yml密码请以该文件为准。
set -e
REDIS_HOST="${REDIS_HOST:-127.0.0.1}"
REDIS_PORT="${REDIS_PORT:-6379}"
REDIS_PASSWORD="${REDIS_PASSWORD:-}"
if ! command -v redis-cli &>/dev/null; then
echo "未找到 redis-cli请安装 Redis 客户端或在已安装的机器上执行"
exit 1
fi
CLI=(redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT")
if [[ -n "$REDIS_PASSWORD" ]]; then
CLI+=(-a "$REDIS_PASSWORD")
fi
echo "清理 H5 验证码与短信相关缓存 (host=$REDIS_HOST port=$REDIS_PORT) ..."
for pattern in "global:captcha_codes:*" "h5:sms:*"; do
count=0
while IFS= read -r key; do
[[ -z "$key" ]] && continue
"${CLI[@]}" DEL "$key" &>/dev/null && ((count++)) || true
done < <("${CLI[@]}" --no-auth-warning KEYS "$pattern" 2>/dev/null || true)
echo " 已删除 pattern=$pattern 数量=$count"
done
echo "清理完成。"