Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

A convenience library for Redis integration in a Dropwizard service.

License

Notifications You must be signed in to change notification settings

netfonds/dwtools-redis

This branch is 2 commits ahead of, 162 commits behind dropwizard/dropwizard-redis:release/4.0.x.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

9e153c6 · Mar 10, 2022
Aug 2, 2021
Jun 3, 2019
Jun 4, 2019
Sep 15, 2021
Jun 3, 2019
Jun 3, 2019
Jun 4, 2019
Jun 3, 2019
Mar 10, 2022
Jun 3, 2019
Sep 2, 2021

Repository files navigation

Alte Projekt. Nicht mehr nutzen bitte. Neues Projekt ist dwtools-redis-client

dropwizard-redis

Provides easy integration for Dropwizard applications with Redis via the Lettuce library.

This bundle comes with out-of-the-box support for:

  • Configuration
  • Client lifecycle management
  • Client health checks
  • Dropwizard Metrics integration
  • Brave distributed tracing instrumentation integration for the Lettuce client.
  • Support for the Lettuce cluster client.
  • Support for the Lettuce sentinel client
  • Support the the Lettuce basic Redis client

For more information on Redis, take a look at the official documentation here: https://redis.io/documentation

For More information on the Redis client used (Lettuce), see: https://github.com/lettuce-io/lettuce-core

Dropwizard Version Support Matrix

dropwizard-redis Dropwizard v1.3.x Dropwizard v2.0.x
v1.3.x
v1.4.x
v1.5.x

Usage

Add dependency on library.

Maven:

<dependency>
  <groupId>io.dropwizard.modules</groupId>
  <artifactId>dropwizard-redis</artifactId>
  <version>1.5.1</version>
</dependency>

Gradle:

compile "io.dropwizard.modules:dropwizard-redis:1.5.1"

Basic Lettuce Client

In your Dropwizard Configuration class, configure a RedisClientFactory:

@Valid
@NotNull
@JsonProperty("redis")
private RedisClientFactory<String, String> redisClientFactory;

Then, in your Application class, you'll want to do something similar to the following:

private final RedisClientBundle<String, String, ExampleConfiguration> redis = new RedisClientBundle<String, String, ExampleConfiguration>() {
    @Override
    public RedisClientFactory<String, String> getRedisClientFactory(ExampleConfiguration configuration) {
        return configuration.getRedisClientFactory();
    }
};

@Override
public void initialize(Bootstrap<ExampleConfiguration> bootstrap) {
    bootstrap.addBundle(redis);
}

@Override
public void run(ExampleConfiguration config, Environment environment) {
    final StatefulRedisConnection<String, String> connection = redisCluster.getConnection();
    final PersonCache personCache = new PersonCache(connection); // PersonCache is an arbtirary example
    environment.jersey().register(new PersonResource(personCache));
}
redis:
  type: basic
  name: my-redis-use-case
  node:
    type: redis
    node: "127.0.0.1:6379"
    clientName: person-app
  redisCodec:
    type: string
  clientResources:
    type: default
    commandLatencyCollector:
      type: default
      enabled: false

Lettuce Cluster Client

In your Dropwizard Configuration class, configure a RedisClusterClientFactory:

@Valid
@NotNull
@JsonProperty("redis-cluster")
private RedisClusterClientFactory<String, String> redisClientFactory;

Then, in your Application class, you'll want to do something similar to the following:

private final RedisClusterClientBundle<String, String, ExampleConfiguration> redisCluster = new RedisClusterClientBundle<String, String, ExampleConfiguration>() {
    @Override
    public RedisClusterClientFactory<String, String> getRedisClusterClientFactory(ExampleConfiguration configuration) {
        return configuration.getRedisClusterClientFactory();
    }
};

@Override
public void initialize(Bootstrap<ExampleConfiguration> bootstrap) {
    bootstrap.addBundle(redisCluster);
}

@Override
public void run(ExampleConfiguration config, Environment environment) {
    final StatefulRedisClusterConnection<String, String> clusterConnection = redisCluster.getClusterConnection();
    final PersonCache personCache = new PersonCache(clusterConnection); // PersonCache is an arbtirary example
    environment.jersey().register(new PersonResource(personCache));
}

Configure your factory in your config.yml file:

redis-cluster:
  type: cluster
  name: my-redis-cluster-use-case
  nodes:
    - type: redis
      node: "127.0.0.1:6379"
      clientName: person-app
      password: hunter2
  redisCodec:
    type: string
  clientResources:
    type: default
    commandLatencyCollector:
      type: default
      enabled: false
  # TODO: add more configs than just the required basics

About

A convenience library for Redis integration in a Dropwizard service.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 99.5%
  • Shell 0.5%