Git Product home page Git Product logo

dropwizard-redis's Introduction

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

dropwizard-redis's People

Contributors

charlesg-branch avatar dependabot-preview[bot] avatar dependabot[bot] avatar joschi avatar pstackle avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.