Documentation ¶
Overview ¶
Package redispipebp provides baseplate.go integrations for the redispipe library that conform to the redix.Sync interface.
It is recommended that you use these to add baseplate integrations to the underlying redisx.Sync used by a redisx.Syncx object rather than using these directly so you can take advantage of the Syncx API.
Index ¶
- Variables
- func NewBaseplateRedisClient(ctx context.Context, addr string, opts redisconn.Opts, ...) (redisx.Sync, error)
- func NewBaseplateRedisCluster(ctx context.Context, addrs []string, opts rediscluster.Opts, ...) (redisx.Sync, error)
- type BaseplateRedisClientArgs
- type BreakerScanIterator
- type BreakerSync
- func (s BreakerSync) Do(ctx context.Context, cmd string, args ...interface{}) interface{}
- func (s BreakerSync) Scanner(ctx context.Context, opts redis.ScanOpts) redisx.ScanIterator
- func (s BreakerSync) Send(ctx context.Context, r redis.Request) interface{}
- func (s BreakerSync) SendMany(ctx context.Context, reqs []redis.Request) []interface{}
- func (s BreakerSync) SendTransaction(ctx context.Context, reqs []redis.Request) ([]interface{}, error)
- type ClientConfig
- type ClusterConfig
- type ClusterOpts
- type MonitoredScanIterator
- type MonitoredSync
- func (s MonitoredSync) Do(ctx context.Context, cmd string, args ...interface{}) (result interface{})
- func (s MonitoredSync) Scanner(ctx context.Context, opts redis.ScanOpts) redisx.ScanIterator
- func (s MonitoredSync) Send(ctx context.Context, r redis.Request) (result interface{})
- func (s MonitoredSync) SendMany(ctx context.Context, reqs []redis.Request) (results []interface{})
- func (s MonitoredSync) SendTransaction(ctx context.Context, reqs []redis.Request) (results []interface{}, err error)
- type Opts
- type RedispipeError
- type RetryScanIterator
- type RetrySync
- func (s RetrySync) Do(ctx context.Context, cmd string, args ...interface{}) (result interface{})
- func (s RetrySync) Scanner(ctx context.Context, opts redis.ScanOpts) redisx.ScanIterator
- func (s RetrySync) Send(ctx context.Context, req redis.Request) (result interface{})
- func (s RetrySync) SendMany(ctx context.Context, reqs []redis.Request) (results []interface{})
- func (s RetrySync) SendTransaction(ctx context.Context, reqs []redis.Request) (results []interface{}, err error)
- type Timeouts
- type WrapErrorsSync
- func (s WrapErrorsSync) Do(ctx context.Context, cmd string, args ...interface{}) interface{}
- func (s WrapErrorsSync) Scanner(ctx context.Context, opts redis.ScanOpts) redisx.ScanIterator
- func (s WrapErrorsSync) Send(ctx context.Context, r redis.Request) interface{}
- func (s WrapErrorsSync) SendMany(ctx context.Context, reqs []redis.Request) []interface{}
- func (s WrapErrorsSync) SendTransaction(ctx context.Context, reqs []redis.Request) ([]interface{}, error)
- type WrappedErrorsScanIterator
Constants ¶
This section is empty.
Variables ¶
var ErrBaseplateNameRequired = errors.New("redispipebp: Name is a required field in BaseplateRedisClientArgs")
ErrBaseplateNameRequired is returned when do not set a Name in the argument struct to a new baseplate redis client.
Functions ¶
func NewBaseplateRedisClient ¶
func NewBaseplateRedisClient(ctx context.Context, addr string, opts redisconn.Opts, args BaseplateRedisClientArgs) (redisx.Sync, error)
NewBaseplateRedisClient returns a new redisx.Sync that wraps a single instance redis client.
func NewBaseplateRedisCluster ¶
func NewBaseplateRedisCluster(ctx context.Context, addrs []string, opts rediscluster.Opts, args BaseplateRedisClientArgs) (redisx.Sync, error)
NewBaseplateRedisCluster returns a new redisx.Sync that wraps a single instance redis cluster client.
Types ¶
type BaseplateRedisClientArgs ¶
type BaseplateRedisClientArgs struct { // Name is the name of the redis client for use in client tracing. // This is a required field. Name string // Breaker is the circuit breaker config for the redis client. // This is optional, if it is nil then we will not wrap the client in a BreakerSync. Breaker *breakerbp.Config // Retry is the retry options for the redis client. // This is optional, if it is empty or nil, then we will not wrap the client in a RetrySync Retry []retry.Option // ReplicaPolicy is the config enumeration of policies of redis replica hosts usage. // This is optional, if nil, default to MasterOnly policy // This config only applies if NewBaseplateRedisCluster is used to create a redis client otherwise does nothing. // See: https://pkg.go.dev/github.com/joomcode/redispipe/rediscluster#ReplicaPolicyEnum ReplicaPolicy rediscluster.ReplicaPolicyEnum }
BaseplateRedisClientArgs is used to configure a baseplate redis client (cluster or single instance). The underlying client is wrapped in the following order, depending on the config:
- MonitoredSync
- If retrys are configured:
- RetrySync
- MonitoredSync for monitoring each request
- If a circuit breaker is configured:
- BreakerSync
- WrapErrorsSync
type BreakerScanIterator ¶
type BreakerScanIterator struct { redisx.ScanIterator // contains filtered or unexported fields }
BreakerScanIterator is a ScanIterator that is wrapped with a circuit breaker.
func (BreakerScanIterator) Next ¶
func (s BreakerScanIterator) Next() ([]string, error)
Next wraps s.ScanIterator.Next in the given CircuitBreaker
type BreakerSync ¶
type BreakerSync struct { Sync redisx.Sync Breaker breakerbp.CircuitBreaker }
BreakerSync wraps redis calls is the given CircuitBreaker.
func (BreakerSync) Do ¶
func (s BreakerSync) Do(ctx context.Context, cmd string, args ...interface{}) interface{}
Do wraps s.Sync.Do in the given CircuitBreaker
func (BreakerSync) Scanner ¶
func (s BreakerSync) Scanner(ctx context.Context, opts redis.ScanOpts) redisx.ScanIterator
Scanner returns a new BreakerScanIterator using s.Sync.Scanner and the given CircuitBreaker.
func (BreakerSync) Send ¶
func (s BreakerSync) Send(ctx context.Context, r redis.Request) interface{}
Send wraps s.Sync.Send in the given CircuitBreaker
func (BreakerSync) SendMany ¶
func (s BreakerSync) SendMany(ctx context.Context, reqs []redis.Request) []interface{}
SendMany wraps s.Sync.SendMany in the given CircuitBreaker
func (BreakerSync) SendTransaction ¶
func (s BreakerSync) SendTransaction(ctx context.Context, reqs []redis.Request) ([]interface{}, error)
SendTransaction wraps s.Sync.SendTransaction in the given CircuitBreaker
type ClientConfig ¶
type ClientConfig struct { // Addr is the address of your Redis server. // // This is the only required field. Addr string `yaml:"addr"` Options Opts `yaml:"options"` }
ClientConfig can be used to configure a redispipe "Client". See the docs for redisconn.Opts in redispipe for details on what each value means and what its defaults are: https://pkg.go.dev/github.com/joomcode/redispipe@v0.9.4/redisconn?tab=doc#Opts
Can be deserialized from YAML.
Examples:
Minimal YAML:
redis: addr: localhost:6379
Full YAML:
redis: addr: redis://localhost:6379 opts: db: 1 writePause: 150000ns # 150 microseconds reconnectPause: 2s tcpKeepAlive: 333ms asyncDial: false scriptMode: false timeouts: dial: 1s io: 500ms
func (ClientConfig) Opts ¶
func (cfg ClientConfig) Opts() redisconn.Opts
Opts returns a redisconn.Opts object with the configured options applied.
type ClusterConfig ¶
type ClusterConfig struct { // Addrs is the list of seed addresses to connect to the Redis Cluster. Addrs []string `yaml:"addrs"` // Options maps to rediscluster.Opts.HostOpts Options Opts `yaml:"options"` // Cluster is the remaining, Redis Cluster specific options. Cluster ClusterOpts `yaml:"cluster"` }
ClusterConfig can be used to configure a redispipe "Cluster". See the docs for redisluster.Opts in redispipe.
Can be deserialized from YAML.
Examples:
Minimal YAML:
redis: addrs: - localhost:6379 - localhost:6380
Full YAML:
redis: addrs: - localhost:6379 - localhost:6380 options: writePause: 150000ns # 150 microseconds reconnectPause: 2s tcpKeepAlive: 333ms asyncDial: false scriptMode: false timeouts: dial: 1s io: 500ms
func (ClusterConfig) Opts ¶
func (cfg ClusterConfig) Opts() rediscluster.Opts
Opts returns a rediscluster.Opts object with the configured options applied.
type ClusterOpts ¶
type ClusterOpts struct { // Name is the name of the cluster. // // Maps to rediscluster.Opts.Name Name string `yaml:"name"` }
ClusterOpts are Redis Cluster specific options.
All fields in Opts are optional and redispipe provides default values.
See the documentation for details on each field as well as the default values. https://pkg.go.dev/github.com/joomcode/redispipe@v0.9.4/rediscluster?tab=doc#Opts
func (ClusterOpts) ApplyOpts ¶
func (o ClusterOpts) ApplyOpts(opts *rediscluster.Opts)
ApplyOpts applies any values set in o to opts, if a value is not set on o, then we don't update opts and allow redispipe to use its defaults.
type MonitoredScanIterator ¶
type MonitoredScanIterator struct { redisx.ScanIterator // contains filtered or unexported fields }
MonitoredScanIterator is a ScanIterator that is wrapped with a client spans.
func (MonitoredScanIterator) Next ¶
func (s MonitoredScanIterator) Next() (results []string, err error)
Next wraps s.ScanIterator.Next in a client span.
type MonitoredSync ¶
MonitoredSync wraps Sync methods in client spans.
func (MonitoredSync) Do ¶
func (s MonitoredSync) Do(ctx context.Context, cmd string, args ...interface{}) (result interface{})
Do wraps s.Sync.Do in a client span.
func (MonitoredSync) Scanner ¶
func (s MonitoredSync) Scanner(ctx context.Context, opts redis.ScanOpts) redisx.ScanIterator
Scanner returns a new MonitoredScanIterator.
func (MonitoredSync) Send ¶
func (s MonitoredSync) Send(ctx context.Context, r redis.Request) (result interface{})
Send wraps s.Sync.Send in a client span.
func (MonitoredSync) SendMany ¶
func (s MonitoredSync) SendMany(ctx context.Context, reqs []redis.Request) (results []interface{})
SendMany wraps s.Sync.SendMany in a client span.
func (MonitoredSync) SendTransaction ¶
func (s MonitoredSync) SendTransaction(ctx context.Context, reqs []redis.Request) (results []interface{}, err error)
SendTransaction wraps s.Sync.SendTransaction in a client span.
type Opts ¶
type Opts struct { // DB is the database number in Redis. // // Maps to redisconn.Opts.DB DB *int `yaml:"db"` // WritePause is the duration of time the write loop should wait to collect // commands to flush. // // Maps to redisconn.Opts.WritePause WritePause time.Duration `yaml:"writePause"` // ReconnectPause is how long the client will wait to attempt to make a // connection the previous attempt fails. // // Maps to redisconn.Opts.ReconnectPause ReconnectPause time.Duration `yaml:"reconnectPause"` // TCPKeepAlive is the KeepAlive parameter for the net.Dial used to make a new // connection. // // Maps to redisconn.Opts.TCPKeepAlive TCPKeepAlive time.Duration `yaml:"tcpKeepAlive"` // Timeouts is used to configure the different connection timeouts. Timeouts Timeouts `yaml:"timeouts"` }
Opts is used to apply the configured options to a rediscluster.Opts.
All fields in Opts are optional and redispipe provides default values.
See the documentation for details on each field as well as the default values. https://pkg.go.dev/github.com/joomcode/redispipe@v0.9.4/redisconn?tab=doc#Opts
type RedispipeError ¶
type RedispipeError struct { // Errorx is the Error wrapped by the RedispipeError. // Note, this is not embedded because Error ends up conflicting with the // Error() function we must implement to fufill the error interface. Errorx *errorx.Error }
RedispipeError wraps an errorx.Err from redispipe and provides an interface that interacts with the errors package provided by Go.
func (*RedispipeError) As ¶
func (e *RedispipeError) As(v interface{}) bool
As implements helper interface for errors.As.
func (*RedispipeError) Error ¶
func (e *RedispipeError) Error() string
func (*RedispipeError) Unwrap ¶
func (e *RedispipeError) Unwrap() error
Unwrap implements helper interface for errors.Unwrap.
Unwraps the underlying errorx.Error by calling Cause() and wrapping the result.
type RetryScanIterator ¶
type RetryScanIterator struct { redisx.ScanIterator // contains filtered or unexported fields }
RetryScanIterator is a ScanIterator that is wrapped with retry logic.
func (RetryScanIterator) Next ¶
func (s RetryScanIterator) Next() (results []string, err error)
Next wraps s.ScanIterator.Next in the retry logic.
type RetrySync ¶
RetrySync wraps redis calls in retry logic using the given Options.
type Timeouts ¶
type Timeouts struct { // Dial is the timeout for the net.Dialer used to create a connection. // // Maps to redisconn.Opts.DialTimeout Dial time.Duration `yaml:"dial"` // IO is the timeout for read/write operations on the socket. // // Maps to redisconn.Opts.IOTimeout IO time.Duration `yaml:"io"` }
Timeouts applies the timeout options to redisconn.Opts.
All fields in Timeouts are optional and redispipe provides default values.
Can be deserialized from YAML.
type WrapErrorsSync ¶
WrapErrorsSync takes any errors returned by redispipe and wraps them in a new type that is compatible with the built-in errors package.
func (WrapErrorsSync) Do ¶
func (s WrapErrorsSync) Do(ctx context.Context, cmd string, args ...interface{}) interface{}
Do calls s.Sync.Do and if it returns an error, wraps the error in a RedispipeError.
func (WrapErrorsSync) Scanner ¶
func (s WrapErrorsSync) Scanner(ctx context.Context, opts redis.ScanOpts) redisx.ScanIterator
Scanner returns a new WrapErrorsScanIterator.
func (WrapErrorsSync) Send ¶
func (s WrapErrorsSync) Send(ctx context.Context, r redis.Request) interface{}
Send calls s.Sync.Send and if it returns an error, wraps the error in a RedispipeError.
func (WrapErrorsSync) SendMany ¶
func (s WrapErrorsSync) SendMany(ctx context.Context, reqs []redis.Request) []interface{}
SendMany calls s.Sync.SendMany and if it returns any errors, wraps them in a RedispipeError.
func (WrapErrorsSync) SendTransaction ¶
func (s WrapErrorsSync) SendTransaction(ctx context.Context, reqs []redis.Request) ([]interface{}, error)
SendTransaction calls s.Sync.SendTransaction and if it returns an error, wraps the error in a RedispipeError.
type WrappedErrorsScanIterator ¶
type WrappedErrorsScanIterator struct {
redisx.ScanIterator
}
WrappedErrorsScanIterator takes any errors returned by redispipe and wraps them in a new type that is compatible with the built-in errors package.
func (WrappedErrorsScanIterator) Next ¶
func (s WrappedErrorsScanIterator) Next() ([]string, error)
Next calls s.ScanIterator.Next and if it returns an error, wraps the error in a RedispipeError.