💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
~~~ package service_redis import ( "fmt" "github.com/go-redis/redis" "gitee.com/winnie_gss/microService/service-log" "os" "gopkg.in/ini.v1" ) var redisConfig RedisConfig var client *redis.Client var pwd string type RedisConfig struct { RdHost string RdPort string RdPassword string } func InitRedis() { pwd, _ = os.Getwd() pwd += "//static" file, err := ini.Load(pwd + "//config.ini") service_log.ErrorLog(err) file.BlockMode = false err = file.Section("redis").MapTo(&redisConfig) service_log.ErrorLog(err) client = redis.NewClient(&redis.Options{Addr: fmt.Sprintf("%s:%s", redisConfig.RdHost, redisConfig.RdPort), Password: redisConfig.RdPassword}) client.WrapProcess(func(old func(cmd redis.Cmder) error) func(cmd redis.Cmder) error { return func(cmd redis.Cmder) error { service_log.InfoLog(fmt.Sprintf("starting process:<%s>\n", cmd)) err := old(cmd) service_log.InfoLog(fmt.Sprintf("finished process:<%s>\n", cmd)) return err } }) } func RGet(key string) *redis.StringCmd { cmd := redis.NewStringCmd("get", key) client.Process(cmd) return cmd } func RSet(key string, value interface{}) *redis.StringCmd { cmd := redis.NewStringCmd("set", key, value) client.Process(cmd) return cmd } func RExpire(key string, time int) *redis.StringCmd { cmd := redis.NewStringCmd("expire", key, time) client.Process(cmd) return cmd } ~~~