<aside> 💡 Tip. 특정 줄만 실행하는 방법 In 콘솔창
해당 줄을 드래그하고 Command + Enter
</aside>
# Java의 Map과 동일
# Map<String, String> map = new HashMap<>();
# map.put("greeting", "Hello Redis")
# String
# SET key value
SET string "string value"
GET string
# 정수형 문자열의 경우 증감할 수 있다.
SET intstring 1
INCR intstring
DECR intstring
GET intstring
# 복수의 Key - Value 설정
MSET name minkyu age 100 married false
MGET name age married
# List
# LinkedList란 추상 자료형태로 저장이 되며tack 또는 Queue로 활용
# 앞쪽에 저장
LPUSH fruitList apple
# 뒤쪽에 저장
RPUSH fruitList banana
LPUSH fruitList coconut
RPUSH fruitList peer
# 뒤쪽에서 삭제
RPOP fruitList
# 앞쪽에서 삭제
LPOP fruitList
# 전체 길이
LLEN fruitList
# 잘라서 출력
LRANGE fruitList 0 3
# 전체 출력
LRANGE fruitList 0 -1
# 0부터 100000
LRANGE fruitList 0 1000000
# nothing
LRANGE fruitList 4 3
# Sets
# 집합 값 넣기
SADD students alex
SADD students brad
SADD students chad
# 집합 전체 가져오기
SMEMBERS students
# 집합 내, 해당 요소 있는지 확인
SISMEMBER students alex
SISMEMBER students dave
# 삭제
SREM students alex
# 전체 개수 가져오기
SCARD students
# Hash
# Map<String, Map<String, String>>
# : Redis 자체가 이미 Map이므로 Hash를 쓰면 저렇게 저장이 된다고 할 수 있다.
# HSET Map이름 Field Value Field Value ...
HSET alexInfo name alex age 20
HSET alexInfo major CSE
# 이미 있는 필드를 수정 가능
HSET alexInfo name "alex rodriguez"
# 필드로 Value 조회
# : 문자열이 아니므로 받고자 하는 필드명을 적어준다.
HGET alexInfo name
HGET alexInfo age
# value 한꺼번에 가져오기
HMGET alexInfo name age major
# 전체 Hash를 다 가져오는 방법
HGETALL alexInfo
# 전체 필드 가져오기
HKEYS alexInfo
# 전체 value 가져오기
HVALS alexInfo
# 전체 길이 가져오기
HLEN alexInfo
# Sorted Set
# : 순서가 있는 Set, Java의 LinkedSet과 비슷하다.
# Sorted Set이름 Score 이름
ZADD grades 10 alex
ZADD grades 9 brad 11 chadd
ZADD grades 8 dave
# 점수를 올려줄 수 있다.
ZINCRBY grades 1 dave
# 몇등인지 알 수 있다.
ZRANK grades alex
# 일부 조회
ZRANGE grades 0 1
# 전체 조회
ZRANGE grades 0 -1
ZREVRANK grades alex
ZREVRANGE grades 0 -1
# EXPIRE
# : EXPIRE 명령을 사용하면 특정 Key의 만료시간을 초단위로 지정할 수 있다.
SET expirekey "to be expired"
EXPIRE expirekey 5
# 언제 만료가 되는지 알려준다.(Redis Cloud 7버전부터)
EXPIRETIME expirekey
-- 필드 단위로 EXPIRE 하는 것은 불가능하다.
EXPIRE fruitList 10
# DEL
DEL grades
DEL students
# FLUSHDB
# : 전체 DB 삭제
FLUSHDB
<aside> 📍 테킷 백엔드 스쿨 자바 8기
</aside>