ERR Can't execute '<cmd>': only (P|S)SUBSCRIBE / (P|S)UNSUBSCRIBE / PING / QUIT / RESET are allowed in this context: Command not allowed in subscribe context (subscribe 컨텍스트에서 허용되지 않는 명령)
Redis의미
연결이 Pub/Sub subscribe 모드에 들어간 후 이 모드에서 허용되지 않는 일반 명령(예: GET/SET)을 실행하려 했다. subscribe 모드의 연결은 제한된 명령 집합만 받는다. 이전 버전의 메시지는 "ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / PING / QUIT allowed in this context"였다.
원인
SUBSCRIBE/PSUBSCRIBE/SSUBSCRIBE로 subscribe 모드로 전환된 연결에서 데이터 명령을 보낸 경우다. RESP2 프로토콜에서 구독 중인 연결은 (P|S)SUBSCRIBE, (P|S)UNSUBSCRIBE, PING, QUIT, RESET만 허용한다. 하나의 연결을 pub/sub와 일반 작업에 공유하는 것이 전형적인 실수다.
해결 방법
Pub/Sub에는 전용 연결을 사용하고 일반 명령에는 다른 연결을 연다(대부분의 클라이언트 라이브러리는 자동으로 처리한다). subscribe 모드를 벗어나려면 UNSUBSCRIBE/PUNSUBSCRIBE를 보낸다. 이후 일반 명령이 동작한다. RESP3 프로토콜(HELLO 3)에서는 구독 중인 연결에서도 다른 명령이 허용되므로, 드라이버가 지원한다면 RESP3로 전환한다.
같은 데이터베이스의 다른 항목
- NOGROUP No such key or consumer groupNo such key or consumer group in stream
- NOTBUSY No scripts in execution right nowNo scripts in execution right now
- DENIED Redis is running in protected modeRedis is running in protected mode
- ERR SELECT is not allowed in cluster modeSELECT is not allowed in cluster mode
- ERR wrong number of arguments for commandWrong number of arguments for command
- ERR Background save already in progressBackground save already in progress
- ERR bit offset is not an integer or out of rangeBit offset is not an integer or out of range (비트 오프셋이 정수가 아니거나 범위를 벗어남)