package cache import ( "context" "fmt" "time" "github.com/redis/go-redis/v9" ) type KVWrite struct { Key string Val []byte TTL time.Duration Delete bool } func (c *Cache) GetRaw(ctx context.Context, key string) ([]byte, error) { if c == nil || c.rdb == nil { return nil, fmt.Errorf("redis unavailable") } b, err := c.rdb.Get(ctx, key).Bytes() if err == redis.Nil { return nil, nil } return b, err } func (c *Cache) TxWrite(ctx context.Context, writes []KVWrite) error { if c == nil || c.rdb == nil { return fmt.Errorf("redis unavailable") } if len(writes) == 0 { return nil } pipe := c.rdb.TxPipeline() for _, w := range writes { if w.Delete { pipe.Del(ctx, w.Key) continue } pipe.Set(ctx, w.Key, w.Val, w.TTL) } _, err := pipe.Exec(ctx) return err }