
io.zeebe.redis.exporter.UniversalRedisConnection Maven / Gradle / Ivy
package io.zeebe.redis.exporter;
import io.lettuce.core.RedisConnectionStateListener;
import io.lettuce.core.api.StatefulConnection;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.async.RedisStreamAsyncCommands;
import io.lettuce.core.api.sync.RedisStreamCommands;
import io.lettuce.core.api.sync.RedisStringCommands;
import io.lettuce.core.cluster.api.StatefulRedisClusterConnection;
public class UniversalRedisConnection {
private StatefulRedisConnection redisConnection = null;
private StatefulRedisClusterConnection redisClusterConnection = null;
private StatefulConnection theConnection;
public UniversalRedisConnection(StatefulConnection redisConnection) {
this.theConnection = redisConnection;
if (redisConnection instanceof StatefulRedisConnection) {
this.redisConnection = (StatefulRedisConnection) redisConnection;
} else {
this.redisClusterConnection = (StatefulRedisClusterConnection) redisConnection;
}
}
public void addListener(RedisConnectionStateListener listener) {
theConnection.addListener(listener);
}
public RedisStreamCommands syncStreamCommands() {
if (redisConnection != null) return redisConnection.sync();
return redisClusterConnection.sync();
}
public RedisStringCommands syncStringCommands() {
if (redisConnection != null) return redisConnection.sync();
return redisClusterConnection.sync();
}
public RedisStreamAsyncCommands asyncStreamCommands() {
if (redisConnection != null) return redisConnection.async();
return redisClusterConnection.async();
}
public void setAutoFlushCommands(boolean autoFlush) {
theConnection.setAutoFlushCommands(autoFlush);
}
public void flushCommands() {
theConnection.flushCommands();
}
public void syncDel(K... ks) {
if (redisConnection != null) {
redisConnection.sync().del(ks);
} else {
redisClusterConnection.sync().del(ks);
}
}
public void close() {
theConnection.close();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy