routing
v9.24.1
Documentation
pkg.go.dev ↗Constants
ReadOnlyCMD
const ( ReadOnlyCMD string = "readonly" )
Variables
ErrMaxAggregation (4 declarations)
var (
ErrMaxAggregation = errors.New("redis: no valid results to aggregate for max operation")
ErrMinAggregation = errors.New("redis: no valid results to aggregate for min operation")
ErrAndAggregation = errors.New("redis: no valid results to aggregate for logical AND operation")
ErrOrAggregation = errors.New("redis: no valid results to aggregate for logical OR operation")
)
SpecialAggregatorRegistry
var SpecialAggregatorRegistry = make(map[string]func([]interface{}, []error) (interface{}, error))
SpecialAggregatorRegistry holds custom aggregation functions for specific commands.
Functions
RegisterSpecialAggregator
func RegisterSpecialAggregator(cmdName string, fn func([]interface{}, []error) (interface{}, error))
RegisterSpecialAggregator registers a custom aggregation function for a command.
Types
AggLogicalAndAggregator
type AggLogicalAndAggregator struct {
// contains filtered or unexported fields
}
AggLogicalAndAggregator performs logical AND on boolean values.
AggLogicalAndAggregator.Add
func (a *AggLogicalAndAggregator) Add(result interface{}, err error) error
AggLogicalAndAggregator.AddWithKey
func (a *AggLogicalAndAggregator) AddWithKey(key string, result interface{}, err error) error
AggLogicalAndAggregator.Aggregate
func (a *AggLogicalAndAggregator) Aggregate() (interface{}, error)
AggLogicalAndAggregator.BatchAdd
func (a *AggLogicalAndAggregator) BatchAdd(results map[string]AggregatorResErr) error
AggLogicalAndAggregator.BatchSlice
func (a *AggLogicalAndAggregator) BatchSlice(results []AggregatorResErr) error
AggLogicalOrAggregator
type AggLogicalOrAggregator struct {
// contains filtered or unexported fields
}
AggLogicalOrAggregator performs logical OR on boolean values.
AggLogicalOrAggregator.Add
func (a *AggLogicalOrAggregator) Add(result interface{}, err error) error
AggLogicalOrAggregator.AddWithKey
func (a *AggLogicalOrAggregator) AddWithKey(key string, result interface{}, err error) error
AggLogicalOrAggregator.Aggregate
func (a *AggLogicalOrAggregator) Aggregate() (interface{}, error)
AggLogicalOrAggregator.BatchAdd
func (a *AggLogicalOrAggregator) BatchAdd(results map[string]AggregatorResErr) error
AggLogicalOrAggregator.BatchSlice
func (a *AggLogicalOrAggregator) BatchSlice(results []AggregatorResErr) error
AggMaxAggregator
type AggMaxAggregator struct {
// contains filtered or unexported fields
}
AggMaxAggregator returns the maximum numeric value from all shards.
AggMaxAggregator.Add
func (a *AggMaxAggregator) Add(result interface{}, err error) error
AggMaxAggregator.AddWithKey
func (a *AggMaxAggregator) AddWithKey(_ string, result interface{}, err error) error
AggMaxAggregator.Aggregate
func (a *AggMaxAggregator) Aggregate() (interface{}, error)
AggMaxAggregator.BatchAdd
func (a *AggMaxAggregator) BatchAdd(results map[string]AggregatorResErr) error
AggMaxAggregator.BatchSlice
func (a *AggMaxAggregator) BatchSlice(results []AggregatorResErr) error
AggMinAggregator
type AggMinAggregator struct {
// contains filtered or unexported fields
}
AggMinAggregator returns the minimum numeric value from all shards.
AggMinAggregator.Add
func (a *AggMinAggregator) Add(result interface{}, err error) error
AggMinAggregator.AddWithKey
func (a *AggMinAggregator) AddWithKey(_ string, result interface{}, err error) error
AggMinAggregator.Aggregate
func (a *AggMinAggregator) Aggregate() (interface{}, error)
AggMinAggregator.BatchAdd
func (a *AggMinAggregator) BatchAdd(results map[string]AggregatorResErr) error
AggMinAggregator.BatchSlice
func (a *AggMinAggregator) BatchSlice(results []AggregatorResErr) error
AggSumAggregator
type AggSumAggregator struct {
// contains filtered or unexported fields
}
AggSumAggregator sums numeric replies without losing integer precision.
AggSumAggregator.Add
func (a *AggSumAggregator) Add(result interface{}, err error) error
AggSumAggregator.AddWithKey
func (a *AggSumAggregator) AddWithKey(_ string, result interface{}, err error) error
AggSumAggregator.Aggregate
func (a *AggSumAggregator) Aggregate() (interface{}, error)
AggSumAggregator.BatchAdd
func (a *AggSumAggregator) BatchAdd(results map[string]AggregatorResErr) error
AggSumAggregator.BatchSlice
func (a *AggSumAggregator) BatchSlice(results []AggregatorResErr) error
AggregatorResErr
type AggregatorResErr struct {
Result interface{}
Err error
}
AllSucceededAggregator
type AllSucceededAggregator struct {
// contains filtered or unexported fields
}
AllSucceededAggregator returns one non-error reply if every shard succeeded, propagates the first error otherwise.
AllSucceededAggregator.Add
func (a *AllSucceededAggregator) Add(result interface{}, err error) error
AllSucceededAggregator.AddWithKey
func (a *AllSucceededAggregator) AddWithKey(key string, result interface{}, err error) error
AllSucceededAggregator.Aggregate
func (a *AllSucceededAggregator) Aggregate() (interface{}, error)
AllSucceededAggregator.BatchAdd
func (a *AllSucceededAggregator) BatchAdd(results map[string]AggregatorResErr) error
AllSucceededAggregator.BatchSlice
func (a *AllSucceededAggregator) BatchSlice(results []AggregatorResErr) error
CommandPolicy
type CommandPolicy struct {
Request RequestPolicy
Response ResponsePolicy
// Tips that are not request_policy or response_policy
// e.g nondeterministic_output, nondeterministic_output_order.
Tips map[string]string
}
CommandPolicy.CanBeUsedInPipeline
func (p *CommandPolicy) CanBeUsedInPipeline() bool
CommandPolicy.IsReadOnly
func (p *CommandPolicy) IsReadOnly() bool
DefaultKeyedAggregator
type DefaultKeyedAggregator struct {
// contains filtered or unexported fields
}
DefaultKeyedAggregator reassembles replies in the exact key order of the original request.
NewDefaultKeyedAggregator
func NewDefaultKeyedAggregator(keyOrder []string) *DefaultKeyedAggregator
DefaultKeyedAggregator.Add
func (a *DefaultKeyedAggregator) Add(result interface{}, err error) error
DefaultKeyedAggregator.AddWithKey
func (a *DefaultKeyedAggregator) AddWithKey(key string, result interface{}, err error) error
DefaultKeyedAggregator.Aggregate
func (a *DefaultKeyedAggregator) Aggregate() (interface{}, error)
DefaultKeyedAggregator.BatchAdd
func (a *DefaultKeyedAggregator) BatchAdd(results map[string]AggregatorResErr) error
DefaultKeyedAggregator.BatchAddWithKeyOrder
func (a *DefaultKeyedAggregator) BatchAddWithKeyOrder(results map[string]AggregatorResErr, keyOrder []string) error
DefaultKeyedAggregator.BatchSlice
func (a *DefaultKeyedAggregator) BatchSlice(results []AggregatorResErr) error
DefaultKeyedAggregator.SetKeyOrder
func (a *DefaultKeyedAggregator) SetKeyOrder(keyOrder []string)
DefaultKeylessAggregator
type DefaultKeylessAggregator struct {
// contains filtered or unexported fields
}
DefaultKeylessAggregator collects all results in an array, order doesn't matter.
DefaultKeylessAggregator.Add
func (a *DefaultKeylessAggregator) Add(result interface{}, err error) error
DefaultKeylessAggregator.AddWithKey
func (a *DefaultKeylessAggregator) AddWithKey(key string, result interface{}, err error) error
DefaultKeylessAggregator.Aggregate
func (a *DefaultKeylessAggregator) Aggregate() (interface{}, error)
DefaultKeylessAggregator.BatchAdd
func (a *DefaultKeylessAggregator) BatchAdd(results map[string]AggregatorResErr) error
DefaultKeylessAggregator.BatchSlice
func (a *DefaultKeylessAggregator) BatchSlice(results []AggregatorResErr) error
OneSucceededAggregator
type OneSucceededAggregator struct {
// contains filtered or unexported fields
}
OneSucceededAggregator returns the first non-error reply, if all shards errored, returns any one of those errors.
OneSucceededAggregator.Add
func (a *OneSucceededAggregator) Add(result interface{}, err error) error
OneSucceededAggregator.AddWithKey
func (a *OneSucceededAggregator) AddWithKey(key string, result interface{}, err error) error
OneSucceededAggregator.Aggregate
func (a *OneSucceededAggregator) Aggregate() (interface{}, error)
OneSucceededAggregator.BatchAdd
func (a *OneSucceededAggregator) BatchAdd(results map[string]AggregatorResErr) error
OneSucceededAggregator.BatchSlice
func (a *OneSucceededAggregator) BatchSlice(results []AggregatorResErr) error
RandomPicker
type RandomPicker struct{}
RandomPicker.Next
func (RandomPicker) Next(total int) int
RequestPolicy
type RequestPolicy uint8
ReqDefault (5 declarations)
const ( ReqDefault RequestPolicy = iota ReqAllNodes ReqAllShards ReqMultiShard ReqSpecial )
ParseRequestPolicy
func ParseRequestPolicy(raw string) (RequestPolicy, error)
RequestPolicy.String
func (p RequestPolicy) String() string
ResponseAggregator
type ResponseAggregator interface {
// Add processes a single shard response.
Add(result interface{}, err error) error
// AddWithKey processes a single shard response for a specific key (used by keyed aggregators).
AddWithKey(key string, result interface{}, err error) error
BatchAdd(map[string]AggregatorResErr) error
BatchSlice([]AggregatorResErr) error
// Aggregate returns the final aggregated result and any error.
Aggregate() (interface{}, error)
}
ResponseAggregator defines the interface for aggregating responses from multiple shards.
NewDefaultAggregator
func NewDefaultAggregator(isKeyed bool) ResponseAggregator
NewResponseAggregator
func NewResponseAggregator(policy ResponsePolicy, cmdName string) ResponseAggregator
NewResponseAggregator creates an aggregator based on the response policy.
ResponsePolicy
type ResponsePolicy uint8
RespDefaultKeyless (10 declarations)
const ( RespDefaultKeyless ResponsePolicy = iota RespDefaultHashSlot RespAllSucceeded RespOneSucceeded RespAggSum RespAggMin RespAggMax RespAggLogicalAnd RespAggLogicalOr RespSpecial )
ParseResponsePolicy
func ParseResponsePolicy(raw string) (ResponsePolicy, error)
ResponsePolicy.String
func (p ResponsePolicy) String() string
RoundRobinPicker
type RoundRobinPicker struct {
// contains filtered or unexported fields
}
RoundRobinPicker.Next
func (p *RoundRobinPicker) Next(total int) int
ShardPicker
type ShardPicker interface {
Next(total int) int // returns an index in [0,total)
}
ShardPicker chooses “one arbitrary shard” when the request_policy is ReqDefault and the command has no keys.
SpecialAggregator
type SpecialAggregator struct {
// contains filtered or unexported fields
}
SpecialAggregator provides a registry for command-specific aggregation logic.
NewSpecialAggregator
func NewSpecialAggregator(cmdName string) *SpecialAggregator
NewSpecialAggregator creates a special aggregator with command-specific logic if available.
SpecialAggregator.Add
func (a *SpecialAggregator) Add(result interface{}, err error) error
SpecialAggregator.AddWithKey
func (a *SpecialAggregator) AddWithKey(key string, result interface{}, err error) error
SpecialAggregator.Aggregate
func (a *SpecialAggregator) Aggregate() (interface{}, error)
SpecialAggregator.BatchAdd
func (a *SpecialAggregator) BatchAdd(results map[string]AggregatorResErr) error
SpecialAggregator.BatchSlice
func (a *SpecialAggregator) BatchSlice(results []AggregatorResErr) error
StaticShardPicker
type StaticShardPicker struct {
// contains filtered or unexported fields
}
StaticShardPicker always returns the same shard index.
NewStaticShardPicker
func NewStaticShardPicker(index int) *StaticShardPicker
StaticShardPicker.Next
func (p *StaticShardPicker) Next(total int) int