update_cache.go 596 B

123456789101112131415161718192021222324252627
  1. package repository
  2. import (
  3. "context"
  4. "time"
  5. "github.com/Wei-Shaw/sub2api/internal/service"
  6. "github.com/redis/go-redis/v9"
  7. )
  8. const updateCacheKey = "update:latest"
  9. type updateCache struct {
  10. rdb *redis.Client
  11. }
  12. func NewUpdateCache(rdb *redis.Client) service.UpdateCache {
  13. return &updateCache{rdb: rdb}
  14. }
  15. func (c *updateCache) GetUpdateInfo(ctx context.Context) (string, error) {
  16. return c.rdb.Get(ctx, updateCacheKey).Result()
  17. }
  18. func (c *updateCache) SetUpdateInfo(ctx context.Context, data string, ttl time.Duration) error {
  19. return c.rdb.Set(ctx, updateCacheKey, data, ttl).Err()
  20. }