# frozen_string_literal: trueclassRedismoduleCommandsmodulePubsub# Post a message to a channel.defpublish(channel,message)send_command([:publish,channel,message])enddefsubscribed?!@subscription_client.nil?end# Listen for messages published to the given channels.defsubscribe(*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.defsubscribe_with_timeout(timeout,*channels,&block)_subscription(:subscribe_with_timeout,timeout,channels,block)end# Stop listening for messages posted to the given channels.defunsubscribe(*channels)_subscription(:unsubscribe,0,channels,nil)end# Listen for messages published to channels matching the given patterns.# See the [Redis Server PSUBSCRIBE documentation](https://redis.io/docs/latest/commands/psubscribe/)# for further detailsdefpsubscribe(*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.# See the [Redis Server PSUBSCRIBE documentation](https://redis.io/docs/latest/commands/psubscribe/)# for further detailsdefpsubscribe_with_timeout(timeout,*channels,&block)_subscription(:psubscribe_with_timeout,timeout,channels,block)end# Stop listening for messages posted to channels matching the given patterns.# See the [Redis Server PUNSUBSCRIBE documentation](https://redis.io/docs/latest/commands/punsubscribe/)# for further detailsdefpunsubscribe(*channels)_subscription(:punsubscribe,0,channels,nil)end# Inspect the state of the Pub/Sub subsystem.# Possible subcommands: channels, numsub, numpat.defpubsub(subcommand,*args)send_command([:pubsub,subcommand]+args)end# Post a message to a channel in a shard.defspublish(channel,message)send_command([:spublish,channel,message])end# Listen for messages published to the given channels in a shard.defssubscribe(*channels,&block)_subscription(:ssubscribe,0,channels,block)end# Listen for messages published to the given channels in a shard.# Throw a timeout error if there is no messages for a timeout period.defssubscribe_with_timeout(timeout,*channels,&block)_subscription(:ssubscribe_with_timeout,timeout,channels,block)end# Stop listening for messages posted to the given channels in a shard.defsunsubscribe(*channels)_subscription(:sunsubscribe,0,channels,nil)endendendend