stefanwille / crystal-redis

Full featured Redis client for Crystal
MIT License
381 stars 61 forks source link

After unsubscribe() Connection thinks it is still subscribed #106

Closed stefanwille closed 3 years ago

stefanwille commented 4 years ago

As mentioned here: https://github.com/stefanwille/crystal-redis/issues/83

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")