티스토리 뷰

오늘 redis scan 후 delete하는 bash shell 실행 중에 아래와 같은 오류를 봤습니다.

CROSSSLOT Keys in request don't hash to the same slot

scan 후에 여러 키를 삭제하려고 했더니 같은 slot에 있지 않다고 하네요

bash shell을 수정해서 key 각각 요청하도록 변경했습니다.

#!/bin/bash

if [ $# -ne 3 ]
then
  echo "Delete keys from Redis matching a pattern using SCAN & DEL"
  echo "Usage: $0 <host> <port> <pattern>"
  exit 1
fi

cursor=-1
keys=""

while [ $cursor -ne 0 ]; do
  if [ $cursor -eq -1 ]
  then
    cursor=0
  fi

  reply=`redis-cli -c -h $1 -p $2 SCAN $cursor MATCH $3`
  cursor=`expr "$reply" : '\([0-9]*[0-9 ]\)'`
  keys=${reply#[0-9]*[[:space:]]}
  for key in $keys
  do
    redis-cli -c -h $1 -p $2 DEL $key
  done
done

 

다른 방법도 있으니 아래 aws 문서 참고해서 처리하시면 될 것 같네요

 

참고

https://repost.aws/ko/knowledge-center/elasticache-crossslot-keys-error-redis

반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함