Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 拨号tcp[::1]:6397:connectex:无法建立连接,因为目标计算机主动拒绝它_Windows_Go_Redis - Fatal编程技术网

Windows 拨号tcp[::1]:6397:connectex:无法建立连接,因为目标计算机主动拒绝它

Windows 拨号tcp[::1]:6397:connectex:无法建立连接,因为目标计算机主动拒绝它,windows,go,redis,Windows,Go,Redis,我正在用Redis(第一次试用Redis)在Windows上编写一个简单的Go web应用程序。我正在使用go redis包连接到redis package main import ( "fmt" "net/http" "text/template" "github.com/go-redis/redis" "github.com/gorilla/mux"

我正在用Redis(第一次试用Redis)在Windows上编写一个简单的Go web应用程序。我正在使用go redis包连接到redis

package main

import (
    "fmt"
    "net/http"
    "text/template"

    "github.com/go-redis/redis"
    "github.com/gorilla/mux"
)

var client *redis.Client
var tmpl *template.Template

func init() {
    client = redis.NewClient(&redis.Options{
        Addr:     "localhost:6397",
        Password: "",
        DB:       0,
    })
    tmpl = template.Must(template.ParseGlob("./templates/*.gohtml"))
    pong, err := client.Ping().Result()
    fmt.Println(pong, err)
}

func main() {
    router := mux.NewRouter()
    router.HandleFunc("/", indexHandler).Methods("GET")
    http.Handle("/", router)
    http.ListenAndServe(":1234", nil)
}

func indexHandler(w http.ResponseWriter, r *http.Request) {
    comments, err := client.LRange("comments", 0, 10).Result()
    check(err)
    tmpl.ExecuteTemplate(w, "index.gohtml", comments)
}

func check(err error) {
    if err != nil {
        fmt.Println(err)
        return
    }
}
但是当我运行这个代码时,我得到

拨号tcp[::1]:6397:connectex:无法建立连接,因为目标计算机主动拒绝它

我能找到的唯一答案是“启动redis服务器”。我的redis服务器已启动并正在运行(在redis客户端中使用“PING”命令进行检查)。我也尝试过以管理员的身份运行它,但没有成功

截图:


发生这种情况的原因很可能是Redis服务器运行在端口
6379
(这是Redis服务器的默认端口)上,但您正在尝试连接到端口
6397

将服务器地址更改为:

Addr:“localhost:6379”

Addr:“localhost:6397”


这应该能解决你的问题

这很可能是因为Redis服务器运行在端口
6379
(这是Redis服务器的默认端口)上,但您正在尝试连接到端口
6397

将服务器地址更改为:

Addr:“localhost:6379”

Addr:“localhost:6397”


这应该能解决你的问题

太感谢你了,修好了!考虑到我的问题有多愚蠢,我真的很尴尬。再次感谢!它发生了,没问题。非常感谢你,修复了它!考虑到我的问题有多愚蠢,我真的很尴尬。再次感谢!这是常有的事,没问题。