func NewPubSub(ctx context.Context, taskStarter component.TaskStarter, conf config.RedisEvents) events.PubSub {
	ttnRedisClient := ttnredis.New(&conf.Config)
	ctx = log.NewContextWithFields(ctx, log.Fields(
		"namespace", "events/redis",
	))
	ctx, cancel := context.WithCancel(ctx)
	ps := &PubSub{
		PubSub: basic.NewPubSub(),
		ctx:    ctx,
		cancel: cancel,
		client: ttnRedisClient,
		subscriptions: make(map[string]int),
	}
	ps.sub = ps.client.Subscribe(ctx)
	workers := conf.Workers
	if workers == 0 {
		workers = 1
	}
	for i := 0; i < workers; i++ {
		taskStarter.StartTask(&component.TaskConfig{
			Context: ps.ctx,
			ID:      fmt.Sprintf("events_redis_subscribe_%02d", i),
			Func:    ps.subscribeTask,
			Restart: component.TaskRestartOnFailure,
			Backoff: component.DefaultTaskBackoffConfig,
		})
	}
	if !conf.Store.Enable {
		return ps
	}
	pss := &PubSubStore{
		PubSub:                    ps,
		historyTTL:                conf.Store.TTL,
		entityHistoryCount:        conf.Store.EntityCount,
		entityHistoryTTL:          conf.Store.EntityTTL,
		correlationIDHistoryCount: conf.Store.CorrelationIDCount,
	}
	if pss.historyTTL == 0 {
		pss.historyTTL = 10 * time.Minute
	}
	if pss.entityHistoryCount == 0 {
		pss.entityHistoryCount = 100
	}
	if pss.entityHistoryTTL == 0 {
		pss.entityHistoryTTL = time.Hour
	}
	if pss.correlationIDHistoryCount == 0 {
		pss.correlationIDHistoryCount = 100
	}
	return pss
}
NewPubSub creates a new PubSub that publishes and subscribes to Redis.
package redis
import (
	"context"
	"fmt"
	"strings"
	"sync"
	"time"
	"github.com/go-redis/redis/v8"
	"go.thethings.network/lorawan-stack/v3/pkg/component"
	"go.thethings.network/lorawan-stack/v3/pkg/config"
	"go.thethings.network/lorawan-stack/v3/pkg/errors"
	"go.thethings.network/lorawan-stack/v3/pkg/events"
	"go.thethings.network/lorawan-stack/v3/pkg/events/basic"
	"go.thethings.network/lorawan-stack/v3/pkg/log"
	ttnredis "go.thethings.network/lorawan-stack/v3/pkg/redis"
	"go.thethings.network/lorawan-stack/v3/pkg/ttnpb"
	"go.thethings.network/lorawan-stack/v3/pkg/unique"
)