Documentation ¶
Overview ¶
Package redis implements the storage.Backend interface for redis.
Index ¶
- Variables
- func ParseClusterURL(rawurl string) (*redis.ClusterOptions, error)
- func ParseSentinelURL(rawurl string) (*redis.FailoverOptions, error)
- type Backend
- func (backend *Backend) Close() error
- func (backend *Backend) Get(ctx context.Context, recordType, id string) (_ *databroker.Record, err error)
- func (backend *Backend) GetAll(ctx context.Context) (records []*databroker.Record, versions *databroker.Versions, err error)
- func (backend *Backend) GetOptions(ctx context.Context, recordType string) (*databroker.Options, error)
- func (backend *Backend) Put(ctx context.Context, record *databroker.Record) (serverVersion uint64, err error)
- func (backend *Backend) SetOptions(ctx context.Context, recordType string, options *databroker.Options) error
- func (backend *Backend) Sync(ctx context.Context, serverVersion, recordVersion uint64) (storage.RecordStream, error)
- type Option
Constants ¶
This section is empty.
Variables ¶
var (
ErrExceededMaxRetries = errors.New("redis: transaction reached maximum number of retries")
)
custom errors
Functions ¶
func ParseClusterURL ¶ added in v0.14.0
ParseClusterURL parses a redis-cluster URL. Format is:
redis+cluster://[username:password@]host:port[,host2:port2,...]/[?param1=value1[¶m2=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
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[¶m2=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 (*Backend) Close ¶ added in v0.14.0
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.
type Option ¶
type Option func(*config)
Option customizes a Backend.
func WithExpiry ¶ added in v0.14.0
WithExpiry sets the expiry for changes.
func WithTLSConfig ¶
WithTLSConfig sets the tls.Config which Backend uses.