pubsub.go 562 B

123456789101112131415161718192021222324252627
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package redis
  4. func (p *Redis) Publish(channel string, message interface{}) (res int64, err error) {
  5. // 安全检查
  6. if p == nil {
  7. return res, errRedis
  8. }
  9. if p.cluster {
  10. // 客户端安全检查
  11. if p.cclient == nil {
  12. return res, errRedisCClient
  13. }
  14. return p.cclient.Publish(channel, message).Result()
  15. }
  16. // 客户端安全检查
  17. if p.client == nil {
  18. return res, errRedisClient
  19. }
  20. return p.client.Publish(channel, message).Result()
  21. }