package redisdao import ( "context" "fmt" "time" "git.lzcwy.cn/zhengchiliu/zt-closet-backend/global" "git.lzcwy.cn/zhengchiliu/zt-closet-backend/internal/redismodel" "github.com/redis/go-redis/v9" ) // HoroscopeSet 缓存星座运势内容(zodiac + 日期维度,data 由上层负责序列化) func HoroscopeSet(ctx context.Context, zodiac string, statDate int64, data []byte, ttl time.Duration) error { ctx, span := global.Tracer.Start(ctx, "redisdao.HoroscopeSet") defer span.End() key := fmt.Sprintf(redismodel.KeyHoroscope, zodiac, statDate) if err := global.RedisEngine.Set(ctx, key, data, ttl).Err(); err != nil { span.RecordError(err) return err } return nil } // HoroscopeGet 读取星座运势缓存,未命中返回 redis.Nil func HoroscopeGet(ctx context.Context, zodiac string, statDate int64) ([]byte, error) { ctx, span := global.Tracer.Start(ctx, "redisdao.HoroscopeGet") defer span.End() key := fmt.Sprintf(redismodel.KeyHoroscope, zodiac, statDate) data, err := global.RedisEngine.Get(ctx, key).Bytes() if err != nil && err != redis.Nil { span.RecordError(err) } return data, err }