-
Notifications
You must be signed in to change notification settings - Fork 945
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
.
This wiki and the README document contains a lot of information, please take your time and read these instructions carefully.
If you run into any trouble, you may start with getting started.
We provide detailed changes for each Lettuce release.
Be sure to read the CONTRIBUTING guidelines before reporting a new Lettuce issue or open a pull request.
If you have any questions about the Lettuce usage or want to share some information with the community, please go to one of the following places:
- GitHub Discussions
- for chatting
More resources:
- Javadoc
- Build status: Travis CI
- All versions: Maven Central
- Snapshots: Sonatype OSS Repository
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