redis

package
v0.0.0-...-60b8695 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

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

Example
package main

import (
	"context"

	"github.com/aureliar8/ttn-fork/pkg/component"
	"github.com/aureliar8/ttn-fork/pkg/events"
	"github.com/aureliar8/ttn-fork/pkg/events/redis"

	ttnredis "github.com/aureliar8/ttn-fork/pkg/redis"
)

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

	redisPubSub := redis.NewPubSub(context.TODO(), taskStarter, ttnredis.Config{
		// 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

This section is empty.

Types

type PubSub

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

PubSub with Redis backend.

func NewPubSub

func NewPubSub(ctx context.Context, taskStarter component.TaskStarter, conf ttnredis.Config) *PubSub

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

func (*PubSub) Close

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

Close the Redis publisher.

func (*PubSub) Publish

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

Publish an event to Redis.

func (*PubSub) Subscribe

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

Subscribe implements the events.Subscriber interface.

Jump to

Keyboard shortcuts

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