Giter Site home page Giter Site logo

java-redis-client's Introduction

Build Status Coverage Status Released Version Apache-2.0 license

OpenTracing Redis Client Instrumentation

OpenTracing instrumentation for Redis Client

Requirements

  • Java 8

Installation

Jedis

Jedis 2

pom.xml

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-redis-jedis</artifactId>
    <version>VERSION</version>
</dependency>

Jedis 3

pom.xml

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-redis-jedis3</artifactId>
    <version>VERSION</version>
</dependency>

Lettuce

pom.xml

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-redis-lettuce</artifactId>
    <version>VERSION</version>
</dependency>

Redisson

pom.xml

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-redis-redisson</artifactId>
    <version>VERSION</version>
</dependency>

Spring Data Redis 1.x

pom.xml

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-redis-spring-data</artifactId>
    <version>VERSION</version>
</dependency>

Spring Data Redis 2.x

pom.xml

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-redis-spring-data2</artifactId>
    <version>VERSION</version>
</dependency>

Usage

// Instantiate tracer
Tracer tracer = ...

// Optionally register tracer with GlobalTracer
GlobalTracer.register(tracer);

// Create TracingConfiguration
TracingConfiguration tracingConfiguration = new TracingConfiguration.Builder(tracer).build(); 

Jedis

// Create Tracing Jedis
Jedis jedis = new TracingJedis(tracingConfiguration);

jedis.set("foo", "bar");
String value = jedis.get("foo");

Jedis Cluster

Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7379));

// Create Tracing Jedis Cluster
JedisCluster jc = new TracingJedisCluster(jedisClusterNodes, tracingConfiguration);
jc.set("foo", "bar");
String value = jc.get("foo");

Jedis Pool

// Configure the pool
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxIdle(10);
poolConfig.setTestOnBorrow(false);

// Create Tracing Jedis Pool
JedisPool pool = new TracingJedisPool(poolConfig, "127.0.0.1", 6379, tracingConfiguration);

try (Jedis jedis = pool.getResource()) {
    // jedis will be automatically closed and returned to the pool at the end of "try" block
    jedis.set("foo", "bar");
    String value = jedis.get("foo");
}

Jedis Sentinel Pool

// Create Tracing Jedis Sentinel Pool
JedisSentinelPool pool = new TracingJedisSentinelPool(tracingConfiguration, MASTER_NAME, sentinels, poolConfig);

try (Jedis jedis = pool.getResource()) {
// jedis will be automatically closed and returned to the pool at the end of "try" block
   jedis.set("foo", "bar"));
   String value = jedis.get("foo"));
}

Jedis Span Name

By default, span names are set to the operation performed by the Jedis object. To customize the span name, provide a Function to the TracingConfiguration object that alters the span name. If a function is not provided, the span name will remain the default. Refer to the RedisSpanNameProvider class for a function that prefixes the operation name.

TracingConfiguration tracingConfiguration = new TracingConfiguration.Builder(tracer)
    .withSpanNameProvider(RedisSpanNameProvider.PREFIX_OPERATION_NAME("redis."))
    .build(); 
//Create Tracing Jedis with custom span name
Jedis jedis = new TracingJedis(tracingConfiguration);
jedis.set("foo", "bar");
//Span name is now set to "redis.set"

Lettuce

// Create client
RedisClient client = RedisClient.create("redis://localhost");

// Decorate StatefulRedisConnection with TracingStatefulRedisConnection
StatefulRedisConnection<String, String> connection = 
    new TracingStatefulRedisConnection(client.connect(), tracingConfiguration);

// Get sync redis commands
RedisCommands<String, String> commands = connection.sync();

// Get async redis commands
RedisAsyncCommands<String, String> commandsAsync = connection.async();

Redisson

// Instantiate tracer
Tracer tracer = ...

// Optionally register tracer with GlobalTracer
GlobalTracer.register(tracer);

// Create Redisson config object
Config = ...

// Create Redisson instance
RedissonClient redissonClient = Redisson.create(config);

// Decorate RedissonClient with TracingRedissonClient
RedissonClient tracingRedissonClient =  new TracingRedissonClient(redissonClient, tracer);

// Get object you need using TracingRedissonClient
RMap<MyKey, MyValue> map = tracingRedissonClient.getMap("myMap");

Spring

// Create tracing connection factory bean
@Bean
public RedisConnectionFactory redisConnectionFactory(Tracer tracer) {
    MyRedisConnectionFactoryImplementation factory = ...
    return new TracingRedisConnectionFactory(factory, false, tacer);
    
}

Note: if you use Lettuce/Jedis you could achieve the same result using the Lettuce/Jedis support when configuring LettuceConnectionFactory/JedisConnectionFactory instead of using a wrapping TracingRedisConnectionFactory.

License

Apache 2.0 License.

java-redis-client's People

Contributors

malafeev avatar avnandu avatar chenziyu avatar ddcprg avatar elgris avatar natheee avatar pikbot avatar

Watchers

James Cloos avatar  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.