[1] Redis Command
Redis 명령어 : Redis 서버에서 일부 작업을 수행하는 데 사용된다.
Redis 서버에서 명령을 실행하기 위해서 Redis Client가 필요하다.
- Redis Client는 이전에 설치한 Redis 패키지에서 사용할 수 있다.
redis 패키지의 기본 구분
&redis-cli
redis client를 시작하는 방법 ( 로컬 서버 연결 )
- redis client를 실행 후, 로컬 서버에서 Ping 명령어를 통해 서버가 실행중인지 확인한다.
$redis-cli 
redis 127.0.0.1:6379> PING
PONG
redis 원격 서버에서 명령 실행 구문
- Redis 원격 서버의 명령어를 실행하기 위해서는 동일한 클라이언트 redis-cli로 서버에 연결해야 한다.
- 아래 에제는 호스트 127.0.0.1 : 6379에서 실행되고 비밀번호가 mypassword인 원격 서버에 연결하는 방법이다.
///// $redis-cli -h host -p porrt -a password /////
$redis-cli -h 127.0.-0.1 -p 6379 -a "mypassword"
redis 127.0.0.1:6379>
redis 127.0.0.1:6379> PING
PONG
[2] Redis Command of DataType
[1] Redis Key
Redis Key 명령들은 Redis에서 키를 관리하는 데 사용된다. ( 단일 key-value )
기본 구문
redis 127.0.0.1:6379> COMMAND KEY_NAME
redis 127.0.0.1:6379> SET tutorialspoint redis 
OK
redis 127.0.0.1:6379> DEL tutorialspoint
(integer) 1
Key 명령어
| sr.no | Command & Description | 
| 1 | DEL key This command deletes the key, if it exists | 
| 2 | DUMP key This command returns a serialized version of the value stored at the specified key. | 
| 3 | EXISTS key This command checks whether the key exists or not. | 
| 4 | EXPIRE key secondsSets the expiry of the key after the specified time. ( 키 만료 설정 ) | 
| 5 | EXPIREAT key timestamp Sets the expiry of the key after the specified time. Here time is in Unix timestamp format. | 
| 6 | PEXPIRE key milliseconds Set the expiry of key in milliseconds. ( 키 만료 설정 : 밀리초 ) | 
| 7 | PEXPIREAT key milliseconds-timestamp Sets the expiry of the key in Unix timestamp specified as milliseconds. | 
| 8 | KEYS pattern Finds all keys matching the specified pattern. ( 패턴과 일치하는 모든 키 탐색 ) | 
| 9 | MOVE key db Moves a key to another database. ( 키를 다른 DB로 이동 ) | 
| 10 | PERSIST key Removes the expiration from the key. | 
| 11 | PTTL key Gets the remaining time in keys expiry in milliseconds. | 
| 12 | TTL key Gets the remaining time in keys expiry. | 
| 13 | RANDOMKEY Returns a random key from Redis. ( 랜덤 키 반환 ) | 
| 14 | RENAME key newkey Changes the key name. ( 키 이름 교체 ) | 
| 15 | RENAMENX key newkey Renames the key, if a new key doesn't exist. ( 키 이름 교체, 중복 확인 ) | 
| 16 | TYPE key Returns the data type of the value stored in the key. ( 키의 값의 데이터 유형 ) | 
[2] Redis String
Redis String은 Redis에서 문자열 값을 관리하는 데 사용된다.
기본 구문
redis 127.0.0.1:6379> COMMAND KEY_VALUE
redis 127.0.0.1:6379> SET tutorialpoint redis 
OK
redis 127.0.0.1:6379> GET tutorialpoint 
"redis"
String 명령어
| 1 (*) | SET key value This command sets the value at the specified key. | 
| 2 (*) | GET key Gets the value of a key. | 
| 3 | GETRANGE key start end Gets a substring of the string stored at a key. | 
| 4 | GETSET key value Sets the string value of a key and return its old value. ( 값 설정, 이전 값 반환 ) | 
| 5 | GETBIT key offset Returns the bit value at the offset in the string value stored at the key. | 
| 6 | MGET key1 [key2..] Gets the values of all the given keys ( 주어진 모든 키의 값을 가져옴 ) | 
| 7 | SETBIT key offset value Sets or clears the bit at the offset in the string value stored at the key | 
| 8 | SETEX key seconds value Sets the value with the expiry of a key ( 키 만료값 설정 ) | 
| 9 | SETNX key value Sets the value of a key, only if the key does not exist ( 키 존재하지 않을 때만 값 설정 ) | 
| 10 | SETRANGE key offset value Overwrites the part of a string at the key starting at the specified offset ( 오프셋 부터 일부 덮어씀 ) | 
| 11 | STRLEN key Gets the length of the value stored in a key ( 값의 길이를 리턴 ) | 
| 12 | MSET key value [key value ...] Sets multiple keys to multiple values ( 여러 키-값 선언 ) | 
| 13 | MSETNX key value [key value ...] Sets multiple keys to multiple values, only if none of the keys exist | 
| 14 | PSETEX key milliseconds value Sets the value and expiration in milliseconds of a key ( 키 만료를 밀리초 단위로 ) | 
| 15 | INCR key Increments the integer value of a key by one ( 키의 정수값을 1씩 증가 ) | 
| 16 | INCRBY key increment Increments the integer value of a key by the given amount ( increment만큼 키 정수값 증가 ) | 
| 17 | INCRBYFLOAT key increment Increments the float value of a key by the given amount ( increment만큼 키의 부동 소수점 값 증가 ) | 
| 18 | DECR key Decrements the integer value of a key by one ( 키의 정수값을 1씩 감소 ) | 
| 19 | DECRBY key decrement Decrements the integer value of a key by the given number | 
| 20 | APPEND key value Appends a value to a key ( 키에 값 추가 "기존값" + "value" ) | 
[3] Redis Hash
Redis Hash는 문자열 필드와 문자열 값 간의 MAP으로 객체를 나타낼 수 있는 데이터 타입이다.
Redis에서 모든 해시는 최대 40억 개 이상의 필드-값 쌍을 저장할 수 있다.
기본 구문 : 이름 설명 좋아요 방문자를 설정함
redis 127.0.0.1:6379> HMSET tutorialspoint name "redis tutorial" 
description "redis basic commands for caching" likes 20 visitors 23000 
OK 
redis 127.0.0.1:6379> HGETALL tutorialspoint  
1) "name" 
2) "redis tutorial" 
3) "description" 
4) "redis basic commands for caching" 
5) "likes" 
6) "20" 
7) "visitors" 
8) "23000"
Hash 명령어
| Sr.No | Command & Description | 
| 1 | HDEL key field2 [field2] Deletes one or more hash fields. ( 해시 필드 삭제 ) | 
| 2 | HEXISTS key field Determines whether a hash field exists or not. ( 필드 존재 여부 ) | 
| 3 | HGET key field Gets the value of a hash field stored at the specified key. ( 키에 저장된 해시 필드 값 가져옴) | 
| 4 | HGETALL key Gets all the fields and values stored in a hash at the specified key ( 모든 필드 값 가져옴 ) | 
| 5 | HINCRBY key field increment Increments the integer value of a hash field by the given number ( incre만큼 정수 값 증가 ) | 
| 6 | HINCRBYFLOAT key field increment Increments the float value of a hash field by the given amount ( incre만큼 부동 소수점 값 증가 ) | 
| 7 | HKEYS key Gets all the fields in a hash ( 해시의 모든 필드를 가져옴 ) | 
| 8 | HLEN key Gets the number of fields in a hash ( 해시의 필드 수를 가져옴 ) | 
| 9 | HMGET key field1 [field2] Gets the values of all the given hash fields ( 주어진 모든 해시 필드 값을 가져옴 ) | 
| 10 | HMSET key field1 value1 [field2 value2 ] Sets multiple hash fields to multiple values ( 주어진 모든 해시 필드 값 설정 ) | 
| 11 | HSET key field value Sets the string value of a hash field ( 필드의 값 설정 ) | 
| 12 | HSETNX key field value Sets the value of a hash field, only if the field does not exist ( 필드 존재하지 않는 경우만 값 설정 ) | 
| 13 | HVALS key Gets all the values in a hash ( 해시의 모든 값을 가져옴 ) | 
| 14 | HSCAN key cursor [MATCH pattern] [COUNT count] Incrementally iterates hash fields and associated values ( 해시 필드 및 관련 값을 점진적으로 반복 ) | 
[4] Redis List
Redis List는 단순히 삽입 순서로 정렬된 문자열 목록이다.
요소의 추가는 List의 Head부분 or Tail 부분에서 추가할 수 있다.
목록의 최대 길이는 2 32 - 1개 요소(4294967295, 목록당 40억 개 이상의 요소)
기본 구문
redis 127.0.0.1:6379> LPUSH tutorials redis 
(integer) 1 
redis 127.0.0.1:6379> LPUSH tutorials mongodb 
(integer) 2 
redis 127.0.0.1:6379> LPUSH tutorials mysql 
(integer) 3 
redis 127.0.0.1:6379> LRANGE tutorials 0 10  
1) "mysql" 
2) "mongodb" 
3) "redis"
List 명령어
L : Head 부분 , R : Tail 부분
| Sr.No | Command & Description | 
| 1 | BLPOP key1 [key2 ] timeout Removes and gets the first element in a list, or blocks until one is available [ list의 첫번째 요소 제거 ] | 
| 2 | BRPOP key1 [key2 ] timeout Removes and gets the last element in a list, or blocks until one is available [ list의 마지막 요소 제거 ] | 
| 3 | BRPOPLPUSH source destination timeout Pops a value from a list, pushes it to another list and returns it; or blocks until one is available [ list에서 값을 꺼내 다른 목록으로 push하고 반환 ] | 
| 4 | LINDEX key index Gets an element from a list by its index [ index로 list의 요소에 접근함 ] | 
| 5 | LINSERT key BEFORE|AFTER pivot value Inserts an element before or after another element in a list [ list의 pivot 앞/뒤로 값을 추가함 ] | 
| 6 | LLEN key Gets the length of a list [ 리스트의 길이 반환 ] | 
| 7 | LPOP key Removes and gets the first element in a list [ 리스트의 첫번째 요소 제거 ] | 
| 8 | LPUSH key value1 [value2] Prepends one or multiple values to a list [ list 에 하나 이상의 값을 추가함 ] | 
| 9 | LPUSHX key value Prepends a value to a list, only if the list exists [ list가 존재하는 경우, list head에 값을 추가 ] | 
| 10 | LRANGE key start stop Gets a range of elements from a list [ list의 요소 범위를 가져옴 ] | 
| 11 | LREM key count value Removes elements from a list [ list에서 요소를 제거함 ] | 
| 12 | LSET key index value Sets the value of an element in a list by its index [ index를 통해 요소 값 설정 ] | 
| 13 | LTRIM key start stop Trims a list to the specified range [ list를 지정된 범위로 자름 ] | 
| 14 | RPOP key Removes and gets the last element in a list [ list의 마지막 요소를 제거하고 반환받음 ] | 
| 15 | RPOPLPUSH source destination Removes the last element in a list, appends it to another list and returns it [ list의 마지막 요소를 제거하고 다른 목록에 추가하고 반환받음 ] | 
| 16 | RPUSH key value1 [value2 Appends one or multiple values to a list [ list에 하나 이상의 값을 추가함 ] | 
| 17 | RPUSHX key value Appends a value to a list, only if the list exists [ list가 있는 경우에만 값을 추가함 ] | 
[5] Redis Set
[6] Redis SortedSet
'Tech Stack > Database ( TSDB, NOSQL, SQL )' 카테고리의 다른 글
| InfluxDB CQ ( continuous query ) (0) | 2022.08.12 | 
|---|---|
| Telegraf (0) | 2022.07.15 | 
| InfluxDB (1) | 2022.06.27 | 
| Redis 기초 (0) | 2022.04.04 | 
| 정규화 (0) | 2022.03.10 | 
 
                    
                   
                    
                  