

package org.apache.geode.redis.internal.commands.executor.pubsub;

import java.util.List;

import org.apache.geode.redis.internal.commands.Command;
import org.apache.geode.redis.internal.commands.executor.CommandExecutor;
import org.apache.geode.redis.internal.commands.executor.RedisResponse;
import org.apache.geode.redis.internal.netty.ExecutionHandlerContext;

public class PublishExecutor implements CommandExecutor {

  @Override
  public RedisResponse executeCommand(Command command,
      ExecutionHandlerContext context) {
    context.checkForLowMemory(command.getCommandType());

    List<byte[]> args = command.getCommandArguments();
    byte[] channelName = args.get(0);
    byte[] message = args.get(1);
    long publishCount = context.getPubSub()
        .publish(channelName, message, context.getClient());

    return RedisResponse.integer(publishCount);
  }
}
