0
点赞
收藏
分享

微信扫一扫

百亿级访问量,如何做缓存架构设计

weipeng2k 2023-09-02 阅读 12

yaml配置文件

RedisS:
  Host: 
  Type: 
  Pass: 

config增加

RedisS struct {
		Host string
		Type string
		Pass 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.Type
			r.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)
	}
举报

相关推荐

0 条评论