go链接redis错误:A connection attempt failed because the connected

go链接redis错误:A connection attempt failed because the connected,第1张

package main

import (
	"fmt"
	"github.com/garyburd/redigo/redis"
)

func main() {
	conn, err := redis.Dial("tcp", "192.168.5.104:6379")
	if err != nil {
		fmt.Println("redis.Dial err = ", err)
		return
	}
	defer conn.Close()

	_, err = conn.Do("Set", "name", "tomje 猫")
	if err != nil {
		fmt.Println("Set err = ", err)
		return
	}

	r, err := redis.String(conn.Do("Get", "name"))
	if err != nil {
		fmt.Println("Get err = ", err)
		return
	}
	fmt.Println(" *** 作OK  :", r)
}

 这个错误应该是网络问题的,查看服务器的防火墙

 

#关闭防火墙
@localhost ~]# systemctl stop firewalld
@localhost ~]# systemctl disable firewalld
@localhost ~]# systemctl status firewalld

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/995159.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存