func (r *EvaluationRepository) FindAllByReqHash(ctx context.Context, reqHash string) (flaggio.EvaluationList, error) {
	span, ctx := opentracing.StartSpanFromContext(ctx, "RedisEvaluationRepository.FindAllByReqHash")
	defer span.Finish()
	cacheKey := flaggio.EvalCacheKey(reqHash)
	cached, err := r.redis.WithContext(ctx).HGetAll(cacheKey).Result()
	if err != nil && !errors.Is(err, redis.Nil) {
		return nil, err
	}
	if len(cached) > 0 {
		var el flaggio.EvaluationList
		for _, val := range cached {
			var e flaggio.Evaluation
			if err := msgpack.Unmarshal([]byte(val), &e); err == nil {
				el = append(el, &e)
			}
		}
		if len(el) == len(cached) {
			return el, nil
		}
	}
	evals, err := r.store.FindAllByReqHash(ctx, reqHash)
	if err != nil {
		return nil, err
	}
	if err := r.cacheEvaluations(ctx, reqHash, evals...); err != nil {
		return nil, err
	}
	return evals, nil
}
FindAllByReqHash returns all previous flag evaluations for a given request hash.
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.Evaluation = (*EvaluationRepository)(nil)
type EvaluationRepository struct {
	redis *redis.Client
	store repository.Evaluation
	ttl   time.Duration
}
func (r *EvaluationRepository) FindAllByUserID(ctx context.Context, userID string, search *string, offset, limit *int64) (*flaggio.EvaluationResults, error) {
	span, ctx := opentracing.StartSpanFromContext(ctx, "RedisEvaluationRepository.FindAllByUserID")
	defer span.Finish()
	return r.store.FindAllByUserID(ctx, userID, search, offset, limit)
}
func (r *EvaluationRepository) FindByReqHashAndFlagKey(ctx context.Context, reqHash, flagKey string) (*flaggio.Evaluation, error) {
	span, ctx := opentracing.StartSpanFromContext(ctx, "RedisEvaluationRepository.FindByReqHashAndFlagKey")
	defer span.Finish()
	cacheKey := flaggio.EvalCacheKey(reqHash)
	cached, err := r.redis.WithContext(ctx).HGet(cacheKey, flagKey).Result()
	if err != nil && !errors.Is(err, redis.Nil) {
		return nil, err
	}
	if cached != "" {
		var e flaggio.Evaluation
		if err := msgpack.Unmarshal([]byte(cached), &e); err == nil {
			return &e, nil
		}
	}
	eval, err := r.store.FindByReqHashAndFlagKey(ctx, reqHash, flagKey)
	if err != nil {
		return nil, err
	}
	if err := r.cacheEvaluations(ctx, reqHash, eval); err != nil {
		return nil, err
	}
	return eval, nil
}