Redis Stack

Redis Stack 이 나온지는 꽤 되었지만, 그 유용함과 확장의 성격에 비해 아직까지는 공유된 사례가 많지 않아 간략히 개요정도의 수준으로 소개해 봅니다. 개인적으로 Redis라는 기술 자체를 좋아하고,  지금 실무에도 너무나 유용하게 활용하고 있기 때문에 Redis Stack 또한 지금의 Redis가 제공하는 기능 이상의 흥미있고, 유용한 기능들을 제공해 줄 수 있다고 기대하고 있습니다.

 

개요

Redis의 확장서비스로 최신 데이타모델 지원과 처리 엔진(데이타 처리도구)을 제공, 기존 레디스 기능을 모두 포함하고 확장기능을 제공하기 위한 5개의 모듈을 탑재.

  • RedisSearch -Full-Text 검색 지원
  • RedisJSON - 쿼리가능한 JSON 문서 지원
  • RedisGraph - Cyper 쿼리언어를 사용한 그래프 데이타 모델
  • RedisTimeSeries - 시계열 데이타 처리 (수집 및 쿼리)
  • RedisBloom - 확률적 데이타 구조

현재 포함된 모듈 버전 정보

 

  • Redis Stack을 구성하는 각 모듈들이 제공하는 서비스의 범위로 봤을때는 왠만한 상용 RDBMS가 제공하는 데이타의 관리기능 및 분석 기능들은 모두 커버할 만한 수준으로 보입니다. 특히 쿼리가능한 JSON 문서를 지원하는 RedisJSON이나 Text Search가 가능한 RedisSearch, 시계열 데이타 처리에 사용되는 RedisTimeSeries기능은 실시간성 서비스를 필요로 하는 서비스에는 매우 유용할 것으로 생각됩니다.
  • 결국은 Redis Stack은 왠만한 웹서비스의 Data영역 전체를 커버하는 수준의 기능을 제공하는 서비스로 볼 수 있으며, 기존의 Redis를 사용하는 주 목적이었던 순수한 캐시용도 또는 간단한 Pub/Sub 역할을 하는 메세지 브로커 역할로 사용하기에는 오버스펙인 서비스로 보입니다.

  • 공식 사이트의 소개글을 보면 그 목적이 기존의 Redis와는 다름을 알 수 있습니다.
Redis Stack was created to allow developers to build real-time applications with a backend data platform that can reliably process requests in milliseconds or less. Redis Stack does this by taking the original Redis OSS as the core and enhancing it with modern data models, data processing tools, and continuing to fight complexity at every turn. Ultimately, the goal of Redis Stack is to build a real-time data platform that continues to fulfill the philosophy of Redis OSS: simplicity, performance, and reliability.
Redis Stack unifies and simplifies the developer experience of Redis by offering all the cutting-edge capabilities provided by the leading Redis modules. Redis Stack bundles the following capabilities into Redis: RedisJSONRediSearchRedisGraphRedisTimeSeries, and RedisBloom.
The overarching vision is to provide developers with a powerful platform for all real-time data use cases. As we continue to advance the capabilities of Redis beyond caching, Redis Stack is the place to start. Redis Stack delivers the core capabilities developers love about Redis and goes beyond to help you build modern applications where performance is paramount.

 

요약(번역)하자면 이런 내용입니다.

가장 중요한 비전은 개발자에게 모든 실시간 데이터 사용 사례를 위한 강력한 플랫폼을 제공하는 것입니다. 캐싱을 넘어 Redis의 기능을 지속적으로 발전시켜 나가고 있으며, 그 시작은 바로 Redis Stack입니다. Redis Stack은 개발자들이 좋아하는 Redis의 핵심 기능을 제공하며, 그 이상의 기능을 제공하여 성능이 가장 중요한 최신 애플리케이션을 구축할 수 있도록 지원합니다.

 

 

 

 

 

Redis Service

 Redis Stack은   Redis 엔진(Redis OSS) + 확장기능을 포함한 서비스로 결국 상용 플랫폼 서비스로 가기 위한 시작점이라고 볼 수 있겠습니다. 현재 Redis는 아래의 3가지 서비스로 구분해서 제공됩니다.
 
  • Redis OSS: the core engine for our software and services
  • Redis Stack: the starting point for developers who want all the power of Redis OSS and the the latest innovations Redis, Inc. has to offer all in an easy to use software package.
  • Redis Enterprise: our commercial product. Redis Enterprise maintains the simplicity and high performance of Redis, while adding many enterprise-grade capabilities including

 

Redis Enterprise의 경우, 상용서비스로 아래의 기능들과 더불어 클라우드 기반의 운영기능도 같이 제공합니다. 

  • Linear scaling to hundreds of millions of operations per second
  • Improved high availability with up to 99.999% uptime
  • Geo-replicated, active-active data distribution
  • Data tiering
  • Advanced security features
  • Several deployment options (managed cloud service, software packages, K8s)
  • 24/7 support
 
본 글은 Redis Stack소개에 대한 내용을 다루기 때문에 Redis Enterprise나 클라우드에 대한 상세한 정보는 아래의 링크를 참고하시기 바랍니다.
 
 

Redis Enterprise Cloud – Fully Managed Cloud Service | Redis

Redis Enterprise Cloud provides performance, operational simplicity, data management, and security in the cloud.

redis.com

 

Redis Client Library ( For Spring ORM )

Redis와 마찬가지로 여러 언어기반 Redis Client 모듈을 지원합니다.

 

Redis Stack clients

Client libraries supporting Redis Stack

redis.io

 

특히, Java의 경우 Spring Data기반 고수준(High-Level)의 API를 제공하고 있기 때문에 기존 Data Access 처리와 동일한 형태로 Repository와 Data Model 클래스를 구현할 수 있습니다.  

https://github.com/redis/redis-om-spring

 

GitHub - redis/redis-om-spring: Spring Data Redis extensions for better search, documents models, and more

Spring Data Redis extensions for better search, documents models, and more - GitHub - redis/redis-om-spring: Spring Data Redis extensions for better search, documents models, and more

github.com

 

특히 SpringBoot 기반 프로젝트일 경우, 간단한 어노테이션 설정만으로  Spring ORM기반의 추상화된 SDR(Spring Data Redis) API를 사용할 수 있습니다.

 

 

 

 

SpringBoot Main 클래스

@SpringBootApplication
@Configuration
@EnableRedisDocumentRepositories(basePackages = "com.redis.om.documents.*")
public class RedisOrmApplication {
	public static void main(String[] args) {
    	SpringApplication.run(RedisOrmApplication.class, args);
  	}
}

EnableRedisDocumentRepositories 어노테이션을 사용하여 @Document 어노테이션이 있는 Spring 모델 객체의 Scan이 가능해집니다. 그리고 CRUD 작업 및 사용자 정의 쿼리(모두 Spring 데이터 쿼리 인터페이스를 선언하여)에 사용할 수 있는RedisDocumentRepository 인터페이스를 구현하는 리포지토리 빈을 주입하여 비즈니스 로직을 구현하게 됩니다.

즉, @EnableRedisDocumentRepositories 어노테이션만 추가하면 Redis를 SDR기반으로 사용할 준비는 끝나게 됩니다.

 

Domain Model 클래스

package com.redis.om.documents.domain;

import java.util.HashSet;
import java.util.Set;

import org.springframework.data.annotation.Id;
import org.springframework.data.geo.Point;
import com.redis.om.spring.annotations.Document;
import com.redis.om.spring.annotations.Searchable;
import lombok.*;

@Data 
@NoArgsConstructor 
@RequiredArgsConstructor(staticName = "of") 
@AllArgsConstructor(access = AccessLevel.PROTECTED) 
@Document 
public class Company {
  @Id private String id;
  @Searchable private String name;
  @Indexed private Point location;
  @Indexed private Set<String> tags = new HashSet<>();
  @Indexed private Integer numberOfEmployees;
  @Indexed private Integer yearFounded;
  private String url;
  private boolean publiclyListed;

  // ...
}

Redis OM Spring은 클래스 수준의 @Document 어노테이션을 제공하여 해당 어노테이션이 적용된 클래스 객체를 RedisJSON구조의 객체로 매핑해줍니다. 즉 JSON기반의 구조로 데이타가 관리되며 RedisJSON이 제공하는 쿼리기반의 JSON 문서기반을 가능하게 해줍니다.

https://redis.io/docs/stack/json/

 

RedisJSON

JSON support for Redis

redis.io

 

@Searchable이나 @Indexed와 같은 어노테이션이 그런 기능을 가능하게 해줍니다.

https://redis.io/docs/stack/search/indexing_json/

 

Index and search JSON documents

How to index and search JSON documents

redis.io

 

@Id 어노테이션은 식별자(Identifier)를 생성하기 위한 어노테이션으로 RDMS의 테이블의 PK(Primary Key)와 유사한 역할을 합니다.

해당 어노테이션의 붙은 변수가 String 유형으로 정의되면 Redis OM Spring은 기존의 UUID 기본키 생성전략보다 키 생성속도가 빠르고 보기쉬운 ULID(Universally Unique Lexicographically Sortable Identifier)로 대체하여 생성합니다.

 

Repository 클래스 

package com.redis.om.documents.repositories;

import java.util.*;

import org.springframework.data.geo.Distance;
import org.springframework.data.geo.Point;
import org.springframework.data.repository.query.Param;

import com.redis.om.documents.domain.Company;
import com.redis.om.spring.annotations.Query;
import com.redis.om.spring.repository.RedisDocumentRepository;

public interface CompanyRepository extends RedisDocumentRepository<Company, String> {
  // find one by property
  Optional<Company> findOneByName(String name);

  // geospatial query
  Iterable<Company> findByLocationNear(Point point, Distance distance);

  // find by tag field, using JRediSearch "native" annotation
  @Query("@tags:{$tags}")
  Iterable<Company> findByTags(@Param("tags") Set<String> tags);

  // find by numeric property
  Iterable<Company> findByNumberOfEmployees(int noe);

  // find by numeric property range
  Iterable<Company> findByNumberOfEmployeesBetween(int noeGT, int noeLT);

  // starting with/ending with
  Iterable<Company> findByNameStartingWith(String prefix);
}

다른 Spring 데이터 리포지토리와 마찬가지로, Redis OM Spring 데이터 리포지토리의 Interface 생성방식도 거의 동일합니다.

Repository의 대상이 되는 Domain 클래스와 Domain 클래스의 ID 유형(@Id 어노테이션이 선언된 변수의 데이타유형)을 인수로 사용하는 RedisDocumentRepository를 상속받은 인터페이스를 생성하면 됩니다.

 

그리고 Query Name기반의 메소드를 정의하면 됩니다. 추가적으로 @Query나 SDR이 제공하는 어노테이션을 사용하여 커스텀하게 쿼리를 제너레이션 할 수도 있습니다.

 

참고로 RedisDocumentRepository 클래스는 Spring 데이터 클래스 PagingAndSortingRepository를 확장한 클래스입니다. 즉, Spring 의 Pageble 객체를 사용해서 페이징 처리가 가능하다는 의미입니다.


인터페이스에 쿼리 메서드를 선언합니다. 둘 다, CRUD 메서드를 노출하거나 런타임에 Redis OM Spring이 수행할 복잡한 쿼리에 대한 선언을 생성할 수 있습니다.

 

실제 리포지토리 프록시는 메서드 명으로 부터 Query를 도출할때 두 가지 방법을 사용해서 도출합니다.

  • 메서드 이름에서 쿼리를 직접 파생하는 방법 
  • @Query 또는 @Aggregation 어노테이션을 사용하여 수동으로 정의한 쿼리를 사용합니다.

 

글을 적다 보니 Redis Stack 내용보다 Redis OM Spring에 대한 내용이 더 많이 나온 것 같습니다.

다음편(#2)에는 Redis Stack 설치 및 기본적인 환경구성에 대해서 다루어 보도록 하겠습니다.

 

그리고  기회가 된다면  Redis OM Spring에 대해서는 따로 주제를 만들어 추후에 기회가 되면 좀 더 깊게 다루어 보도록 하겠습니다.

 

 

 

 

 

참고 문서

Reis Stack 공식사이트 - https://redis.io/docs/stack/

 

Redis Stack

Extends Redis with modern data models and processing engines

redis.io

Redis OM Spring - https://redis.io/docs/stack/get-started/tutorials/stack-spring/

 

Redis OM Spring

Learn how to build with Redis Stack and Spring

redis.io



  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기