-
Notifications
You must be signed in to change notification settings - Fork 973
CDI Support
CDI support for Lettuce is available for RedisClient
and RedisClusterClient
. You need to provide a RedisURI
in order to get Lettuce injected.
Implement a simple producer (either field producer or producer method) of RedisURI
:
@Produces
public RedisURI redisURI() {
return RedisURI.Builder.redis("localhost").build();
}
Lettuce also supports qualified RedisURI
's:
@Produces
@PersonDB
public RedisURI redisURI() {
return RedisURI.Builder.redis("localhost").build();
}
After declaring your RedisURI
's you can start using Lettuce in your classes:
public class InjectedClient {
@Inject
private RedisClient redisClient;
@Inject
private RedisClusterClient redisClusterClient;
@Inject
@PersonDB
private RedisClient redisClient;
private RedisConnection<String, String> connection;
@PostConstruct
public void postConstruct() {
connection = redisClient.connect();
}
public void pingRedis() {
connection.ping();
}
@PreDestroy
public void preDestroy() {
if (connection != null) {
connection.close();
}
}
}
By default, you just drop Lettuce on your classpath and declare at least one RedisURI
bean. That’s all.
The CDI extension registers one bean pair (RedisClient
and RedisClusterClient
) per discovered RedisURI
. This means,
if you do not declare any RedisURI
producers, the CDI extension won’t be activated at all. This way you can use
Lettuce in CDI-capable containers without even activating the CDI extension.
All produced beans (RedisClient
and RedisClusterClient
) remain active as long as your application is running since the beans are @ApplicationScoped
.
Lettuce documentation was moved to https://redis.github.io/lettuce/overview/
Intro
Getting started
- Getting started
- Redis URI and connection details
- Basic usage
- Asynchronous API
- Reactive API
- Publish/Subscribe
- Transactions/Multi
- Scripting and Functions
- Redis Command Interfaces
- FAQ
HA and Sharding
Advanced usage
- Configuring Client resources
- Client Options
- Dynamic Command Interfaces
- SSL Connections
- Native Transports
- Unix Domain Sockets
- Streaming API
- Events
- Command Latency Metrics
- Tracing
- Stateful Connections
- Pipelining/Flushing
- Connection Pooling
- Graal Native Image
- Custom commands
Integration and Extension
Internals