jhutchison commented on a change in pull request #6604:
URL: https://github.com/apache/geode/pull/6604#discussion_r650120643
##########
File path:
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/publishAndSubscribe/Subscriptions.java
##########
@@ -73,28 +73,52 @@ boolean exists(Object channelOrPattern, Client client) {
.collect(Collectors.toList());
}
- public List<byte[]> findChannelNames() {
+ public List<Object> findChannelNames() {
ObjectOpenCustomHashSet<byte[]> hashSet =
new ObjectOpenCustomHashSet<>(ByteArrays.HASH_STRATEGY);
- findChannels()
+ findChannelSubscriptions()
.forEach(channel -> hashSet.add(channel.getSubscriptionName()));
return new ArrayList<>(hashSet);
}
- public List<byte[]> findChannelNames(byte[] pattern) {
+ public List<Object> findChannelNames(byte[] pattern) {
GlobPattern globPattern = new GlobPattern(Coder.bytesToString(pattern));
return findChannelNames()
.stream()
- .filter(name -> globPattern.matches(Coder.bytesToString(name)))
+ .filter(name -> globPattern.matches(Coder.bytesToString((byte[])
name)))
.collect(Collectors.toList());
}
- private Stream<ChannelSubscription> findChannels() {
+ public List<Object> findNumberOfSubscribersForChannel(List<byte[]> names) {
+
+ List<Object> result = new ArrayList<>();
+
+ names.forEach(name -> {
+
+ List<Subscription> subscriptions =
+ findSubscriptions(name)
+ .stream()
+ .filter(subscription -> subscription instanceof
ChannelSubscription)
+ .collect(Collectors.toList());
+
+ if (subscriptions.isEmpty()) {
+ result.add(name);
+ result.add(0L);
+ } else {
+ result.add(name);
+ result.add((long) subscriptions.size());
+ }
Review comment:
thank you- yes, simpler!
##########
File path:
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/executor/pubsub/PubSubExecutor.java
##########
@@ -33,28 +33,57 @@
@Override
public RedisResponse executeCommand(Command command, ExecutionHandlerContext
context) {
- byte[] subCommand = command.getProcessedCommand().get(1);
+ List<byte[]> processedCommand = command.getProcessedCommand();
+ String subCommand =
Coder.bytesToString(processedCommand.get(1)).toLowerCase();
- if (!Arrays.equals(subCommand, Coder.stringToBytes("channels"))) {
- return RedisResponse
- .error(String.format(ERROR_UNKNOWN_PUBSUB_SUBCOMMAND, new
String(subCommand)));
- }
+ List<Object> response;
+
+ switch (subCommand) {
+ case "channels":
+ // in a subsequent story, a new parameter requirement class
+ // specific to subCommands might be a better way to do this
+ if (processedCommand.size() > 3) {
+ return RedisResponse
+ .error(String.format(ERROR_UNKNOWN_PUBSUB_SUBCOMMAND,
subCommand));
+ }
+
+ response = doChannels(processedCommand, context);
+ break;
+
+ case "numsub":
+ response = doNumsub(processedCommand, context);
+ break;
+
+ default:
+ return RedisResponse
+ .error(String.format(ERROR_UNKNOWN_PUBSUB_SUBCOMMAND, subCommand));
- // in a subsequent story, a new parameter requirement class
- // specific to subCommands might be a better way to do this
- if (command.getProcessedCommand().size() > 3) {
- return RedisResponse
- .error(String.format(ERROR_UNKNOWN_PUBSUB_SUBCOMMAND, new
String(subCommand)));
}
- List<byte[]> response;
- if (command.getProcessedCommand().size() > 2) {
- byte[] pattern = command.getProcessedCommand().get(2);
+ return RedisResponse.array(response);
Review comment:
yeah, that's a bit better- thanks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]