redis

package
v3.33.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package redis implements an events.PubSub implementation that uses Redis PubSub.

Example
package main

import (
	"context"

	"go.thethings.network/lorawan-stack/v3/pkg/config"
	"go.thethings.network/lorawan-stack/v3/pkg/events"
	"go.thethings.network/lorawan-stack/v3/pkg/events/redis"
	"go.thethings.network/lorawan-stack/v3/pkg/task"
)

type mockComponent struct {
	task.Starter
}

func (mockComponent) FromRequestContext(ctx context.Context) context.Context {
	return ctx
}

func main() {
	// The task starter is used for automatic re-subscription on failure.
	taskStarter := task.StartTaskFunc(task.DefaultStartTask)

	redisPubSub := redis.NewPubSub(context.TODO(), mockComponent{taskStarter}, config.RedisEvents{
		// Config here...
	}, config.BatchEvents{
		// Batch config here...
	})

	// Replace the default pubsub so that we will now publish to Redis.
	events.SetDefaultPubSub(redisPubSub)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPubSub

func NewPubSub(
	ctx context.Context, component workerpool.Component, conf config.RedisEvents, batchConf config.BatchEvents,
) events.PubSub

NewPubSub creates a new PubSub that publishes and subscribes to Redis.

Types

type PubSub

type PubSub struct {
	*basic.PubSub
	// contains filtered or unexported fields
}

PubSub with Redis backend.

func (*PubSub) Close

func (ps *PubSub) Close(ctx context.Context) error

Close the Redis publisher.

func (*PubSub) Publish

func (ps *PubSub) Publish(evs ...events.Event)

Publish an event to Redis.

func (*PubSub) Subscribe added in v3.8.5

func (ps *PubSub) Subscribe(
	ctx context.Context, names []string, ids []*ttnpb.EntityIdentifiers, hdl events.Handler,
) error

Subscribe implements the events.Subscriber interface.

type PubSubStore added in v3.13.0

type PubSubStore struct {
	*PubSub
	// contains filtered or unexported fields
}

PubSubStore is a PubSub with historical event storage.

func (*PubSubStore) FetchHistory added in v3.13.0

func (ps *PubSubStore) FetchHistory(
	ctx context.Context, names []string, ids []*ttnpb.EntityIdentifiers, after *time.Time, tail int,
) ([]events.Event, error)

FetchHistory fetches the tail (optional) of historical events matching the given names (optional) and identifiers (mandatory) after the given time (optional).

func (*PubSubStore) FindRelated added in v3.13.0

func (ps *PubSubStore) FindRelated(ctx context.Context, correlationID string) ([]events.Event, error)

FindRelated finds events with matching correlation IDs.

func (*PubSubStore) LoadEvent added in v3.13.0

func (ps *PubSubStore) LoadEvent(ctx context.Context, uid string) (*ttnpb.Event, error)

LoadEvent loads an event by its UID.

func (*PubSubStore) Publish added in v3.13.0

func (ps *PubSubStore) Publish(evs ...events.Event)

Publish implements events.Publisher.

func (*PubSubStore) SubscribeWithHistory added in v3.13.0

func (ps *PubSubStore) SubscribeWithHistory(
	ctx context.Context, names []string, ids []*ttnpb.EntityIdentifiers, after *time.Time, tail int, hdl events.Handler,
) (err error)

SubscribeWithHistory is like FetchHistory, but after fetching historical events, this continues sending live events until the context is done.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL