redis

package
v0.14.3 Latest Latest
Warning

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

Go to latest
Published: May 21, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package redis implements the storage.Backend interface for redis.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExceededMaxRetries = errors.New("redis: transaction reached maximum number of retries")
)

custom errors

Functions

func ParseClusterURL added in v0.14.0

func ParseClusterURL(rawurl string) (*redis.ClusterOptions, error)

ParseClusterURL parses a redis-cluster URL. Format is:

redis+cluster://[username:password@]host:port[,host2:port2,...]/[?param1=value1[&param2=value=2&...]]

Additionally TLS is supported with rediss+cluster, or redis+clusters. Supported query params:

max_redirects: int
read_only: bool
route_by_latency: bool
route_randomly: bool
max_retries: int
min_retry_backoff: duration
max_retry_backoff: duration
dial_timeout: duration
read_timeout: duration
write_timeout: duration
pool_size: int
min_idle_conns: int
max_conn_age: duration
pool_timeout: duration
idle_timeout: duration
idle_check_frequency: duration

func ParseSentinelURL added in v0.14.0

func ParseSentinelURL(rawurl string) (*redis.FailoverOptions, error)

ParseSentinelURL parses a redis-sentinel URL. Format is based on https://github.com/exponea/redis-sentinel-url:

redis+sentinel://[:password@]host:port[,host2:port2,...][/service_name[/db]][?param1=value1[&param2=value=2&...]]

Additionally TLS is supported with rediss+sentinel, or redis+sentinels. Supported query params:

slave_only: bool
use_disconnected_slaves: bool
query_sentinel_randomly: bool
username: string (username for redis connection)
password: string (password for redis connection)
max_retries: int
min_retry_backoff: duration
max_retry_backoff: duration
dial_timeout: duration
read_timeout: duration
write_timeout: duration
pool_size: int
min_idle_conns: int
max_conn_age: duration
pool_timeout: duration
idle_timeout: duration
idle_check_frequency: duration

Types

type Backend added in v0.14.0

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

Backend implements the storage.Backend on top of redis.

What's stored:

  • last_version: an integer recordVersion number
  • last_version_ch: a PubSub channel for recordVersion number updates
  • records: a Hash of records. The hash key is {recordType}/{recordID}, the hash value the protobuf record.
  • changes: a Sorted Set of all the changes. The score is the recordVersion number, the member the protobuf record.
  • options: a Hash of options. The hash key is {recordType}, the hash value the protobuf options.
  • changes.{recordType}: a Sorted Set of the changes for a record type. The score is the current time, the value the record id.

Records stored in these keys are typically encrypted.

func New

func New(rawURL string, options ...Option) (*Backend, error)

New creates a new redis storage backend.

func (*Backend) Close added in v0.14.0

func (backend *Backend) Close() error

Close closes the underlying redis connection and any watchers.

func (*Backend) Get added in v0.14.0

func (backend *Backend) Get(ctx context.Context, recordType, id string) (_ *databroker.Record, err error)

Get gets a record from redis.

func (*Backend) GetAll added in v0.14.0

func (backend *Backend) GetAll(ctx context.Context) (records []*databroker.Record, versions *databroker.Versions, err error)

GetAll gets all the records from redis.

func (*Backend) GetOptions added in v0.14.0

func (backend *Backend) GetOptions(ctx context.Context, recordType string) (*databroker.Options, error)

GetOptions gets the options for the given record type.

func (*Backend) Put added in v0.14.0

func (backend *Backend) Put(ctx context.Context, record *databroker.Record) (serverVersion uint64, err error)

Put puts a record into redis.

func (*Backend) SetOptions added in v0.14.0

func (backend *Backend) SetOptions(ctx context.Context, recordType string, options *databroker.Options) error

SetOptions sets the options for the given record type.

func (*Backend) Sync added in v0.14.0

func (backend *Backend) Sync(ctx context.Context, serverVersion, recordVersion uint64) (storage.RecordStream, error)

Sync returns a record stream of any records changed after the specified recordVersion.

type Option

type Option func(*config)

Option customizes a Backend.

func WithExpiry added in v0.14.0

func WithExpiry(expiry time.Duration) Option

WithExpiry sets the expiry for changes.

func WithTLSConfig

func WithTLSConfig(tlsConfig *tls.Config) Option

WithTLSConfig sets the tls.Config which Backend uses.

Jump to

Keyboard shortcuts

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