Skip to content

Commit

Permalink
feat: Channel & Request support
Browse files Browse the repository at this point in the history
  • Loading branch information
CarmJos committed Jan 24, 2024
1 parent bec4d8c commit 1b21bc8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@

public class RedisChannel implements RedisMessageListener {

public static RedisChannel of(@NotNull String channel) {
return new RedisChannel(channel, null, null);
}

public static RedisChannel of(@NotNull String... channelPart) {
return new RedisChannel(String.join(".", channelPart), null, null);
}

public static RedisChannel of(@NotNull String channel, @NotNull Consumer<RedisMessage> handler) {
return builder(channel).handle(handler);
}
Expand Down Expand Up @@ -52,6 +60,10 @@ public RedisChannel(@NotNull String channel,
return this.channel;
}

public boolean shouldRegister() {
return this.handler != null;
}

@Override
public void handle(RedisMessage message) {
if (handler == null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,14 @@ public void registerChannels(@NotNull Class<?> channelClazz) {
}

protected void handleChannel(@NotNull Field field, @NotNull Class<?> source,
@NotNull Consumer<RedisChannel> channel) {
@NotNull Consumer<RedisChannel> consumer) {
try {
field.setAccessible(true);
Object obj = field.get(source);
if (!(obj instanceof RedisChannel)) return;
channel.accept((RedisChannel) obj);
RedisChannel channel = (RedisChannel) obj;
if (!channel.shouldRegister()) return;
consumer.accept(channel);
} catch (Exception ex) {
}
}
Expand Down

0 comments on commit 1b21bc8

Please sign in to comment.