stefanwille / crystal-redis

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

#psubscribe subscription callback not called #43

Closed danielwestendorf closed 6 years ago

danielwestendorf commented 6 years ago

I'm unsure if this is a bug or just improper usage of the library. I can #subscribe to a channel without issue. However, when I try to use #psubscribe the subscription callback never is called. What am I doing wrong?

require "redis"
redis = Redis.new

redis.psubscribe("channel.*") do |on|
  on.message do |channel, message|
    puts "I got a message"
  end
end
$ crystal run src/psubscribe.cr
^
$ redis-cli
127.0.0.1:6379> PSUBSCRIBE channel.*
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "channel.*"
3) (integer) 1
1) "pmessage"
2) "channel.*"
3) "channel.abc"
4) "hello"
$ redis-cli
127.0.0.1:6379> PUBLISH channel.abc hello
(integer) 1
127.0.0.1:6379>
$ crystal --version
Crystal 0.23.1 (2017-09-08) LLVM 4.0.1
  redis:
    github: stefanwille/crystal-redis
    version: 1.9.0
danielwestendorf commented 6 years ago

This was a usage issue. After looking at the specs, the API for listening to #psubscribe is different.

I've created a PR with an example for #psubscribe to the examples repo.