TIL - 3/4

헨도·2025년 3월 4일
0

TIL

목록 보기
13/21
post-thumbnail

Redis 명령어

  • SET 은 문자열 데이터를 등록할 때 사용하는 명령어
  • GET 은 문자열 데이터를 가져올 때 사용하는 명령어
SET user:email alex@example.com

GET user:email
> alex@example.com
  • 정수가 문자열로 저장된 경우
  • INCR, DECR 로 ++, -- 사용 가능
SET user:count1
GET user:count
> 1

INCR user:count
GET user:count
> 2

DECR user:count
> 1
  • MSET, MGET
  • 여러 개를 할당하거나 여러 개를 가져올 때
MSET user:name alex user:email alex@example.com
MGET user:name user:email
> alex alex@example.com
  • List - Linked List
  • Stack 이나 Queue 형태로 많이 사용되는 자료형
  • Push, Pop -> 왼쪽(L) 이냐? 오른쪽(R) 이냐?
LPUSH user:list alex
LPUSH user:list brad
RPUSH user:list chad
RPUSH user:list dave

> alex brad chad dave

LPOP user:list
RPOP user:list

> brad chad
  • LLEN
  • 리스트의 크기를 반환
LLEN user:list
> 2

LRANGE user:list 0 3
> alex brad
  • SET
  • (문자열의) 집합
  • 중복을 허용하지 않는다.
SADD user:java alex
SADD user:java brad
SADD user:java chad

-- 삭제
SADD user:java alex

SISMEMBER user: brad
> true
SISMEMBER user: dave
> true

SMEMBERS user:java
> alex brad chad

SCARD user:java
> 3

SADD user:python alex
SADD user:python dave

- 교집합
SINTER user:java user:python
> alex 

- 합집합
SUNION user:java user:python
> alex brad chad dave
  • Sorted Set
  • 정렬된 집합: 중복되지 않은 데이터 + 점수
  • AZADD key score valud 순서로 저장
ZADD user:ranks 10 alex
ZADD user:ranks 9 brad 11 chad
ZADD user:ranks 8 dave
ZADD user:ranks 9.5 eric

- score 올리기
ZINCRBY user:ranks 2 alex
> alex 12

- sorted set 내 위치한 순서
ZRANK user:ranks alex
> 3

ZRANK user:ranks eric
> 2

ZRANK user:ranks dave
> 1
profile
Junior Backend Developer

0개의 댓글

Powered by GraphCDN, the GraphQL CDN