|  | 
| 22 | 22 | import java.util.List; | 
| 23 | 23 | import java.util.Map; | 
| 24 | 24 | 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; | 
| 26 | 31 | import java.util.concurrent.atomic.AtomicBoolean; | 
| 27 | 32 | import java.util.concurrent.atomic.AtomicInteger; | 
| 28 | 33 | 
 | 
| 29 | 34 | import reactor.core.publisher.Mono; | 
| 30 | 35 | 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; | 
| 32 | 42 | import io.lettuce.core.protocol.ConnectionWatchdog; | 
| 33 | 43 | import io.lettuce.core.protocol.RedisHandshakeHandler; | 
| 34 | 44 | import io.lettuce.core.resource.ClientResources; | 
| 35 | 45 | import io.lettuce.core.resource.DefaultClientResources; | 
| 36 | 46 | import io.netty.bootstrap.Bootstrap; | 
| 37 | 47 | 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; | 
| 39 | 54 | import io.netty.channel.group.ChannelGroup; | 
| 40 | 55 | import io.netty.channel.group.DefaultChannelGroup; | 
| 41 | 56 | import io.netty.channel.nio.NioEventLoopGroup; | 
| @@ -79,6 +94,8 @@ public abstract class AbstractRedisClient { | 
| 79 | 94 | 
 | 
| 80 | 95 |     private final ClientResources clientResources; | 
| 81 | 96 | 
 | 
|  | 97 | +    private final List<CommandListener> commandListeners = new ArrayList<>(); | 
|  | 98 | + | 
| 82 | 99 |     private final Map<Class<? extends EventLoopGroup>, EventLoopGroup> eventLoopGroups = new ConcurrentHashMap<>(2); | 
| 83 | 100 | 
 | 
| 84 | 101 |     private final boolean sharedResources; | 
| @@ -208,6 +225,33 @@ public void removeListener(RedisConnectionStateListener listener) { | 
| 208 | 225 |         connectionEvents.removeListener(listener); | 
| 209 | 226 |     } | 
| 210 | 227 | 
 | 
|  | 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 | + | 
| 211 | 255 |     /** | 
| 212 | 256 |      * Populate connection builder with necessary resources. | 
| 213 | 257 |      * | 
|  | 
0 commit comments