yaml配置文件
RedisS:Host: Type: Pass:
config增加
RedisS struct {Host stringType stringPass string}
svc文件
type * struct {RedisClient *redis.Redis
}
func *(c config.Config) * {sqlConn := sqlx.NewMysql(c.DB.DataSource)return &*{RedisClient: redis.New(c.RedisS.Host, func(r *redis.Redis) {r.Type = c.RedisS.Typer.Pass = c.RedisS.Pass}),}
}
注意*是省略内容可忽视,看位置即可
logic方法
err = l.svcCtx.RedisClient.SetexCtx(ctx, "key", "111", 100)if err != nil {logc.Error(ctx, err)}v, err := l.svcCtx.RedisClient.GetCtx(ctx, "key")if err != nil {logc.Error(ctx, err)}