require "redis"
redis = Redis::PooledClient.new
sub_connection = redis.pool.checkout
sub_connection.subscribe("foo") do |on|
on.message do |c, m|
p({c, m})
sub_connection.unsubscribe(c)
end
end
# We're done with pub/sub using sub_connection at this point, return it to the pool:
redis.pool.checkin(sub_connection)
# The following fails because the only connection in the pool was previously
# used for pub/sub, and is still internally configured as such:
# Unhandled exception: Command SET not allowed in the context of a subscribed connection (Redis::Error)
redis.set("foo", "bar")
As mentioned here: https://github.com/stefanwille/crystal-redis/issues/83