eventbus

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

Package eventbus provides PubSub interface used for distributed cache invalidation, as well as NopPubSub and RedisPubSub implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NopPubSub

type NopPubSub struct{}

NopPubSub implements default do-nothing pub-sub (event bus)

func (*NopPubSub) Publish

func (n *NopPubSub) Publish(string, string) error

Publish does nothing for NopPubSub

func (*NopPubSub) Subscribe

func (n *NopPubSub) Subscribe(func(fromID string, key string)) error

Subscribe does nothing for NopPubSub

type PubSub

type PubSub interface {
	Publish(fromID, key string) error
	Subscribe(fn func(fromID, key string)) error
}

PubSub interface is used for distributed cache invalidation. Publish is called on each entry invalidation, Subscribe is used for subscription for these events.

type RedisPubSub

type RedisPubSub struct {
	// contains filtered or unexported fields
}

RedisPubSub provides Redis implementation for PubSub interface

func NewRedisPubSub

func NewRedisPubSub(addr, channel string) (*RedisPubSub, error)

NewRedisPubSub creates new RedisPubSub with given parameters. Returns an error in case of problems with creating PubSub client for specified channel.

func (*RedisPubSub) Close

func (m *RedisPubSub) Close() error

Close cleans up running goroutines and closes Redis clients

func (*RedisPubSub) Publish

func (m *RedisPubSub) Publish(fromID, key string) error

Publish publishes provided message to channel provided on new RedisPubSub instance creation

func (*RedisPubSub) Subscribe

func (m *RedisPubSub) Subscribe(fn func(fromID, key string)) error

Subscribe calls provided function on subscription channel provided on new RedisPubSub instance creation. Should not be called more than once. Spawns a goroutine and does not return an error.

Jump to

Keyboard shortcuts

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