func (r *FlagRepository) FindByID(ctx context.Context, id string) (*flaggio.Flag, error) {
	span, ctx := opentracing.StartSpanFromContext(ctx, "RedisFlagRepository.FindByID")
	defer span.Finish()
	cacheKey := flaggio.FlagCacheKey(id)
	cached, err := r.redis.WithContext(ctx).Get(cacheKey).Result()
	if err != nil && !errors.Is(err, redis.Nil) {
		return nil, err
	}
	if cached != "" {
		var f flaggio.Flag
		if err := msgpack.Unmarshal([]byte(cached), &f); err == nil {
			return &f, nil
		}
	}
	res, err := r.store.FindByID(ctx, id)
	if err != nil {
		return nil, err
	}
	b, err := msgpack.Marshal(res)
	if err != nil {
		return nil, err
	}
	if err := r.redis.WithContext(ctx).Set(cacheKey, b, r.ttl).Err(); err != nil {
		return nil, err
	}
	return res, nil
}
FindByID returns a flag that has a given ID.
package redis
import (
	"context"
	"errors"
	"time"
	"github.com/go-redis/redis/v7"
	"github.com/opentracing/opentracing-go"
	"github.com/victorkt/flaggio/internal/flaggio"
	"github.com/victorkt/flaggio/internal/repository"
	"github.com/vmihailenco/msgpack/v4"
)
var _ repository.Flag = (*FlagRepository)(nil)
type FlagRepository struct {
	redis *redis.Client
	store repository.Flag
	ttl   time.Duration
}
func (r *FlagRepository) FindAll(ctx context.Context, search *string, offset, limit *int64) (*flaggio.FlagResults, error) {
	span, ctx := opentracing.StartSpanFromContext(ctx, "RedisFlagRepository.FindAll")
	defer span.Finish()
	shouldCache := shouldCacheFindAll(search, offset, limit)
	cacheKey := flaggio.FlagCacheKey("*")
	if shouldCache {
		cached, err := r.redis.WithContext(ctx).Get(cacheKey).Result()
		if err != nil && !errors.Is(err, redis.Nil) {
			return nil, err
		}
		if cached != "" {
			var fr flaggio.FlagResults
			if err := msgpack.Unmarshal([]byte(cached), &fr); err == nil {
				return &fr, nil
			}
		}
	}
	res, err := r.store.FindAll(ctx, search, offset, limit)
	if err != nil {
		return nil, err
	}
	if shouldCache {
		b, err := msgpack.Marshal(res)
		if err != nil {
			return nil, err
		}
		if err := r.redis.Set(cacheKey, b, r.ttl).Err(); err != nil {
			return nil, err
		}
	}
	return res, nil
}