Skip to content

An abstraction for the Jedis and Lettuce Redis Search module which allows JPA-like annotations to be used for basic CRUD operations

License

Notifications You must be signed in to change notification settings

rnbWarden/jredisearch-spring-boot-starter

Repository files navigation

JRediSearch Spring Boot Starter

(jredisearch-spring-boot-starter)

Purpose

This starter provides a Spring Boot starter to handle setup and configuration of JRediSearch clients and indexes. It includes functionality for creating RediSearchClients for annotated RediSearchEntities. The RediSearchClient is an abstraction layer that provides CRUD operations on top of the client-specific RediSearch implementation.

Configuration

Leverages the existing Spring Data Redis properties. Additionally, a base package should be specified to indicate which classes to scan. Example:

redis.search.base-package=com.foo.repository

Supports both Jedis & Lettuce

You will need to include the dependency from JCenter

compile 'com.rnbwarden.redisearch:jredisearch-spring-boot-starter:11.X.Y'

Additionally the following client-specific RediSearch dependencies are required.

For JEDIS

    compile 'org.springframework.data:spring-data-redis:2.4.0'
    compile 'redis.clients:jedis:3.3.0'
    compile 'com.redislabs:jredisearch:2.0.0'

for LETTUCE

    compile 'org.springframework.data:spring-data-redis:2.4.0'
    compile 'com.redislabs:lettusearch:2.4.4'
    compile ('com.redislabs:spring-redisearch:2.4.4') {
        exclude group: 'com.redislabs', module: 'lettusearch'
    }

Annotate your beans as follows:

@RediSearchEntity(name = "${your-index-name-here}")

Annotate your fields on RediSearch beans as follows:

@RediSearchField(name = "{your-index-column-name-here}") //TEXT type by default
/** or */
@RediSearchField(name= "{your-index-column-name-here}", type = RediSearchFieldType.TAG)

example

@RediSearchField(name= CartType.SHOPPING, type = RediSearchFieldType.TAG)
private CartType type;

At runtime a RedisearchClient (of RedisearchClient<{specific-entity-type}>) will be created for your entity and the corresponding index created at application startup. This RediSearchClient bean will be injected into the Spring BeanFactory as follows:

"{simpleName}" + RediSearchClient

…​where simpleName is the lower camel case version of the Entity class simple name. == Serialization

The starter uses Jackson to serialize the RediSearch entities. By default it’s assumed the application has a com.fasterxml.jackson.databind.ObjectMapper configured and uses this ObjectMapper. If one is not supplied by the application the starter will create one. If you wish to supply a specific bean for Redis serialization (ex: use a different ObjectMapper for the application and for redis serialization) you can supply one specifically for RediSearch by create a bean named rediSearchObjectMapper.

About

An abstraction for the Jedis and Lettuce Redis Search module which allows JPA-like annotations to be used for basic CRUD operations

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages