engineredis

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2016 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RedisSubscribeChannelSize is the size for the internal buffered channels RedisEngine
	// uses to synchronize subscribe/unsubscribe. It allows for effective batching during bulk
	// re-subscriptions, and allows large volume of incoming subscriptions to not block when
	// PubSub connection is reconnecting. Two channels of this size will be allocated, one for
	// Subscribe and one for Unsubscribe
	RedisSubscribeChannelSize = 4096
	// RedisPubSubWorkerChannelSize sets buffer size of channel to which we send all
	// messages received from Redis PUB/SUB connection to process in separate goroutine.
	RedisPubSubWorkerChannelSize = 4096
	// Maximum number of channels to include in a single subscribe call. Redis documentation
	// doesn't specify a maximum allowed but we think it probably makes sense to keep a sane
	// limit given how many subscriptions a single Centrifugo instance might be handling.
	RedisSubscribeBatchLimit = 2048
	// RedisPublishChannelSize is the size for the internal buffered channel RedisEngine uses
	// to collect publish requests.
	RedisPublishChannelSize = 1024
	// RedisPublishBatchLimit is a maximum limit of publish requests one batched publish
	// operation can contain.
	RedisPublishBatchLimit = 2048
)
View Source
const (
	RedisAPIKeySuffix         = ".api"
	RedisControlChannelSuffix = ".control"
	RedisPingChannelSuffix    = ".ping"
	RedisAdminChannelSuffix   = ".admin"
	RedisMessageChannelPrefix = ".message."
	RedisJoinChannelPrefix    = ".join."
	RedisLeaveChannelPrefix   = ".leave."
)

Variables

This section is empty.

Functions

func Configure

func Configure(setter config.Setter) error

func New

func New(n *node.Node, configs []*ShardConfig) (engine.Engine, error)

New initializes Redis Engine.

func Plugin

func Plugin(n *node.Node, getter config.Getter) (engine.Engine, error)

Types

type ChannelID

type ChannelID string

ChannelID is unique channel identificator in Redis.

type RedisEngine

type RedisEngine struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

RedisEngine uses Redis datastructures and PUB/SUB to manage Centrifugo logic. This engine allows to scale Centrifugo - you can run several Centrifugo instances connected to the same Redis and load balance clients between instances.

func (*RedisEngine) AddPresence

func (e *RedisEngine) AddPresence(ch string, uid string, info proto.ClientInfo, expire int) error

func (*RedisEngine) Channels

func (e *RedisEngine) Channels() ([]string, error)

func (*RedisEngine) History

func (e *RedisEngine) History(ch string, limit int) ([]proto.Message, error)

func (*RedisEngine) Name

func (e *RedisEngine) Name() string

func (*RedisEngine) Presence

func (e *RedisEngine) Presence(ch string) (map[string]proto.ClientInfo, error)

func (*RedisEngine) PublishAdmin

func (e *RedisEngine) PublishAdmin(message *proto.AdminMessage) <-chan error

func (*RedisEngine) PublishControl

func (e *RedisEngine) PublishControl(message *proto.ControlMessage) <-chan error

func (*RedisEngine) PublishJoin

func (e *RedisEngine) PublishJoin(message *proto.JoinMessage, opts *proto.ChannelOptions) <-chan error

func (*RedisEngine) PublishLeave

func (e *RedisEngine) PublishLeave(message *proto.LeaveMessage, opts *proto.ChannelOptions) <-chan error

func (*RedisEngine) PublishMessage

func (e *RedisEngine) PublishMessage(message *proto.Message, opts *proto.ChannelOptions) <-chan error

func (*RedisEngine) RemovePresence

func (e *RedisEngine) RemovePresence(ch string, uid string) error

func (*RedisEngine) Run

func (e *RedisEngine) Run() error

func (*RedisEngine) Shutdown

func (e *RedisEngine) Shutdown() error

func (*RedisEngine) Subscribe

func (e *RedisEngine) Subscribe(ch string) error

func (*RedisEngine) Unsubscribe

func (e *RedisEngine) Unsubscribe(ch string) error

type Shard

type Shard struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Shard has everything to connect to Redis instance.

func NewShard

func NewShard(n *node.Node, conf *ShardConfig) (*Shard, error)

func (*Shard) AddPresence

func (e *Shard) AddPresence(ch string, uid string, info proto.ClientInfo, expire int) error

func (*Shard) Channels

func (e *Shard) Channels() ([]string, error)

Requires Redis >= 2.8.0 (http://redis.io/commands/pubsub)

func (*Shard) History

func (e *Shard) History(ch string, limit int) ([]proto.Message, error)

func (*Shard) Presence

func (e *Shard) Presence(ch string) (map[string]proto.ClientInfo, error)

func (*Shard) PublishAdmin

func (e *Shard) PublishAdmin(message *proto.AdminMessage) <-chan error

func (*Shard) PublishControl

func (e *Shard) PublishControl(message *proto.ControlMessage) <-chan error

func (*Shard) PublishJoin

func (e *Shard) PublishJoin(message *proto.JoinMessage, opts *proto.ChannelOptions) <-chan error

func (*Shard) PublishLeave

func (e *Shard) PublishLeave(message *proto.LeaveMessage, opts *proto.ChannelOptions) <-chan error

func (*Shard) PublishMessage

func (e *Shard) PublishMessage(message *proto.Message, opts *proto.ChannelOptions) <-chan error

func (*Shard) RemovePresence

func (e *Shard) RemovePresence(ch string, uid string) error

func (*Shard) Run

func (e *Shard) Run() error

func (*Shard) Subscribe

func (e *Shard) Subscribe(ch string) error

func (*Shard) Unsubscribe

func (e *Shard) Unsubscribe(ch string) error

type ShardConfig

type ShardConfig struct {
	// Host is Redis server host.
	Host string
	// Port is Redis server port.
	Port string
	// Password is password to use when connecting to Redis database. If empty then password not used.
	Password string
	// DB is Redis database number as string. If empty then database 0 used.
	DB string
	// MasterName is a name of Redis instance master Sentinel monitors.
	MasterName string
	// SentinelAddrs is a slice of Sentinel addresses.
	SentinelAddrs []string
	// PoolSize is a size of Redis connection pool.
	PoolSize int
	// API enables listening for API queues to publish API commands into Centrifugo via pushing
	// commands into Redis queue.
	API bool
	// NumAPIShards is a number of sharded API queues in Redis to increase volume of commands
	// (most probably publish) that Centrifugo instance can process.
	NumAPIShards int
	// Prefix to use before every channel name and key in Redis.
	Prefix string
	// PubSubNumWorkers sets how many PUB/SUB message processing workers will be started.
	// By default we start runtime.NumCPU() workers.
	PubSubNumWorkers int
	// ReadTimeout is a timeout on read operations. Note that at moment it should be greater
	// than node ping publish interval in order to prevent timing out Pubsub connection's
	// Receive call.
	ReadTimeout time.Duration
	// WriteTimeout is a timeout on write operations
	WriteTimeout time.Duration
	// ConnectTimeout is a timeout on connect operation
	ConnectTimeout time.Duration
}

ShardConfig is struct with Redis Engine options.

Jump to

Keyboard shortcuts

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