revision = "24dfe0572921e42ffe1035f7afbd40f9d97cb8c8"
version = "v6.10.0"
+[[projects]]
+ name = "github.com/go-redis/redis"
+ packages = [
+ ".",
+ "internal",
+ "internal/consistenthash",
+ "internal/hashtag",
+ "internal/pool",
+ "internal/proto",
+ "internal/singleflight",
+ "internal/util"
+ ]
+ revision = "877867d2845fbaf86798befe410b6ceb6f5c29a3"
+ version = "v6.10.2"
+
[[projects]]
name = "github.com/golang/protobuf"
packages = ["proto"]
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
- inputs-digest = "e3fa83f0fc133d3c408abdc47e5c2ca08062fec7c34ea04c21ea122492ab863d"
+ inputs-digest = "587bbc93998cd884863b3559ec6ef87ebf381b7bca10587a7e79c2c227c64ead"
solver-name = "gps-cdcl"
solver-version = 1
}
type Config struct {
- App AppConfig
- Api ApiConfig
- Db db.DBConfig
+ App AppConfig
+ Api ApiConfig
+ Db db.DBConfig
+ Redis db.RedisConfig
utils.LogConfiguration
Address string
api.SetJwtSecretKey(C.Api.JwtSecret)
- db.Init(C.Db)
+ db.Init(C.Db, C.Redis)
if C.Mode == "production" {
gin.SetMode(gin.ReleaseMode)
migrate "github.com/go-pg/migrations"
"github.com/go-pg/pg"
"github.com/go-pg/pg/orm"
+ "github.com/go-redis/redis"
"github.com/jloup/utils"
)
-var DB *pg.DB
-
var log = utils.StandardL().WithField("module", "db")
+var (
+ DB *pg.DB
+ Redis *redis.Client
+)
+
type DBConfig struct {
Address string
Database string
Password string
}
-func Init(config DBConfig) {
+type RedisConfig struct {
+ Type string // tcp or unix
+ Address string
+ Password string
+}
+
+func Init(config DBConfig, redisConfig RedisConfig) {
var err error
DB = connect(config)
if err != nil {
log.Fatalf("cannot migratedb '%v'\n", err)
}
+
+ Redis = redis.NewClient(&redis.Options{
+ Network: redisConfig.Type,
+ Addr: redisConfig.Address,
+ Password: redisConfig.Password,
+ DB: 0,
+ })
+
+ _, err = Redis.Ping().Result()
+
+ if err != nil {
+ log.Fatalf("redis init error %s", err)
+ }
+
}
func migratedb() error {