到目前为止,我一直在这样做:import ( _redis "gopkg.in/redis.v3" "strconv" "time")type Redis struct { Connector *_redis.Client PubSub *_redis.PubSub}var redis *Redis = nilfunc NewRedis() bool { if redis == nil { redis = new(Redis) redis.Connector = _redis.NewClient(&_redis.Options{ Addr: config.RedisHostname + ":" + strconv.FormatInt(config.RedisPort, 10), Password: "", DB: 0, }) Logger.Log(nil, "Connected to Redis") err := redis.Init() if err != nil { Logger.Fatal(nil, "Cannot setup Redis:", err.Error()) return false } return true } return false}func (this *Redis) Init() error { pubsub, err := this.Connector.Subscribe("test") if err != nil { return err } defer pubsub.Close() this.PubSub = pubsub for { msgi, err := this.PubSub.ReceiveTimeout(100 * time.Millisecond) if err != nil { Logger.Error(nil, "PubSub error:", err.Error()) err = this.PubSub.Ping("") if err != nil { Logger.Error(nil, "PubSub failure:", err.Error()) break } continue } switch msg := msgi.(type) { case *_redis.Message: Logger.Log(nil, "Received", msg.Payload, "on channel", msg.Channel) } } return nil}我的连接器是一个 redis.Client,它可以工作,因为我也能够发布消息。当我运行我的程序时,出现以下错误: PubSub error: WSARecv tcp 127.0.0.1:64505: i/o timeout你知道我做错了什么吗?我正在使用这个包:https : //github.com/go-redis/redis
1 回答
- 1 回答
- 0 关注
- 268 浏览
添加回答
举报
0/150
提交
取消