Skip to content

Commit 634e3d7

Browse files
committed
Polishing #1382
Move events from models.events to event.command. Move CommandListener configuration from ClientResources to AbstractRedisClient.addListener. Consider changed writer chain in RedisChannelHandler.setTimeout. Add tests for standalone and Redis Cluster operations. Remove generics from command events to simplify interaction and listener implementation. Replace generic ExecutionException with ExceptionFactory usage. Original pull request: #1424.
1 parent 78f40fb commit 634e3d7

22 files changed

+598
-413
lines changed

src/main/asciidoc/new-features.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
== What's new in Lettuce 6.1
66

77
* Kotlin Coroutines support for `SCAN`/`HSCAN`/`SSCAN`/`ZSCAN` through `ScanFlow`.
8+
* Command Listener API through `RedisClient.addListener(CommandListener)`.
89

910
[[new-features.6-0-0]]
10-
1111
== What's new in Lettuce 6.0
1212

1313
* Support for RESP3 usage with Redis 6 along with RESP2/RESP3 handshake and protocol version discovery.

src/main/java/io/lettuce/core/AbstractRedisClient.java

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,35 @@
2222
import java.util.List;
2323
import java.util.Map;
2424
import java.util.Set;
25-
import java.util.concurrent.*;
25+
import java.util.concurrent.CancellationException;
26+
import java.util.concurrent.CompletableFuture;
27+
import java.util.concurrent.CompletionStage;
28+
import java.util.concurrent.ConcurrentHashMap;
29+
import java.util.concurrent.TimeUnit;
30+
import java.util.concurrent.TimeoutException;
2631
import java.util.concurrent.atomic.AtomicBoolean;
2732
import java.util.concurrent.atomic.AtomicInteger;
2833

2934
import reactor.core.publisher.Mono;
3035
import io.lettuce.core.Transports.NativeTransports;
31-
import io.lettuce.core.internal.*;
36+
import io.lettuce.core.event.command.CommandListener;
37+
import io.lettuce.core.internal.AsyncCloseable;
38+
import io.lettuce.core.internal.Exceptions;
39+
import io.lettuce.core.internal.Futures;
40+
import io.lettuce.core.internal.LettuceAssert;
41+
import io.lettuce.core.internal.LettuceStrings;
3242
import io.lettuce.core.protocol.ConnectionWatchdog;
3343
import io.lettuce.core.protocol.RedisHandshakeHandler;
3444
import io.lettuce.core.resource.ClientResources;
3545
import io.lettuce.core.resource.DefaultClientResources;
3646
import io.netty.bootstrap.Bootstrap;
3747
import io.netty.buffer.ByteBufAllocator;
38-
import io.netty.channel.*;
48+
import io.netty.channel.Channel;
49+
import io.netty.channel.ChannelFuture;
50+
import io.netty.channel.ChannelInitializer;
51+
import io.netty.channel.ChannelOption;
52+
import io.netty.channel.ChannelPipeline;
53+
import io.netty.channel.EventLoopGroup;
3954
import io.netty.channel.group.ChannelGroup;
4055
import io.netty.channel.group.DefaultChannelGroup;
4156
import io.netty.channel.nio.NioEventLoopGroup;
@@ -79,6 +94,8 @@ public abstract class AbstractRedisClient {
7994

8095
private final ClientResources clientResources;
8196

97+
private final List<CommandListener> commandListeners = new ArrayList<>();
98+
8299
private final Map<Class<? extends EventLoopGroup>, EventLoopGroup> eventLoopGroups = new ConcurrentHashMap<>(2);
83100

84101
private final boolean sharedResources;
@@ -208,6 +225,33 @@ public void removeListener(RedisConnectionStateListener listener) {
208225
connectionEvents.removeListener(listener);
209226
}
210227

228+
/**
229+
* Add a listener for Redis Command events. The listener is notified on each command start/success/failure.
230+
*
231+
* @param listener must not be {@code null}
232+
* @since 6.1
233+
*/
234+
public void addListener(CommandListener listener) {
235+
LettuceAssert.notNull(listener, "CommandListener must not be null");
236+
commandListeners.add(listener);
237+
}
238+
239+
/**
240+
* Removes a listener.
241+
*
242+
* @param listener must not be {@code null}
243+
* @since 6.1
244+
*/
245+
public void removeListener(CommandListener listener) {
246+
247+
LettuceAssert.notNull(listener, "CommandListener must not be null");
248+
commandListeners.remove(listener);
249+
}
250+
251+
protected List<CommandListener> getCommandListeners() {
252+
return commandListeners;
253+
}
254+
211255
/**
212256
* Populate connection builder with necessary resources.
213257
*

src/main/java/io/lettuce/core/CommandListenerMulticaster.java

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)