Files
VLoop/backend/internal/middleware/redis/cache.go
2026-05-20 16:34:46 +08:00

36 lines
922 B
Go

package redis
import (
"context"
"errors"
"time"
)
func (c *Client) GetBytes(ctx context.Context, key string) ([]byte, error) {
if c == nil || c.rdb == nil {
return nil, errors.New("redis client not initialized")
}
return c.rdb.Get(ctx, key).Bytes()
}
func (c *Client) SetBytes(ctx context.Context, key string, value []byte, ttl time.Duration) error {
if c == nil || c.rdb == nil {
return errors.New("redis client not initialized")
}
return c.rdb.Set(ctx, key, value, ttl).Err()
}
func (c *Client) Del(ctx context.Context, key string) error {
if c == nil || c.rdb == nil {
return errors.New("redis client not initialized")
}
return c.rdb.Del(ctx, key).Err()
}
func (c *Client) MGet(cacheCtx context.Context, cacheKeys ...string) ([]interface{}, error) {
if c == nil || c.rdb == nil {
return nil, errors.New("redis client not initialized")
}
return c.rdb.MGet(cacheCtx, cacheKeys...).Result()
}