Redis command

From 탱이의 잡동사니
Revision as of 09:04, 14 June 2017 by Pchero (talk | contribs)
Jump to navigation Jump to search

Overview

Redis command 내용 정리

DEL

지정된 키를 삭제한다.

127.0.0.1:6379> help DEL

  DEL key [key ...]
  summary: Delete a key
  since: 1.0.0
  group: generic

GET

지정된 키 값을 가져온다.

127.0.0.1:6379> help GET

  GET key
  summary: Get the value of a key
  since: 1.0.0
  group: string

SET 명령어 사용시, 만약 Key 에 이미 다른 값이 설정되어 있다면 타입에 상관없이 덮어쓰기가 된다. Any previous time to live associated with the key is discarded on successful SET operation.

Example

redis>  GET mykey
"Hello"

HGETALL

해쉬에 저장된 모든 필드의 내용을 가져온다.

  HGETALL key
  summary: Get all the fields and values in a hash
  since: 2.0.0
  group: hash

INFO

Redis 서버 설정 정보를 확인할 수 있다.

127.0.0.1:6379> help INFO

  INFO [section]
  summary: Get information and statistics about the server
  since: 1.0.0
  group: server

Example

> INFO
redis_version:2.4.18
redis_git_sha1:00000000
redis_git_dirty:0
arch_bits:64
...
127.0.0.1:6379> INFO CPU
# CPU
used_cpu_sys:0.60
used_cpu_user:2.74
used_cpu_sys_children:0.00
used_cpu_user_children:0.00

MONITOR

REDIS 에서 수행되는 명령어를 실시간으로 모니터링한다.

127.0.0.1:6379> help monitor

  MONITOR -
  summary: Listen for all requests received by the server in real time
  since: 1.0.0
  group: server

Example

redis 127.0.0.1:6379> monitor
OK
1465549016.028126 "monitor"

1465549888.174607 (db 10) "SELECT" "10"
1465549888.193430 (db 10) "KEYS" "accounts:127.0.0.1-user1:accountinformation"
1465549888.193779 (db 10) "HGETALL" "accounts:127.0.0.1-user1:accountinformation"
1465549888.224193 (db 10) "KEYS" "voicemail:127.0.0.1-user1:message*"
1465549892.531991 (db 10) "SELECT" "10"
1465549892.547614 (db 10) "KEYS" "accounts:127.0.0.1-user1:accountinformation"
1465549892.547991 (db 10) "HGETALL" "accounts:127.0.0.1-user1:accountinformation"
1465549892.578356 (db 10) "KEYS" "voicemail:127.0.0.1-user1:message*"
1465549892.590838 (db 10) "KEYS" "accounts:127.0.0.1-user1:accountinformation"
1465549892.591206 (db 10) "HGETALL" "accounts:127.0.0.1-user1:accountinformation"
1465549892.621536 (db 10) "KEYS" "voicemail:127.0.0.1-user1:message*"
1465549892.622748 (db 10) "HMSET" "mailboxchanges:127.0.0.1:user1" "mboxname" "user1" "old" "0" "new" "0"
...

RENAME

Key 를 업데이트/변경 한다.

127.0.0.1:6379> help RENAME

  RENAME key newkey
  summary: Rename a key
  since: 1.0.0
  group: generic

SADD

set 에 member 를 추가한다. 지정된 key에 member 들을 Sets 타입으로 add 한다.

127.0.0.1:6379> help SADD

  SADD key member [member ...]
  summary: Add one or more members to a set
  since: 1.0.0
  group: set

Example

redis 127.0.0.1:6379[1000]> SADD queues "a684cf64-685c-484c-8157-a53db7e7cef7"
(integer) 1
redis 127.0.0.1:6379[1000]> SADD queues "f9c7e9cf-8415-42d7-a6cd-82fa95410b33"
(integer) 1
redis 127.0.0.1:6379[1000]> SADD queues "e5631cf8-6898-486a-beac-36087c917b8a"
(integer) 1

redis 127.0.0.1:6379[1000]> SMEMBERS queues
1) "a684cf64-685c-484c-8157-a53db7e7cef7"
2) "e5631cf8-6898-486a-beac-36087c917b8a"
3) "f9c7e9cf-8415-42d7-a6cd-82fa95410b33"

SCAN

SET

지정한 키에 값을 지정한다.

127.0.0.1:6379> help SET

  SET key value [EX seconds] [PX milliseconds] [NX|XX]
  summary: Set the string value of a key
  since: 1.0.0
  group: string

Example

redis>  SET mykey "Hello"
OK

SINTER

여러개의 결과 데이터를 조합하여 공통적으로 속해있는 결과만을 리턴한다.

key1 = {a,b,c,d}
key2 = {c}
key3 = {a,c,e}
SINTER key1 key2 key3 = {c}

비어있는(empty) 혹은 존재하지 않는 키와의 SINTER 는 항상 empty list 를 반환한다.

Example

redis>  SADD key1 "a"
(integer) 1
redis>  SADD key1 "b"
(integer) 1
redis>  SADD key1 "c"
(integer) 1
redis>  SADD key2 "c"
(integer) 1
redis>  SADD key2 "d"
(integer) 1
redis>  SADD key2 "e"
(integer) 1
redis>  SINTER key1 key2
1) "c"

SMEMBERS

지정된 set 에 저장된 모든 member 를 보여준다.

127.0.0.1:6379> help smembers

  SMEMBERS key
  summary: Get all the members in a set
  since: 1.0.0
  group: set

Example

redis 127.0.0.1:6379[1000]> SADD queues "a684cf64-685c-484c-8157-a53db7e7cef7"
(integer) 1
redis 127.0.0.1:6379[1000]> SADD queues "f9c7e9cf-8415-42d7-a6cd-82fa95410b33"
(integer) 1
redis 127.0.0.1:6379[1000]> SADD queues "e5631cf8-6898-486a-beac-36087c917b8a"
(integer) 1

redis 127.0.0.1:6379[1000]> SMEMBERS queues
1) "a684cf64-685c-484c-8157-a53db7e7cef7"
2) "e5631cf8-6898-486a-beac-36087c917b8a"
3) "f9c7e9cf-8415-42d7-a6cd-82fa95410b33"

SLAVEOF

Slave 설정을 변경한다.

127.0.0.1:6379> help SLAVEOF

  SLAVEOF host port
  summary: Make the server a slave of another instance, or promote it as master
  since: 1.0.0
  group: server

slave 설정시, 모든 데이터는 master 와 동기화 된다. 즉, 동기화 하기 전에 slave 쪽에 중복되는 데이터가 있다면, master 쪽의 데이터로 덮어써지게 된다.

Example

$ redis-cli -n 10 slaveof 192.168.250.10 6379

SUNION

여러개의 결과 데이터를 조합하여 중복된 데이터를 제외한 결과를 리턴한다.

127.0.0.1:6379> help SUNION

  SUNION key [key ...]
  summary: Add multiple sets
  since: 1.0.0
  group: set

Example

key1 = {a,b,c,d}
key2 = {c}
key3 = {a,c,e}
SUNION key1 key2 key3 = {a,b,c,d,e}

See also

Reference

<references />