mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-17 04:30:03 +02:00
35 lines
639 B
Go
35 lines
639 B
Go
package cache
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/go-redis/cache/v9"
|
|
)
|
|
|
|
type RedisStore struct {
|
|
c *cache.Cache
|
|
}
|
|
|
|
func NewRedisStore(options *cache.Options) *RedisStore {
|
|
return &RedisStore{
|
|
c: cache.New(options),
|
|
}
|
|
}
|
|
|
|
func (s *RedisStore) Get(ctx context.Context, key string, value interface{}) error {
|
|
return s.c.Get(ctx, key, value)
|
|
}
|
|
|
|
func (s *RedisStore) Has(ctx context.Context, key string) bool {
|
|
return s.c.Exists(ctx, key)
|
|
}
|
|
|
|
func (s *RedisStore) Set(ctx context.Context, key string, value any, ttl time.Duration) error {
|
|
return s.c.Set(&cache.Item{
|
|
Ctx: ctx,
|
|
Key: key,
|
|
Value: value,
|
|
TTL: ttl,
|
|
})
|
|
}
|