go 项目容器化,依赖redis,项目的redis怎么配置啊?我的redis host写docker-compose.yaml文件中 redis的名称,也配置了network,定时服务能起来并运行了,结果redis里面没有写入数据?
这是项目的redis配置
```
[redis]
host = 'redis'
port = 6379
password = ''
network = 'main'
```
下面的是docker-compose.yaml
```
version: '2.0'
services:
redis:
image: 'redis:6'
ports:
- '6379:6379'
networks:
- main
container_name: miracle-redis
goapp:
build:
context: ./lightning
dockerfile: Dockerfile
container_name: lightning
expose:
- "8080"
ports:
- "8080:8080"
environment:
TZ: "Asia/Shanghai"
volumes:
- /root/flyme/lightning:/app
depends_on:
- redis
restart: on-failure
networks:
main:
```
redis 连接客户端代码
```
import (
"fmt"
"github.com/go-redis/redis/v8"
probing "github.com/prometheus-community/pro-bing"
"lightning/setting"
"regexp"
"strconv"
)
var RedisClient = redis.NewClient(&redis.Options{
Addr: setting.Config.Redis.Host + ":" + strconv.Itoa(setting.Config.Redis.Port),
Password: setting.Config.Redis.Password,
DB: 8,
Network: setting.Config.Redis.Network,
})
var RedisStorageClient = redis.NewClient(&redis.Options{
Addr: setting.Config.Redis.Host + ":" + strconv.Itoa(setting.Config.Redis.Port),
Password: setting.Config.Redis.Password,
DB: 3,
Network: setting.Config.Redis.Network,
})
```
找了好久没找到问题,我的Python项目中,redis host配置直接使用`redis`就可以了,也不用配置network,求指导
有疑问加站长微信联系(非本文作者)