keyspace_notifications

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package keyspace_notifications对象,用于管理监听redis事件,本工具实际是pubsub中sub的一个实例

Index

Constants

This section is empty.

Variables

View Source
var Defaultopt = Options{
	NotificationEventHandlers: map[string]pchelper.EventHanddler{},
}

Defaultopt 默认的可选配置

View Source
var ErrNoitificationsAlreadyListened = errors.New("keyspace-notification already listened")

ErrNoitificationsAlreadyListened keyspace-notification已经被监听了

View Source
var ErrNoitificationsNotListeningYet = errors.New("keyspace-notification not listrning yet")

ErrNoitificationsNotListeningYet keyspace-notification未被监听

Functions

func WithKeyEventNotificationHandler added in v2.0.1

func WithKeyEventNotificationHandler(db int, event string, fn pchelper.EventHanddler) optparams.Option[Options]

WithKeyEventNotificationHandler 注册监听KeyEvent通知的回调函数

func WithKeySpaceNotificationHandler added in v2.0.1

func WithKeySpaceNotificationHandler(db int, key string, fn pchelper.EventHanddler) optparams.Option[Options]

WithKeySpaceNotificationHandler 注册监听keyspace通知的回调函数

Types

type KeyspaceNotification

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

KeyspaceNotification 键空间通知的配置

func New

func New(cli redis.UniversalClient, opts ...optparams.Option[Options]) (*KeyspaceNotification, error)

New 创建一个键空间通知对象

func (*KeyspaceNotification) CheckConf added in v2.0.1

func (c *KeyspaceNotification) CheckConf(ctx context.Context) (string, error)

CheckConf 查看当前notify-keyspace-events的相关配置,具体可以查看<http://redisdoc.com/topic/notification.html>

func (*KeyspaceNotification) SetConf added in v2.0.1

func (c *KeyspaceNotification) SetConf(ctx context.Context, conf string) error

SetConf 设置当前的notify-keyspace-events配置<http://redisdoc.com/topic/notification.html>

func (*KeyspaceNotification) Start added in v2.0.1

Start 监听事件 @params opts ...optparams.Option[pchelper.ListenOptions] 监听时的一些配置,具体看listenoption.go说明

func (*KeyspaceNotification) Stop added in v2.0.1

func (s *KeyspaceNotification) Stop() error

Stop 停止监听

type NotificationEvent

type NotificationEvent struct {
	Type      NotificationEventType `json:"type"`
	DB        string                `json:"db"`
	Key       string                `json:"key"`
	EventName string                `json:"event_name"` //事件名可以参考<http://redisdoc.com/topic/notification.html>
}

func FromTopicToNotificationEvent added in v2.0.1

func FromTopicToNotificationEvent(topic, value string) (*NotificationEvent, error)

func (*NotificationEvent) Topic added in v2.0.1

func (event *NotificationEvent) Topic() string

type NotificationEventType

type NotificationEventType uint16

NotificationEventType 通知类型

const (

	//KeySpaceNotification 键空间通知
	KeySpaceNotification NotificationEventType = iota
	//KeyEventNotification 键事件通知
	KeyEventNotification
)

type Options added in v2.0.1

type Options struct {
	NotificationEventHandlers map[string]pchelper.EventHanddler
}

Options broker的配置

Jump to

Keyboard shortcuts

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