Update RedisOperations#convertAndSend to return number of clients receiving the message.
Currently, `RedisOperations#convertAndSend` is void event though the underlying `RedisPubSubCommands#publish` returns a `Long` that represents the number of clients receiving the published message (see https://redis.io/commands/publish). This commit updates `RedisOperations#convertAndSend` to return the number of clients that received the message. Closes #2209 Original pull request: #2225.
This commit is contained in:
committed by
Mark Paluch
parent
d2cae7528b
commit
178d44c5f1
@@ -46,6 +46,7 @@ import org.springframework.util.Assert;
|
||||
* @author ihaohong
|
||||
* @author Todd Merrill
|
||||
* @author Chen Li
|
||||
* @author Vedran Pavic
|
||||
*/
|
||||
public interface RedisOperations<K, V> {
|
||||
|
||||
@@ -591,9 +592,11 @@ public interface RedisOperations<K, V> {
|
||||
*
|
||||
* @param destination the channel to publish to, must not be {@literal null}.
|
||||
* @param message message to publish
|
||||
* @return the number of clients that received the message
|
||||
* @see <a href="https://redis.io/commands/publish">Redis Documentation: PUBLISH</a>
|
||||
*/
|
||||
void convertAndSend(String destination, Object message);
|
||||
@Nullable
|
||||
Long convertAndSend(String destination, Object message);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Methods to obtain specific operations interface objects.
|
||||
|
||||
@@ -86,6 +86,7 @@ import org.springframework.util.CollectionUtils;
|
||||
* @author Denis Zavedeev
|
||||
* @author ihaohong
|
||||
* @author Chen Li
|
||||
* @author Vedran Pavic
|
||||
* @param <K> the Redis key type against which the template works (usually a String)
|
||||
* @param <V> the Redis value type against which the template works
|
||||
* @see StringRedisTemplate
|
||||
@@ -942,14 +943,14 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertAndSend(String channel, Object message) {
|
||||
public Long convertAndSend(String channel, Object message) {
|
||||
|
||||
Assert.hasText(channel, "a non-empty channel is required");
|
||||
|
||||
byte[] rawChannel = rawString(channel);
|
||||
byte[] rawMessage = rawValue(message);
|
||||
|
||||
executeWithoutResult(connection -> connection.publish(rawChannel, rawMessage));
|
||||
return execute(connection -> connection.publish(rawChannel, rawMessage), true);
|
||||
}
|
||||
|
||||
private void executeWithoutResult(Consumer<RedisConnection> action) {
|
||||
|
||||
Reference in New Issue
Block a user