redis

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package redis provides a Redis-backed Broadcaster for socketio, enabling multi-node scale-out: broadcasts are relayed between server instances over Redis pub/sub so a message emitted on one node reaches sockets connected to any node. It speaks the Redis RESP protocol directly using only the standard library — no third-party client.

bc, _ := redis.New(redis.Options{Addr: "localhost:6379", Channel: "socket.io"})
io.SetBroadcaster(bc) // io is a *socketio.Server

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broadcaster

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

Broadcaster relays socketio broadcasts over Redis pub/sub. It satisfies socketio.Broadcaster.

func New

func New(opts Options) (*Broadcaster, error)

New connects to Redis, subscribes to the broadcast channel, and returns a Broadcaster ready to install with server.SetBroadcaster.

func (*Broadcaster) Close

func (b *Broadcaster) Close() error

Close implements socketio.Broadcaster.

func (*Broadcaster) OnMessage

func (b *Broadcaster) OnMessage(fn func([]byte))

OnMessage implements socketio.Broadcaster.

func (*Broadcaster) Publish

func (b *Broadcaster) Publish(data []byte) error

Publish implements socketio.Broadcaster: it PUBLISHes data to the channel.

type Options

type Options struct {
	// Addr is the Redis server address (host:port).
	Addr string
	// Channel is the pub/sub channel used for broadcasts (default "socket.io").
	Channel string
	// Password, if set, authenticates via AUTH.
	Password string
	// DB selects a Redis database via SELECT (default 0).
	DB int
	// Dial overrides the network dialer (used in tests).
	Dial func(addr string) (net.Conn, error)
}

Options configures the Redis broadcaster.

Jump to

Keyboard shortcuts

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