RM   (remove key)

Redis Developer Course Redis Technical Support Redis Enterprise Server

패턴(pattern)으로 키(key) 삭제

사용법은 rm key* 입니다. 비동기로 삭제합니다.
이 명령은 Enterprise 서버에서 사용 가능합니다. (use-sql yes/no 관계없이 사용 가능)
👉 명령 개발 의도: 'll' 또는 'ls' 명령과 같이 키 패턴으로 키를 삭제할 수 있게 만들었습니다.

  • rm * -> 모든 키를 삭제합니다. flushdb를 실행한 것과 같습니다.
  • rm key* -> key로 시작하는 모든 키를 삭제합니다.
  • rm * string -> string 키를 모두 삭제합니다.
  • rm key* string -> key로 시작하는 string 키를 삭제합니다.
  • 'll' 명령과 조합해서 사용: ll 명령으로 삭제할 키를 확인하고 삭제하면 유용합니다.

Key에 glob-style pattern을 사용할 수 있습니다.

  • * : 모든 문자 매치(match): h*llo -> hllo, heeeello, etc
  • ? : 1개 문자 매치(match): h?llo -> hallo, hello, hxllo, etc
  • [alphabet] : 대괄호 안에 있는 문자 매치(match): h[ae]llo -> hallo, hello
  • [^e] : 대괄호 안에 있는 문자 제외하고 매치(match): h[^e]llo -> hallo, hbllo, ... 그러나 hello는 제외됨.
  • [a-c] : 대괄호 안에 있는 문자 범위로 매치(match): h[a-c]llo -> hallo, hbllo, hcllo
  • \ : 위에 사용한 특수문자(*?[^])를 그대로 사용하려면 앞에 \를 붙이세요.

Example

명령>rm key*
결과>1
명령>rm * string
결과>9
명령>rm mylist* list
결과>2

명령문

RM key_pattern [type]

  • type은 string/list/set/zset/hash/stream 지정 가능합니다.
  • 이 명령은 Enterprise version 8.0.0 부터 사용할 수 있다.
  • 논리적 처리 소요시간은 O(N)입니다. N은 키 개수이다.
  • 이 명령은 'keys' 명령과 같이 DB를 'full scan'해서 서버 성능에 영향을 미치므로 redis.conf ll-max 파라미터로 제한을 두었습니다.
    키 개수가 ll-max 이상일 경우 다음과 같은 메시지가 나오고 조회되지 않습니다.
    "If the number of keys is greater than ll-max, the 'll' command cannot be executed.
    To execute, modify the 'CONFIG SET ll-max number' command.
    The number of keys can be checked with the 'dbsize' command, and the 'll-max' value can be checked with the 'CONFIG GET ll-max' command."
    'CONFIG SET ll-max number' 명령으로 값을 수정할 수 있습니다.
    이 명령은 개발/테스트 서버에서 사용하시고, 운영 서버에서는 꼭 필요한 경우가 아니면 자제해 주시기 바랍니다.
관련 명령 SCAN, DBSIZE

<< LS RM SCAN >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.