Sha256: 4d28179a1c7718e786f94fdb6666a16ee1b6652e62d52d80a539598d324ed23c

Contents?: true

Size: 1.75 KB

Versions: 13

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

class Redis
  module Commands
    module Pubsub
      # Post a message to a channel.
      def publish(channel, message)
        send_command([:publish, channel, message])
      end

      def subscribed?
        !@subscription_client.nil?
      end

      # Listen for messages published to the given channels.
      def subscribe(*channels, &block)
        _subscription(:subscribe, 0, channels, block)
      end

      # Listen for messages published to the given channels. Throw a timeout error
      # if there is no messages for a timeout period.
      def subscribe_with_timeout(timeout, *channels, &block)
        _subscription(:subscribe_with_timeout, timeout, channels, block)
      end

      # Stop listening for messages posted to the given channels.
      def unsubscribe(*channels)
        _subscription(:unsubscribe, 0, channels, nil)
      end

      # Listen for messages published to channels matching the given patterns.
      def psubscribe(*channels, &block)
        _subscription(:psubscribe, 0, channels, block)
      end

      # Listen for messages published to channels matching the given patterns.
      # Throw a timeout error if there is no messages for a timeout period.
      def psubscribe_with_timeout(timeout, *channels, &block)
        _subscription(:psubscribe_with_timeout, timeout, channels, block)
      end

      # Stop listening for messages posted to channels matching the given patterns.
      def punsubscribe(*channels)
        _subscription(:punsubscribe, 0, channels, nil)
      end

      # Inspect the state of the Pub/Sub subsystem.
      # Possible subcommands: channels, numsub, numpat.
      def pubsub(subcommand, *args)
        send_command([:pubsub, subcommand] + args)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
redis-5.0.7 lib/redis/commands/pubsub.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/redis-5.0.5/lib/redis/commands/pubsub.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/redis-5.0.5/lib/redis/commands/pubsub.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/redis-5.0.5/lib/redis/commands/pubsub.rb
redis-5.0.6 lib/redis/commands/pubsub.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/redis-5.0.5/lib/redis/commands/pubsub.rb
redis-5.0.5 lib/redis/commands/pubsub.rb
redis-5.0.4 lib/redis/commands/pubsub.rb
redis-5.0.3 lib/redis/commands/pubsub.rb
redis-5.0.2 lib/redis/commands/pubsub.rb
redis-5.0.1 lib/redis/commands/pubsub.rb
redis-5.0.0 lib/redis/commands/pubsub.rb
redis-5.0.0.beta4 lib/redis/commands/pubsub.rb