ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / QUIT allowed in this context
这是log中错误信息
我用了go-redis这个库
package cache
import (
"github.com/go-redis/redis"
)
var (
Client *redis.Client
Addr string
Password string
DBNum int
)
func Init(addr, password string, dbNum int) {
Client = redis.NewClient(&redis.Options{
Addr: addr,
Password: password,
DB: dbNum,
})
_, err := Client.Ping().Result()
if err != nil {
panic(err.Error())
}
Addr = addr
Password = password
DBNum = dbNum
}
func NewClient() *redis.Client {
client := redis.NewClient(&redis.Options{
Addr: Addr,
Password: Password,
DB: DBNum,
})
_, err := client.Ping().Result()
if err != nil {
log.Error("create subscription client failed " + err.Error())
return nil
} else {
return client
}
}
Client是平常的操作Client
订阅的Client是用的NewClient()的
pub 和sub 应该使用不同的client
文档里面说的有
https://redis.io/topics/pubsub