redimem

package
v0.0.0-...-1215978 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Membership

type Membership interface {
	// Register adds name to the list of available servers. The registration lasts
	// for timeout duration. Register should be called again before timeout expires
	// in order to remain a member of the group.
	Register(ctx context.Context, memberName string, timeout time.Duration) error

	// Unregister removes a name from the list immediately. It's intended to be
	// used during shutdown so that there's no delay in the case of deliberate downsizing.
	Unregister(ctx context.Context, memberName string) error

	// GetMembers retrieves the list of all currently registered members. Members
	// that have registered but timed out will not be returned.
	GetMembers(ctx context.Context) ([]string, error)
}

Membership allows services to register themselves as members of a group and the list of all members can be retrieved by any member in the group.

type RedisMembership

type RedisMembership struct {
	// Prefix is a way of namespacing your group membership
	Prefix string
	// Pool should be an already-initialized redis pool
	Pool *redis.Pool
	// RepeatCount is the number of times GetMembers should ask Redis for the list
	// of members in the pool. As seen in the Redis docs "The SCAN family of
	// commands only offer limited guarantees about the returned elements"
	// (https://redis.io/commands/scan). In order to overcome some of these
	// limitations and gain confidence that the list of members is complete (and
	// preferring to get older members than miss current members), you can
	// configure RedisMembership to repeat the request for all members and union
	// the results, returning a potentially more complete list. This option
	// determines how many times RedisMembership asks Redis for the list of members
	// in the pool before taking the union of results and returning. Defaults to
	// 2.
	RepeatCount int
}

RedisMembership implements the Membership interface using Redis as the backend

func (*RedisMembership) GetMembers

func (rm *RedisMembership) GetMembers(ctx context.Context) ([]string, error)

GetMembers reaches out to Redis to retrieve a list of all members in the cluster. It does this multiple times (how many is configured on initializition) and takes the union of the results returned.

func (*RedisMembership) Register

func (rm *RedisMembership) Register(ctx context.Context, memberName string, timeout time.Duration) error

func (*RedisMembership) Unregister

func (rm *RedisMembership) Unregister(ctx context.Context, memberName string) error

Jump to

Keyboard shortcuts

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