Creating client is simple as:
// Create Lettuce Pooled Client
val poolConfig = GenericObjectPoolConfig<StatefulRedisConnection<String, String>>()
val client = LettucePooled(poolConfig) { RedisClient.create("redis://localhost:6379").connect() }
Or if you need Pub/Sub support:
// Create Lettuce Pooled Pub/Sub Client
val poolConfig = GenericObjectPoolConfig<StatefulRedisConnection<String, String>>()
val pubSubClient = LettucePubSubPooled(poolConfig) { RedisClient.create("redis://localhost:6379").connectPubSub() }
Creating lock:
// Create lock
val lock = LockFactory.createSimplifiedMutex(client)
lock.lock("myResource", Duration.ofSeconds(1))
// do something
lock.unlock("myResource")
// Create Lettuce Pooled Client
var client = RedisClient.create("redis://localhost:6379");
var poolConfig = new GenericObjectPoolConfig<StatefulRedisConnection<String, String>>();
var lettucePooled = new LettucePooled<>(poolConfig, client::connect);
Or if you need Pub/Sub support:
// Create Lettuce Pooled Pub/Sub Client
var client = RedisClient.create("redis://localhost:6379");
var poolConfig = new GenericObjectPoolConfig<StatefulRedisPubSubConnection<String, String>>();
var lettucePubSubPooled = new LettucePubSubPooled<>(poolConfig, client::connectPubSub);
Creating lock:
// Create lock
var lock = LockFactory.createSimplifiedMutex(lettucePooled, Duration.ofSeconds(1), 3);
lock.lock("myResource", Duration.ofSeconds(1));
// do something
lock.unlock("myResource");
This module provides Lettuce pooled client that simplify connection management. Instead of creating new connection each time or manage connection pool manually you can use this module.
Available options:
- LettucePooled - Lettuce pooled client.
- LettucePubSubPooled - Lettuce pooled client with Pub/Sub support.
Both clients support synchronous, asynchronous and reactive APIs.