Here is an example of a CDI producer for Redis using the Jedis (Java) client for Redis. Check out the project README to get this up and running…. Below is a quick summary
Use of CDI Qualifier
Two types of CDI producers have been demonstrated
- non-qualified: no additional qualifiers for simply obtaining a standalone
Jedis
connection - qualified: uses a custom CDI
Qualifier
(@FromJedisPool
) to get the connection from theJedis
pool
Scoping
@RequestScoped
for pooled producer: theJedis
connection is returned to the pool after the method invocation is complete@DependentScoped
for basic producer: the lifetime of theJedis
connection object depends on which component has injected it
Common stuff
- In both the cases, the producer (CDI) bean itself is
@ApplicationScoped
and the producers have been scoped differently - An equivalent
@Disposes
method has been provided to perform clean up (i.e. close the connection or return it to the pool)
Further reading
Cheers!