All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.lettuce.core.pubsub.RedisPubSubAsyncCommandsImpl Maven / Gradle / Ivy

Go to download

Advanced and thread-safe Java Redis client for synchronous, asynchronous, and reactive usage. Supports Cluster, Sentinel, Pipelining, Auto-Reconnect, Codecs and much more.

The newest version!
/*
 * Copyright 2011-Present, Redis Ltd. and Contributors
 * All rights reserved.
 *
 * Licensed under the MIT License.
 *
 * This file contains contributions from third-party contributors
 * licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.lettuce.core.pubsub;

import java.util.List;
import java.util.Map;

import io.lettuce.core.RedisAsyncCommandsImpl;
import io.lettuce.core.RedisFuture;
import io.lettuce.core.codec.RedisCodec;
import io.lettuce.core.pubsub.api.async.RedisPubSubAsyncCommands;

/**
 * An asynchronous and thread-safe API for a Redis pub/sub connection.
 *
 * @param  Key type.
 * @param  Value type.
 * @author Will Glozer
 * @author Mark Paluch
 * @author Ali Takavci
 */
public class RedisPubSubAsyncCommandsImpl extends RedisAsyncCommandsImpl implements RedisPubSubAsyncCommands {

    private final PubSubCommandBuilder commandBuilder;

    /**
     * Initialize a new connection.
     *
     * @param connection the connection .
     * @param codec Codec used to encode/decode keys and values.
     */
    public RedisPubSubAsyncCommandsImpl(StatefulRedisPubSubConnection connection, RedisCodec codec) {
        super(connection, codec, null);
        this.commandBuilder = new PubSubCommandBuilder<>(codec);
    }

    @Override
    @SuppressWarnings("unchecked")
    public RedisFuture psubscribe(K... patterns) {
        return (RedisFuture) dispatch(commandBuilder.psubscribe(patterns));
    }

    @Override
    @SuppressWarnings("unchecked")
    public RedisFuture punsubscribe(K... patterns) {
        return (RedisFuture) dispatch(commandBuilder.punsubscribe(patterns));
    }

    @Override
    @SuppressWarnings("unchecked")
    public RedisFuture subscribe(K... channels) {
        return (RedisFuture) dispatch(commandBuilder.subscribe(channels));
    }

    @Override
    @SuppressWarnings("unchecked")
    public RedisFuture unsubscribe(K... channels) {
        return (RedisFuture) dispatch(commandBuilder.unsubscribe(channels));
    }

    @Override
    public RedisFuture publish(K channel, V message) {
        return dispatch(commandBuilder.publish(channel, message));
    }

    @Override
    public RedisFuture> pubsubChannels(K channel) {
        return dispatch(commandBuilder.pubsubChannels(channel));
    }

    @Override
    public RedisFuture> pubsubNumsub(K... channels) {
        return dispatch(commandBuilder.pubsubNumsub(channels));
    }

    @Override
    public RedisFuture> pubsubShardChannels(K pattern) {
        return dispatch(commandBuilder.pubsubShardChannels(pattern));
    }

    @Override
    public RedisFuture> pubsubShardNumsub(K... shardChannels) {
        return dispatch(commandBuilder.pubsubShardNumsub(shardChannels));
    }

    @Override
    public RedisFuture spublish(K shardChannel, V message) {
        return dispatch(commandBuilder.spublish(shardChannel, message));
    }

    @Override
    @SuppressWarnings("unchecked")
    public RedisFuture ssubscribe(K... channels) {
        return (RedisFuture) dispatch(commandBuilder.ssubscribe(channels));
    }

    @Override
    @SuppressWarnings("unchecked")
    public RedisFuture sunsubscribe(K... channels) {
        return (RedisFuture) dispatch(commandBuilder.sunsubscribe(channels));
    }

    @Override
    @SuppressWarnings("unchecked")
    public StatefulRedisPubSubConnection getStatefulConnection() {
        return (StatefulRedisPubSubConnection) super.getStatefulConnection();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy