首页 > 解决方案 > 角度发送请求时redis崩溃

问题描述

我有一个带有 redigo 的 go 服务器,我有这个功能可以从 redis 获取数据:

func findCompetition(conn redis.Conn, username string) competition{
    conn.Send("KEYS", "*")
    conn.Flush()
    re, erre := conn.Receive()
    keys, err := redis.Strings(re, erre)
    if err != nil {
        log.Print(re)
        log.Print(err)
        return competition{Username:"null"}
    }
    for _, key := range keys {
        comp := getCompetition(conn, key)
        if comp.Competitor == username && 
time.Now().Sub(comp.Time_asked).Minutes() < 2.0 {
            return comp
        }
    }
    return competition{Username:"null"}
}

当我通过浏览器发送请求时,例如:http://localhost:4500/find_competition/aicam 没关系,但是当我的 Angular 项目在几秒钟后每 1.5 秒发送一次请求时 log.Print(err) 在下面打印错误:

读取 tcp 127.0.0.1:35874->127.0.0.1:6379: 使用关闭的网络连接

我尝试了所有解决方案,例如:stackoverflow github 和端口 35874 有时会发生变化

标签: angularlinuxsocketsgo

解决方案


推荐阅读