I am writing a simple go web application with redis (trying out redis for the first time) on windows. I'm using the go-redis package to connect to 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
}
}
But when I run this code, I get "dial tcp [::1]:6397: connectex: No connection could be made because the target machine actively refused it."
The only answer that I could find was to "start the redis server". My redis server is up and running (Checked it by using the "PING" command in redis client).I have also tried running it as administrator, but no luck. Screenshot attached
Any help would be appreciated. Thanks in advanced!