# go-lib-cache **Repository Path**: allan577/go-lib-cache ## Basic Information - **Project Name**: go-lib-cache - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2021-04-11 - **Last Updated**: 2022-06-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # go-lib-cache # 基础开发框架缓存组件 ## 依赖 ## - github.com/BurntSushi/toml - github.com/go-redis/redis/v7 - github.com/opentracing/opentracing-go - github.com/stretchr/testify ## xhash ## ### 介绍 ### - 读取 hash 类型数据可以方便的将 map 转成结构体 - 写入 hash 类型数据可以将结构体转成 map - 结构体可以被其他 sdk 复用,例如 xorm, gorm 等 ### 类型支持 ### - `Bool` `*Bool` - `Int` `Int8` `Int16` `Int32` `Int64` - `*Int` `*Int8` `*Int16` `*Int32` `*Int64` - `Uint` `Uint8` `Uint16` `Uint32` `Uint64` - `*Uint` `*Uint8` `*Uint16` `*Uint32` `*Uint64` - `Float32` `*Float32` `Float64` `*Float64` - `Interface` - `Map` - `Slice` - `String` `*String` - `Struct` `*Struct` - `time.Time` `*time.Time` - `alias` 例: `type UserStatus int` ### 快速开始 ### ```go // model 转 map result, err := xhash.Model2map(yourModel) // map 转 model yourModel := new(Model) err := xhash.Map2model(mapVar, yourModel) ``` ## trace支持 ## ```go redisConfig := new(cache.RedisConfig) err := Cfg("redis").UnmarshalKey(name, redisConfig) if err != nil { log.WithError(err).Error("load redis config err") return nil } redisEngine, err := cache.CreateRedisClient(name, redisConfig) if err != nil { log.WithError(err).Error("create redis engine err") return nil } redisEngine.Client.AddHook(&RedisHook{ RedisConfig: redisConfig, }) ``` ### WithCtx ### ```go redisEngine.WithCtx(ctx) ```