본문 바로가기

DB & 클라우드/Redis

[Redis] 01 Redis(레디스) 알아보기

계기

아쉽게도 레디스를 직접 사용할 일은 없어서 자세히 알아볼 기회가 없었는데, 이번 프로젝트에서 랭킹을 구현하면서 사용하게 되어 알아보고자 한다.

Redis란?

https://redis.io/

 

Redis

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker

redis.io

공식 홈에서는 

The Open source, in-memory data store used by millions of developers as database, cache, streaming engine, and message broker.
(해석)
수백만 명의 개발자가 데이터베이스, 캐시, 스트리밍 엔진 및 메시지 브로커로 사용하는 오픈 소스 인 메모리 데이터 저장소입니다.
여기서 in-memory란?
디스크가 아닌 주 메모리에 모든 데이터를 보유함.
디스크 io가 발생하지 않아 자료 접근이 훨씬 빠른 것이 가장 큰 장점.
데이터 양의 빠른 증가로 데이터베이스 응답 속도가 떨어지는 문제를 해결할 수 있는 대안임.
단점: 휘발성. db 서버 전원이 갑자기 꺼진다면 안의 자료들이 즉시 삭제됨. 그래서 보통 임시 데이터에 주로 쓰임.(Redis는 이를 대비하여 동작 중 로그나 스냅샷을 통해 디스크에 데이터를 저장함)
쓰임: microsecond 단위의 응답시간을 요구하는 애플리케이션, 실시간 분석, 세션 저장, 게임 순위 선정 등 트래픽이 비교적 몰리는 상황에 적절함.

이렇게 써있는데.. 핵심 능력?을 먼저 봐야겠다.

핵심 능력

1. In-memory data structures (인 메모리 데이터 구조)

 "데이터 구조 서버"로 잘 알려져 있으며 해시, 목록, 집합, 정렬된 집합, 스트림 등을 지원한다.

2. Programmability(프로그래밍 능력)

서버 측 스크립팅에 Lua를 사용하고, 서버 측 저장 프로시져에는 Redis 함수들을 사용한다.

3. Extensibility(확장 가능성)

Redis에 C, C++, Rust를 사용하여 커스텀 익스텐션들을 빌드할 수 있는 module API가 있다.

4. Persistence(영속성)

빠른 액세스를 위해 데이터셋을 메모리에 보관하지만 모든 데이터를 유지할 수 있다. 재부팅 및 시스템 장애를 극복하기 위해 영구 스토리지에 기록한다.

5. Clustering(클러스터링)

해시 기반 샤딩을 통한 수평 확장성, 클러스터 확장 시 자동 재파티셔닝을 통해 수백만 개의 노드로 확장 가능하다.

6. High availability(고가용성)

독립 실행형 및 클러스터형 배포 환경 모두에 자동 페일오버 기능을 갖춘 복제(?)

Use cases

실시간 데이터 저장소 : Redis의 다용도 인메모리 데이터 구조로 짧은 대기 시간과 높은 처리량을 필요로 하는 실시간 애플리케이션을 위한 데이터 인프라를 구축할 수 있다.

캐싱 & 세션 스토리지 : Redis의 속도는 데이터베이스 ㅝ리, 복잡한 계산, API 호출 및 세션 상태를 캐싱하는 데 이상적이다.

스트리밍 & 메시징 : 스트리밍 데이터 유형을 사용하면 높은 속도의 데이터 수집, 메시징, 이벤트 소싱 및 알림이 가능합니다.

 

https://redis.io/docs/

 

Documentation

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker

redis.io

공식 문서에 따르면


Redis is an open source (BSD licensed), in-memory data structure store used as a database, cache, message broker, and streaming engine. Redis provides data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes, and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions, and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.
You can run atomic operations on these types, like appending to a string; incrementing the value in a hash; pushing an element to a list; computing set intersection, union and difference; or getting the member with highest ranking in a sorted set.
To achieve top performance, Redis works with an in-memory dataset. Depending on your use case, Redis can persist your data either by periodically dumping the dataset to disk or by appending each command to a disk-based log. You can also disable persistence if you just need a feature-rich, networked, in-memory cache.
Redis supports asynchronous replication, with fast non-blocking synchronization and auto-reconnection with partial resynchronization on net split.
Redis는 데이터베이스, 캐시, 메시지 브로커 및 스트리밍 엔지으로 사용되는 오픈소스 인 메모리 데이터 구조 저장소이다.
제공하는 데이터 구조: 문자열, 해시, 목록, 집합, 범위 쿼리, 비트맵, 하이퍼로그, 지리공간 인덱스, 스트림으로 정렬된 집합들 포함
복제, Lus 스크립트, LRU 제거, 트랜젝션 및 다양한 수준의 온디스크 지속성을 내장하고 있으며 Redis Sentinel과 Redis Cluster를 통한 자동 분할을 통해 고가용성을 제공한다.