Search code examples
javaredislettuce

What does the Redis 'redis.publish()' method do?


What does redis.publish(); method do in the following module.

redis.publish("WordCountTopology", exclamatedWord.toString() + "|" + Long.toString(count));

public void execute(Tuple tuple)
    {
      String word = tuple.getString(0);

      StringBuilder exclamatedWord = new StringBuilder();
      exclamatedWord.append(word).append("!!!");

      _collector.emit(tuple, new Values(exclamatedWord.toString()));

      long count = 30;
      redis.publish("WordCountTopology", exclamatedWord.toString() + "|" + Long.toString(count));
    }

Solution

  • It publishes the string (ExclamatedWord + "|30") to a Redis channel called WordCountTopology - subscribers to that channel will get the message once redis.publish executes.

    For more information about Redis' Pub/Sub see: http://redis.io/topics/pubsub