Contents
Overview
Jedis is a Java client for Redis.
This CDI portable extension provides support for injecting Jedis clients in your Helidon MicroProfile applications.
Maven Coordinates
To enable Jedis add the following dependency to your project’s pom.xml (see Managing Dependencies).
<dependency>
<groupId>io.helidon.integrations.cdi</groupId>
<artifactId>helidon-integrations-cdi-jedis</artifactId>
</dependency>Usage
After you have added the above dependency to your project you can inject a Jedis client in your application. The following examples show how to create and inject a Jedis pool named orders in your application code.
@Inject
@Named("orders")
private JedisPool ordersPool; private final JedisPool ordersPool;
@Inject
public YourConstructor(@Named("orders") JedisPool pool) {
super();
this.ordersPool = pool;
}Helidon implements this injection point by creating a JedisPool object in the application scope.
Configuration
You can configure the object using MicroProfile config. For example, the Jedis pool created above can be configured as follows:
redis.clients.jedis.JedisPool.orders.port=6379The Jedis client can be configured using the following properties.
Property names that start with redis.clients.jedis.JedisPoolConfig.instanceName. are parsed, and the remaining portion of each name is treated as a Java Bean property of JedisPoolConfig. Because the JedisPoolConfig class inherits from Apache commons-pool’s GenericObjectPoolConfig class and from Apache commons-pool’s BaseObjectPoolConfig class, those writable Java Bean properties are available as well.
Accordingly, the JedisPoolConfig Java Bean properties that can be set are as follows, where instanceName should be replaced with the actual name used in application code:
redis.clients.jedis.JedisPoolConfig.instanceName.blockWhenExhausted |
redis.clients.jedis.JedisPoolConfig.instanceName.evictionPolicyClassName |
redis.clients.jedis.JedisPoolConfig.instanceName.fairness |
redis.clients.jedis.JedisPoolConfig.instanceName.jmxEnabled |
redis.clients.jedis.JedisPoolConfig.instanceName.jmxNameBase |
redis.clients.jedis.JedisPoolConfig.instanceName.jmxNamePrefix |
redis.clients.jedis.JedisPoolConfig.instanceName.lifo |
redis.clients.jedis.JedisPoolConfig.instanceName.maxIdle |
redis.clients.jedis.JedisPoolConfig.instanceName.maxTotal |
redis.clients.jedis.JedisPoolConfig.instanceName.maxWaitMillis |
redis.clients.jedis.JedisPoolConfig.instanceName.minEvictableTimeMillis |
redis.clients.jedis.JedisPoolConfig.instanceName.minIdle |
redis.clients.jedis.JedisPoolConfig.instanceName.numTestsPerEvictionRun |
redis.clients.jedis.JedisPoolConfig.instanceName.softMinEvictableIdleTimeMillis |
redis.clients.jedis.JedisPoolConfig.instanceName.testOnBorrow |
redis.clients.jedis.JedisPoolConfig.instanceName.testOnCreate |
redis.clients.jedis.JedisPoolConfig.instanceName.testOnReturn |
redis.clients.jedis.JedisPoolConfig.instanceName.testWhileIdle |
redis.clients.jedis.JedisPoolConfig.instanceName.timeBetweenEvictionRunsMillis |
Any documentation for these properties that exists may be found in the javadocs for the JedisPoolConfig, GenericObjectPoolConfig and BaseObjectPoolConfig classes.
Property names that start with redis.clients.jedis.JedisPool.instanceName. are parsed, and the remaining portion of each name is treated as a Java Bean property of JedisPool, or as a primitive value accepted by its constructor. Because the JedisPool class inherits from the Pool class, its writable Java Bean properties are available as well.
Accordingly, the JedisPool properties that can be set are as follows, where instanceName should be replaced with the actual named used in application code:
redis.clients.jedis.JedisPool.instanceName.clientName |
redis.clients.jedis.JedisPool.instanceName.connectionTimeout |
redis.clients.jedis.JedisPool.instanceName.database |
redis.clients.jedis.JedisPool.instanceName.host |
redis.clients.jedis.JedisPool.instanceName.password |
redis.clients.jedis.JedisPool.instanceName.port |
redis.clients.jedis.JedisPool.instanceName.socketTimeout |
redis.clients.jedis.JedisPool.instanceName.ssl |
Any documentation for these properties that exists may be found in the javadocs for the JedisPool and Pool classes.
Injection without a @Named annotation is also possible:
@Inject
private JedisPool ordersPool;In this case, the properties for JedisPoolConfig and JedisPool that can be set will start with redis.clients.jedis.JedisPoolConfig.default and redis.clients.jedis.JedisPool.default respectively.