package redis

import (
	
	
	
	
	

	
	
)

type TimeseriesCmdable interface {
	TSAdd(ctx context.Context, key string, timestamp interface{}, value float64) *IntCmd
	TSAddWithArgs(ctx context.Context, key string, timestamp interface{}, value float64, options *TSOptions) *IntCmd
	TSCreate(ctx context.Context, key string) *StatusCmd
	TSCreateWithArgs(ctx context.Context, key string, options *TSOptions) *StatusCmd
	TSAlter(ctx context.Context, key string, options *TSAlterOptions) *StatusCmd
	TSCreateRule(ctx context.Context, sourceKey string, destKey string, aggregator Aggregator, bucketDuration int) *StatusCmd
	TSCreateRuleWithArgs(ctx context.Context, sourceKey string, destKey string, aggregator Aggregator, bucketDuration int, options *TSCreateRuleOptions) *StatusCmd
	TSIncrBy(ctx context.Context, Key string, timestamp float64) *IntCmd
	TSIncrByWithArgs(ctx context.Context, key string, timestamp float64, options *TSIncrDecrOptions) *IntCmd
	TSDecrBy(ctx context.Context, Key string, timestamp float64) *IntCmd
	TSDecrByWithArgs(ctx context.Context, key string, timestamp float64, options *TSIncrDecrOptions) *IntCmd
	TSDel(ctx context.Context, Key string, fromTimestamp int, toTimestamp int) *IntCmd
	TSDeleteRule(ctx context.Context, sourceKey string, destKey string) *StatusCmd
	TSGet(ctx context.Context, key string) *TSTimestampValueCmd
	TSGetWithArgs(ctx context.Context, key string, options *TSGetOptions) *TSTimestampValueCmd
	TSInfo(ctx context.Context, key string) *MapStringInterfaceCmd
	TSInfoWithArgs(ctx context.Context, key string, options *TSInfoOptions) *MapStringInterfaceCmd
	TSMAdd(ctx context.Context, ktvSlices [][]interface{}) *IntSliceCmd
	TSQueryIndex(ctx context.Context, filterExpr []string) *StringSliceCmd
	TSQueryLabels(ctx context.Context, filterExpr []string) *StringSliceCmd
	TSQueryLabelValues(ctx context.Context, label string, filterExpr []string) *StringSliceCmd
	TSRevRange(ctx context.Context, key string, fromTimestamp int, toTimestamp int) *TSTimestampValueSliceCmd
	TSRevRangeWithArgs(ctx context.Context, key string, fromTimestamp int, toTimestamp int, options *TSRevRangeOptions) *TSTimestampValueSliceCmd
	TSRange(ctx context.Context, key string, fromTimestamp int, toTimestamp int) *TSTimestampValueSliceCmd
	TSRangeWithArgs(ctx context.Context, key string, fromTimestamp int, toTimestamp int, options *TSRangeOptions) *TSTimestampValueSliceCmd
	TSMRange(ctx context.Context, fromTimestamp int, toTimestamp int, filterExpr []string) *MapStringSliceInterfaceCmd
	TSMRangeWithArgs(ctx context.Context, fromTimestamp int, toTimestamp int, filterExpr []string, options *TSMRangeOptions) *MapStringSliceInterfaceCmd
	TSMRevRange(ctx context.Context, fromTimestamp int, toTimestamp int, filterExpr []string) *MapStringSliceInterfaceCmd
	TSMRevRangeWithArgs(ctx context.Context, fromTimestamp int, toTimestamp int, filterExpr []string, options *TSMRevRangeOptions) *MapStringSliceInterfaceCmd
	TSMGet(ctx context.Context, filters []string) *MapStringSliceInterfaceCmd
	TSMGetWithArgs(ctx context.Context, filters []string, options *TSMGetOptions) *MapStringSliceInterfaceCmd
	TSNRange(ctx context.Context, keys []string, fromTimestamp interface{}, toTimestamp interface{}) *TSNRangePivotRowSliceCmd
	TSNRangeWithArgs(ctx context.Context, keys []string, fromTimestamp interface{}, toTimestamp interface{}, options *TSNRangeOptions) *TSNRangePivotRowSliceCmd
	TSNRevRange(ctx context.Context, keys []string, fromTimestamp interface{}, toTimestamp interface{}) *TSNRangePivotRowSliceCmd
	TSNRevRangeWithArgs(ctx context.Context, keys []string, fromTimestamp interface{}, toTimestamp interface{}, options *TSNRevRangeOptions) *TSNRangePivotRowSliceCmd
	TSRead(ctx context.Context, key string, timestamp interface{}) *TSTimestampValueSliceCmd
	TSReadWithArgs(ctx context.Context, key string, timestamp interface{}, options *TSReadOptions) *TSTimestampValueSliceCmd
}

// TS.READ timestamp cursor sentinels.
const (
	TSReadEarliest = "-" // read from the earliest sample
	TSReadLatest   = "+" // latest sample, inclusive
	TSReadNew      = "$" // only samples added after the call
)

// TSReadOptions holds the optional TS.READ arguments.
type TSReadOptions struct {
	Block    bool          // wait for samples (emits the BLOCK group)
	Timeout  time.Duration // max wait; 0 blocks indefinitely
	MinCount int           // unblock threshold; defaults to 1
	MaxCount int           // reply cap; 0 is unlimited
}

type TSOptions struct {
	Retention         int
	ChunkSize         int
	Encoding          string
	DuplicatePolicy   string
	Labels            map[string]string
	IgnoreMaxTimeDiff int64
	IgnoreMaxValDiff  float64
}
type TSIncrDecrOptions struct {
	Timestamp         int64
	Retention         int
	ChunkSize         int
	Uncompressed      bool
	DuplicatePolicy   string
	Labels            map[string]string
	IgnoreMaxTimeDiff int64
	IgnoreMaxValDiff  float64
}

type TSAlterOptions struct {
	Retention         int
	ChunkSize         int
	DuplicatePolicy   string
	Labels            map[string]string
	IgnoreMaxTimeDiff int64
	IgnoreMaxValDiff  float64
}

type TSCreateRuleOptions struct {
	alignTimestamp int64
}

type TSGetOptions struct {
	Latest bool
}

type TSInfoOptions struct {
	Debug bool
}
type Aggregator int

const (
	Invalid = Aggregator(iota)
	Avg
	Sum
	Min
	Max
	Range
	Count
	First
	Last
	StdP
	StdS
	VarP
	VarS
	Twa
	CountNaN
	CountAll
)

func ( Aggregator) () string {
	switch  {
	case Invalid:
		return ""
	case Avg:
		return "AVG"
	case Sum:
		return "SUM"
	case Min:
		return "MIN"
	case Max:
		return "MAX"
	case Range:
		return "RANGE"
	case Count:
		return "COUNT"
	case First:
		return "FIRST"
	case Last:
		return "LAST"
	case StdP:
		return "STD.P"
	case StdS:
		return "STD.S"
	case VarP:
		return "VAR.P"
	case VarS:
		return "VAR.S"
	case Twa:
		return "TWA"
	case CountNaN:
		return "COUNTNAN"
	case CountAll:
		return "COUNTALL"
	default:
		return ""
	}
}

var (
	errTSMultiAggregationGroupBy = errors.New("redis: GROUPBY is not allowed when multiple aggregators are specified")
	errTSAggregationConflict     = errors.New("redis: setting both Aggregator and Aggregators is not allowed; use Aggregators instead because Aggregator is deprecated")
	errTSExcludeEmptyGroupBy     = errors.New("redis: EXCLUDEEMPTY is not allowed with GROUPBY")
)

func formatAggregationArgs( Aggregator,  []Aggregator) (string, int, error) {
	if  != Invalid && len() > 0 {
		return "", 0, errTSAggregationConflict
	}
	if len() == 0 {
		if  == Invalid {
			return "", 0, nil
		}
		,  := formatAggregatorArg()
		if  != nil {
			return "", 0, 
		}
		return , 1, nil
	}

	 := make([]string, len())
	for ,  := range  {
		if  == Invalid {
			return "", 0, fmt.Errorf("redis: invalid timeseries aggregator at index %d: Invalid (%d)", , )
		}
		,  := formatAggregatorArg()
		if  != nil {
			return "", 0, fmt.Errorf("redis: invalid timeseries aggregator at index %d: %d", , )
		}
		[] = 
	}

	return strings.Join(, ","), len(), nil
}

func formatAggregatorArg( Aggregator) (string, error) {
	 := .String()
	if  == "" {
		return "", fmt.Errorf("redis: invalid timeseries aggregator: %d", )
	}
	return , nil
}

type TSRangeOptions struct {
	Latest        bool
	FilterByTS    []int
	FilterByValue []int
	Count         int
	Align         interface{}
	// Deprecated: use Aggregators instead.
	Aggregator      Aggregator
	Aggregators     []Aggregator
	BucketDuration  int
	BucketTimestamp interface{}
	Empty           bool
}

type TSRevRangeOptions struct {
	Latest        bool
	FilterByTS    []int
	FilterByValue []int
	Count         int
	Align         interface{}
	// Deprecated: use Aggregators instead.
	Aggregator      Aggregator
	Aggregators     []Aggregator
	BucketDuration  int
	BucketTimestamp interface{}
	Empty           bool
}

type TSMRangeOptions struct {
	Latest         bool
	FilterByTS     []int
	FilterByValue  []int
	WithLabels     bool
	SelectedLabels []interface{}
	Count          int
	Align          interface{}
	// Deprecated: use Aggregators instead.
	Aggregator      Aggregator
	Aggregators     []Aggregator
	BucketDuration  int
	BucketTimestamp interface{}
	Empty           bool
	// ExcludeEmpty omits matching series that have no samples. Not allowed with GroupByLabel/Reducer. Redis 8.10+.
	ExcludeEmpty bool
	GroupByLabel interface{}
	Reducer      interface{}
}

type TSMRevRangeOptions struct {
	Latest         bool
	FilterByTS     []int
	FilterByValue  []int
	WithLabels     bool
	SelectedLabels []interface{}
	Count          int
	Align          interface{}
	// Deprecated: use Aggregators instead.
	Aggregator      Aggregator
	Aggregators     []Aggregator
	BucketDuration  int
	BucketTimestamp interface{}
	Empty           bool
	// ExcludeEmpty omits matching series that have no samples. Not allowed with GroupByLabel/Reducer. Redis 8.10+.
	ExcludeEmpty bool
	GroupByLabel interface{}
	Reducer      interface{}
}

type TSMGetOptions struct {
	Latest         bool
	WithLabels     bool
	SelectedLabels []interface{}
}

type TSNRangeOptions struct {
	Latest        bool
	FilterByTS    []int
	FilterByValue []float64 // exactly two elements: [min, max]
	Count         int
	Align         interface{}
	// Aggregators holds exactly one aggregator spec per key. Each spec lists one or
	// more aggregators applied to that key and is sent as a single comma-joined token
	// (e.g. {{Min, Max}, {Sum}} -> AGGREGATION MIN,MAX SUM <bucketDuration>).
	Aggregators     [][]Aggregator
	BucketDuration  int
	BucketTimestamp interface{}
	Empty           bool
}

type TSNRevRangeOptions struct {
	Latest        bool
	FilterByTS    []int
	FilterByValue []float64 // exactly two elements: [min, max]
	Count         int
	Align         interface{}
	// Aggregators holds exactly one aggregator spec per key. Each spec lists one or
	// more aggregators applied to that key and is sent as a single comma-joined token
	// (e.g. {{Min, Max}, {Sum}} -> AGGREGATION MIN,MAX SUM <bucketDuration>).
	Aggregators     [][]Aggregator
	BucketDuration  int
	BucketTimestamp interface{}
	Empty           bool
}

// TSAdd - Adds one or more observations to a t-digest sketch.
// For more information - https://redis.io/commands/ts.add/
func ( cmdable) ( context.Context,  string,  interface{},  float64) *IntCmd {
	 := []interface{}{"TS.ADD", , , }
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

// TSAddWithArgs - Adds one or more observations to a t-digest sketch.
// This function also allows for specifying additional options such as:
// Retention, ChunkSize, Encoding, DuplicatePolicy and Labels.
// For more information - https://redis.io/commands/ts.add/
func ( cmdable) ( context.Context,  string,  interface{},  float64,  *TSOptions) *IntCmd {
	 := []interface{}{"TS.ADD", , , }
	if  != nil {
		if .Retention != 0 {
			 = append(, "RETENTION", .Retention)
		}
		if .ChunkSize != 0 {
			 = append(, "CHUNK_SIZE", .ChunkSize)
		}
		if .Encoding != "" {
			 = append(, "ENCODING", .Encoding)
		}

		if .DuplicatePolicy != "" {
			 = append(, "DUPLICATE_POLICY", .DuplicatePolicy)
		}
		if .Labels != nil {
			 = append(, "LABELS")
			for ,  := range .Labels {
				 = append(, , )
			}
		}
		if .IgnoreMaxTimeDiff != 0 || .IgnoreMaxValDiff != 0 {
			 = append(, "IGNORE", .IgnoreMaxTimeDiff, .IgnoreMaxValDiff)
		}
	}
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

// TSCreate - Creates a new time-series key.
// For more information - https://redis.io/commands/ts.create/
func ( cmdable) ( context.Context,  string) *StatusCmd {
	 := []interface{}{"TS.CREATE", }
	 := NewStatusCmd(, ...)
	_ = (, )
	return 
}

// TSCreateWithArgs - Creates a new time-series key with additional options.
// This function allows for specifying additional options such as:
// Retention, ChunkSize, Encoding, DuplicatePolicy and Labels.
// For more information - https://redis.io/commands/ts.create/
func ( cmdable) ( context.Context,  string,  *TSOptions) *StatusCmd {
	 := []interface{}{"TS.CREATE", }
	if  != nil {
		if .Retention != 0 {
			 = append(, "RETENTION", .Retention)
		}
		if .ChunkSize != 0 {
			 = append(, "CHUNK_SIZE", .ChunkSize)
		}
		if .Encoding != "" {
			 = append(, "ENCODING", .Encoding)
		}

		if .DuplicatePolicy != "" {
			 = append(, "DUPLICATE_POLICY", .DuplicatePolicy)
		}
		if .Labels != nil {
			 = append(, "LABELS")
			for ,  := range .Labels {
				 = append(, , )
			}
		}
		if .IgnoreMaxTimeDiff != 0 || .IgnoreMaxValDiff != 0 {
			 = append(, "IGNORE", .IgnoreMaxTimeDiff, .IgnoreMaxValDiff)
		}
	}
	 := NewStatusCmd(, ...)
	_ = (, )
	return 
}

// TSAlter - Alters an existing time-series key with additional options.
// This function allows for specifying additional options such as:
// Retention, ChunkSize and DuplicatePolicy.
// For more information - https://redis.io/commands/ts.alter/
func ( cmdable) ( context.Context,  string,  *TSAlterOptions) *StatusCmd {
	 := []interface{}{"TS.ALTER", }
	if  != nil {
		if .Retention != 0 {
			 = append(, "RETENTION", .Retention)
		}
		if .ChunkSize != 0 {
			 = append(, "CHUNK_SIZE", .ChunkSize)
		}
		if .DuplicatePolicy != "" {
			 = append(, "DUPLICATE_POLICY", .DuplicatePolicy)
		}
		if .Labels != nil {
			 = append(, "LABELS")
			for ,  := range .Labels {
				 = append(, , )
			}
		}
		if .IgnoreMaxTimeDiff != 0 || .IgnoreMaxValDiff != 0 {
			 = append(, "IGNORE", .IgnoreMaxTimeDiff, .IgnoreMaxValDiff)
		}
	}
	 := NewStatusCmd(, ...)
	_ = (, )
	return 
}

// TSCreateRule - Creates a compaction rule from sourceKey to destKey.
// For more information - https://redis.io/commands/ts.createrule/
func ( cmdable) ( context.Context,  string,  string,  Aggregator,  int) *StatusCmd {
	 := []interface{}{"TS.CREATERULE", , , "AGGREGATION", .String(), }
	 := NewStatusCmd(, ...)
	_ = (, )
	return 
}

// TSCreateRuleWithArgs - Creates a compaction rule from sourceKey to destKey with additional option.
// This function allows for specifying additional option such as:
// alignTimestamp.
// For more information - https://redis.io/commands/ts.createrule/
func ( cmdable) ( context.Context,  string,  string,  Aggregator,  int,  *TSCreateRuleOptions) *StatusCmd {
	 := []interface{}{"TS.CREATERULE", , , "AGGREGATION", .String(), }
	if  != nil {
		if .alignTimestamp != 0 {
			 = append(, .alignTimestamp)
		}
	}
	 := NewStatusCmd(, ...)
	_ = (, )
	return 
}

// TSIncrBy - Increments the value of a time-series key by the specified timestamp.
// For more information - https://redis.io/commands/ts.incrby/
func ( cmdable) ( context.Context,  string,  float64) *IntCmd {
	 := []interface{}{"TS.INCRBY", , }
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

// TSIncrByWithArgs - Increments the value of a time-series key by the specified timestamp with additional options.
// This function allows for specifying additional options such as:
// Timestamp, Retention, ChunkSize, Uncompressed and Labels.
// For more information - https://redis.io/commands/ts.incrby/
func ( cmdable) ( context.Context,  string,  float64,  *TSIncrDecrOptions) *IntCmd {
	 := []interface{}{"TS.INCRBY", , }
	if  != nil {
		if .Timestamp != 0 {
			 = append(, "TIMESTAMP", .Timestamp)
		}
		if .Retention != 0 {
			 = append(, "RETENTION", .Retention)
		}
		if .ChunkSize != 0 {
			 = append(, "CHUNK_SIZE", .ChunkSize)
		}
		if .Uncompressed {
			 = append(, "UNCOMPRESSED")
		}
		if .DuplicatePolicy != "" {
			 = append(, "DUPLICATE_POLICY", .DuplicatePolicy)
		}
		if .Labels != nil {
			 = append(, "LABELS")
			for ,  := range .Labels {
				 = append(, , )
			}
		}
		if .IgnoreMaxTimeDiff != 0 || .IgnoreMaxValDiff != 0 {
			 = append(, "IGNORE", .IgnoreMaxTimeDiff, .IgnoreMaxValDiff)
		}
	}
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

// TSDecrBy - Decrements the value of a time-series key by the specified timestamp.
// For more information - https://redis.io/commands/ts.decrby/
func ( cmdable) ( context.Context,  string,  float64) *IntCmd {
	 := []interface{}{"TS.DECRBY", , }
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

// TSDecrByWithArgs - Decrements the value of a time-series key by the specified timestamp with additional options.
// This function allows for specifying additional options such as:
// Timestamp, Retention, ChunkSize, Uncompressed and Labels.
// For more information - https://redis.io/commands/ts.decrby/
func ( cmdable) ( context.Context,  string,  float64,  *TSIncrDecrOptions) *IntCmd {
	 := []interface{}{"TS.DECRBY", , }
	if  != nil {
		if .Timestamp != 0 {
			 = append(, "TIMESTAMP", .Timestamp)
		}
		if .Retention != 0 {
			 = append(, "RETENTION", .Retention)
		}
		if .ChunkSize != 0 {
			 = append(, "CHUNK_SIZE", .ChunkSize)
		}
		if .Uncompressed {
			 = append(, "UNCOMPRESSED")
		}
		if .DuplicatePolicy != "" {
			 = append(, "DUPLICATE_POLICY", .DuplicatePolicy)
		}
		if .Labels != nil {
			 = append(, "LABELS")
			for ,  := range .Labels {
				 = append(, , )
			}
		}
		if .IgnoreMaxTimeDiff != 0 || .IgnoreMaxValDiff != 0 {
			 = append(, "IGNORE", .IgnoreMaxTimeDiff, .IgnoreMaxValDiff)
		}
	}
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

// TSDel - Deletes a range of samples from a time-series key.
// For more information - https://redis.io/commands/ts.del/
func ( cmdable) ( context.Context,  string,  int,  int) *IntCmd {
	 := []interface{}{"TS.DEL", , , }
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

// TSDeleteRule - Deletes a compaction rule from sourceKey to destKey.
// For more information - https://redis.io/commands/ts.deleterule/
func ( cmdable) ( context.Context,  string,  string) *StatusCmd {
	 := []interface{}{"TS.DELETERULE", , }
	 := NewStatusCmd(, ...)
	_ = (, )
	return 
}

// TSGetWithArgs - Gets the last sample of a time-series key with additional option.
// This function allows for specifying additional option such as:
// Latest.
// For more information - https://redis.io/commands/ts.get/
func ( cmdable) ( context.Context,  string,  *TSGetOptions) *TSTimestampValueCmd {
	 := []interface{}{"TS.GET", }
	if  != nil {
		if .Latest {
			 = append(, "LATEST")
		}
	}
	 := newTSTimestampValueCmd(, ...)
	_ = (, )
	return 
}

// TSGet - Gets the last sample of a time-series key.
// For more information - https://redis.io/commands/ts.get/
func ( cmdable) ( context.Context,  string) *TSTimestampValueCmd {
	 := []interface{}{"TS.GET", }
	 := newTSTimestampValueCmd(, ...)
	_ = (, )
	return 
}

type TSTimestampValue struct {
	Timestamp int64
	Value     float64
	Values    []float64
}

func ( TSTimestampValue) () string {
	if len(.Values) > 0 {
		return fmt.Sprintf("{%d %v}", .Timestamp, .Values)
	}
	return fmt.Sprintf("{%d %v}", .Timestamp, .Value)
}

type TSTimestampValueCmd struct {
	baseCmd
	val TSTimestampValue
}

func newTSTimestampValueCmd( context.Context,  ...interface{}) *TSTimestampValueCmd {
	return &TSTimestampValueCmd{
		baseCmd: baseCmd{
			ctx:     ,
			args:    ,
			cmdType: CmdTypeTSTimestampValue,
		},
	}
}

func ( *TSTimestampValueCmd) () string {
	.await()
	return cmdString(, .val)
}

func ( *TSTimestampValueCmd) ( TSTimestampValue) {
	.val = 
}

func ( *TSTimestampValueCmd) () (TSTimestampValue, error) {
	.await()
	return .val, .err
}

func ( *TSTimestampValueCmd) () TSTimestampValue {
	.await()
	return .val
}

func ( *TSTimestampValueCmd) ( *proto.Reader) ( error) {
	,  := .ReadMapLen()
	if  != nil {
		return 
	}
	.val = TSTimestampValue{}
	for  := 0;  < ; ++ {
		,  := .ReadInt()
		if  != nil {
			return 
		}
		,  := .ReadString()
		if  != nil {
			return 
		}
		.val.Timestamp = 
		.val.Value,  = util.ParseStringToFloat()
		if  != nil {
			return 
		}
	}

	return nil
}

func ( *TSTimestampValueCmd) () Cmder {
	 := .val
	if .val.Values != nil {
		.Values = make([]float64, len(.val.Values))
		copy(.Values, .val.Values)
	}
	return &TSTimestampValueCmd{
		baseCmd: .cloneBaseCmd(),
		val:     ,
	}
}

// TSInfo - Returns information about a time-series key.
// For more information - https://redis.io/commands/ts.info/
func ( cmdable) ( context.Context,  string) *MapStringInterfaceCmd {
	 := []interface{}{"TS.INFO", }
	 := NewMapStringInterfaceCmd(, ...)
	_ = (, )
	return 
}

// TSInfoWithArgs - Returns information about a time-series key with additional option.
// This function allows for specifying additional option such as:
// Debug.
// For more information - https://redis.io/commands/ts.info/
func ( cmdable) ( context.Context,  string,  *TSInfoOptions) *MapStringInterfaceCmd {
	 := []interface{}{"TS.INFO", }
	if  != nil {
		if .Debug {
			 = append(, "DEBUG")
		}
	}
	 := NewMapStringInterfaceCmd(, ...)
	_ = (, )
	return 
}

// TSMAdd - Adds multiple samples to multiple time-series keys.
// It accepts a slice of 'ktv' slices, each containing exactly three elements: key, timestamp, and value.
// This struct must be provided for this command to work.
// For more information - https://redis.io/commands/ts.madd/
func ( cmdable) ( context.Context,  [][]interface{}) *IntSliceCmd {
	 := []interface{}{"TS.MADD"}
	for ,  := range  {
		 = append(, ...)
	}
	 := NewIntSliceCmd(, ...)
	_ = (, )
	return 
}

// TSQueryIndex - Returns all the keys matching the filter expression.
// For more information - https://redis.io/commands/ts.queryindex/
func ( cmdable) ( context.Context,  []string) *StringSliceCmd {
	 := []interface{}{"TS.QUERYINDEX"}
	for ,  := range  {
		 = append(, )
	}
	 := NewStringSliceCmd(, ...)
	_ = (, )
	return 
}

// TSQueryLabels - Returns the set of label names present on the time series
// matching the filter expressions. Passing no filter expressions queries all
// indexed series. The reply is unordered and already deduplicated by the
// server; it includes the label names used in the filter itself, and an
// empty reply is a valid result, not an error.
// filterExpr uses the same filter language as TSQueryIndex and is passed to
// the server verbatim. Available since Redis 8.10.
// For more information - https://redis.io/commands/ts.querylabels/
func ( cmdable) ( context.Context,  []string) *StringSliceCmd {
	 := []interface{}{"TS.QUERYLABELS", "LABELS"}
	 = appendTSFilter(, )
	 := NewStringSliceCmd(, ...)
	_ = (, )
	return 
}

// TSQueryLabelValues - Returns the set of values assigned to the given label
// name across the time series matching the filter expressions. Passing no
// filter expressions queries all indexed series. The label name is matched
// byte-exactly; a label present on no matching series yields an empty reply,
// not an error. The reply is unordered and already deduplicated by the
// server.
// filterExpr uses the same filter language as TSQueryIndex and is passed to
// the server verbatim. Available since Redis 8.10.
// For more information - https://redis.io/commands/ts.querylabels/
func ( cmdable) ( context.Context,  string,  []string) *StringSliceCmd {
	 := []interface{}{"TS.QUERYLABELS", "VALUES", }
	 = appendTSFilter(, )
	 := NewStringSliceCmd(, ...)
	_ = (, )
	return 
}

// appendTSFilter appends the FILTER token followed by the filter expressions,
// or nothing when no expressions are given: the server rejects a bare FILTER
// token, and omitting it is the documented way to query all indexed series.
func appendTSFilter( []interface{},  []string) []interface{} {
	if len() == 0 {
		return 
	}
	 = append(, "FILTER")
	for ,  := range  {
		 = append(, )
	}
	return 
}

// TSRevRange - Returns a range of samples from a time-series key in reverse order.
// For more information - https://redis.io/commands/ts.revrange/
func ( cmdable) ( context.Context,  string,  int,  int) *TSTimestampValueSliceCmd {
	 := []interface{}{"TS.REVRANGE", , , }
	 := newTSTimestampValueSliceCmd(, ...)
	_ = (, )
	return 
}

// TSRevRangeWithArgs - Returns a range of samples from a time-series key in reverse order with additional options.
// This function allows for specifying additional options such as:
// Latest, FilterByTS, FilterByValue, Count, Align, Aggregator,
// BucketDuration, BucketTimestamp and Empty.
// For more information - https://redis.io/commands/ts.revrange/
func ( cmdable) ( context.Context,  string,  int,  int,  *TSRevRangeOptions) *TSTimestampValueSliceCmd {
	 := []interface{}{"TS.REVRANGE", , , }
	if  != nil {
		if .Latest {
			 = append(, "LATEST")
		}
		if .FilterByTS != nil {
			 = append(, "FILTER_BY_TS")
			for ,  := range .FilterByTS {
				 = append(, )
			}
		}
		if .FilterByValue != nil {
			 = append(, "FILTER_BY_VALUE")
			for ,  := range .FilterByValue {
				 = append(, )
			}
		}
		if .Count != 0 {
			 = append(, "COUNT", .Count)
		}
		if .Align != nil {
			 = append(, "ALIGN", .Align)
		}
		, ,  := formatAggregationArgs(.Aggregator, .Aggregators)
		if  != nil {
			 := newTSTimestampValueSliceCmd(, ...)
			.SetErr()
			return 
		}
		if  != "" {
			 = append(, "AGGREGATION", )
		}
		if .BucketDuration != 0 {
			 = append(, .BucketDuration)
		}
		if .BucketTimestamp != nil {
			 = append(, "BUCKETTIMESTAMP", .BucketTimestamp)
		}
		if .Empty {
			 = append(, "EMPTY")
		}
	}
	 := newTSTimestampValueSliceCmd(, ...)
	_ = (, )
	return 
}

// TSRange - Returns a range of samples from a time-series key.
// For more information - https://redis.io/commands/ts.range/
func ( cmdable) ( context.Context,  string,  int,  int) *TSTimestampValueSliceCmd {
	 := []interface{}{"TS.RANGE", , , }
	 := newTSTimestampValueSliceCmd(, ...)
	_ = (, )
	return 
}

// TSRangeWithArgs - Returns a range of samples from a time-series key with additional options.
// This function allows for specifying additional options such as:
// Latest, FilterByTS, FilterByValue, Count, Align, Aggregator,
// BucketDuration, BucketTimestamp and Empty.
// For more information - https://redis.io/commands/ts.range/
func ( cmdable) ( context.Context,  string,  int,  int,  *TSRangeOptions) *TSTimestampValueSliceCmd {
	 := []interface{}{"TS.RANGE", , , }
	if  != nil {
		if .Latest {
			 = append(, "LATEST")
		}
		if .FilterByTS != nil {
			 = append(, "FILTER_BY_TS")
			for ,  := range .FilterByTS {
				 = append(, )
			}
		}
		if .FilterByValue != nil {
			 = append(, "FILTER_BY_VALUE")
			for ,  := range .FilterByValue {
				 = append(, )
			}
		}
		if .Count != 0 {
			 = append(, "COUNT", .Count)
		}
		if .Align != nil {
			 = append(, "ALIGN", .Align)
		}
		, ,  := formatAggregationArgs(.Aggregator, .Aggregators)
		if  != nil {
			 := newTSTimestampValueSliceCmd(, ...)
			.SetErr()
			return 
		}
		if  != "" {
			 = append(, "AGGREGATION", )
		}
		if .BucketDuration != 0 {
			 = append(, .BucketDuration)
		}
		if .BucketTimestamp != nil {
			 = append(, "BUCKETTIMESTAMP", .BucketTimestamp)
		}
		if .Empty {
			 = append(, "EMPTY")
		}
	}
	 := newTSTimestampValueSliceCmd(, ...)
	_ = (, )
	return 
}

// TSRead - Returns samples at or after timestamp, in ascending order.
// timestamp is a non-negative Unix-ms integer or a sentinel (TSReadEarliest,
// TSReadLatest, TSReadNew).
// For more information - https://redis.io/commands/ts.read/
func ( cmdable) ( context.Context,  string,  interface{}) *TSTimestampValueSliceCmd {
	 := []interface{}{"TS.READ", , }
	 := newTSTimestampValueSliceCmd(, ...)
	_ = (, )
	return 
}

// TSReadWithArgs - TS.READ with the optional BLOCK and MAX_COUNT groups.
// When options.Block is set it waits for options.MinCount samples or until
// options.Timeout elapses. Blocking calls must not be used in a pipeline or MULTI.
// For more information - https://redis.io/commands/ts.read/
func ( cmdable) ( context.Context,  string,  interface{},  *TSReadOptions) *TSTimestampValueSliceCmd {
	 := []interface{}{"TS.READ", , }
	 := false
	var  time.Duration
	if  != nil {
		if .Block {
			 = true
			 = .Timeout
			 := .MinCount
			if  <= 0 {
				 = 1
			}
			 = append(, "BLOCK", formatMs(, .Timeout), )
		}
		if .MaxCount != 0 {
			 = append(, "MAX_COUNT", .MaxCount)
		}
	}
	 := newTSTimestampValueSliceCmd(, ...)
	if  {
		.setReadTimeout()
	}
	_ = (, )
	return 
}

type TSTimestampValueSliceCmd struct {
	baseCmd
	val []TSTimestampValue
}

func newTSTimestampValueSliceCmd( context.Context,  ...interface{}) *TSTimestampValueSliceCmd {
	return &TSTimestampValueSliceCmd{
		baseCmd: baseCmd{
			ctx:     ,
			args:    ,
			cmdType: CmdTypeTSTimestampValueSlice,
		},
	}
}

func ( *TSTimestampValueSliceCmd) () string {
	.await()
	return cmdString(, .val)
}

func ( *TSTimestampValueSliceCmd) ( []TSTimestampValue) {
	.val = 
}

func ( *TSTimestampValueSliceCmd) () ([]TSTimestampValue, error) {
	.await()
	return .val, .err
}

func ( *TSTimestampValueSliceCmd) () []TSTimestampValue {
	.await()
	return .val
}

func ( *TSTimestampValueSliceCmd) ( *proto.Reader) ( error) {
	,  := .ReadArrayLen()
	if  != nil {
		return 
	}
	.val = make([]TSTimestampValue, )
	for  := 0;  < ; ++ {
		,  := .ReadArrayLen()
		if  != nil {
			return 
		}
		if  < 1 {
			return fmt.Errorf("redis: got %d elements in timeseries sample, expected at least 1", )
		}

		,  := .ReadInt()
		if  != nil {
			return 
		}
		.val[].Timestamp = 
		if  == 2 {
			,  := .ReadString()
			if  != nil {
				return 
			}
			.val[].Value,  = util.ParseStringToFloat()
			if  != nil {
				return 
			}
			continue
		}

		.val[].Values = make([]float64, -1)
		for  := 0;  < -1; ++ {
			,  := .ReadString()
			if  != nil {
				return 
			}
			.val[].Values[],  = util.ParseStringToFloat()
			if  != nil {
				return 
			}
		}
	}

	return nil
}

func ( *TSTimestampValueSliceCmd) () Cmder {
	var  []TSTimestampValue
	if .val != nil {
		 = make([]TSTimestampValue, len(.val))
		copy(, .val)
		for  := range .val {
			if .val[].Values != nil {
				[].Values = make([]float64, len(.val[].Values))
				copy([].Values, .val[].Values)
			}
		}
	}
	return &TSTimestampValueSliceCmd{
		baseCmd: .cloneBaseCmd(),
		val:     ,
	}
}

// TSMRange - Returns a range of samples from multiple time-series keys.
// For more information - https://redis.io/commands/ts.mrange/
func ( cmdable) ( context.Context,  int,  int,  []string) *MapStringSliceInterfaceCmd {
	 := []interface{}{"TS.MRANGE", , , "FILTER"}
	for ,  := range  {
		 = append(, )
	}
	 := NewMapStringSliceInterfaceCmd(, ...)
	_ = (, )
	return 
}

// TSMRangeWithArgs - Returns a range of samples from multiple time-series keys.
// Options are set via TSMRangeOptions.
// For more information - https://redis.io/commands/ts.mrange/
func ( cmdable) ( context.Context,  int,  int,  []string,  *TSMRangeOptions) *MapStringSliceInterfaceCmd {
	 := []interface{}{"TS.MRANGE", , }
	 := 0
	if  != nil {
		if .Latest {
			 = append(, "LATEST")
		}
		if .FilterByTS != nil {
			 = append(, "FILTER_BY_TS")
			for ,  := range .FilterByTS {
				 = append(, )
			}
		}
		if .FilterByValue != nil {
			 = append(, "FILTER_BY_VALUE")
			for ,  := range .FilterByValue {
				 = append(, )
			}
		}
		if .WithLabels {
			 = append(, "WITHLABELS")
		}
		if .SelectedLabels != nil {
			 = append(, "SELECTED_LABELS")
			 = append(, .SelectedLabels...)
		}
		if .Count != 0 {
			 = append(, "COUNT", .Count)
		}
		if .Align != nil {
			 = append(, "ALIGN", .Align)
		}
		, ,  := formatAggregationArgs(.Aggregator, .Aggregators)
		if  != nil {
			 := NewMapStringSliceInterfaceCmd(, ...)
			.SetErr()
			return 
		}
		 = 
		if  != "" {
			 = append(, "AGGREGATION", )
		}
		if .BucketDuration != 0 {
			 = append(, .BucketDuration)
		}
		if .BucketTimestamp != nil {
			 = append(, "BUCKETTIMESTAMP", .BucketTimestamp)
		}
		if .Empty {
			 = append(, "EMPTY")
		}
		if .ExcludeEmpty {
			 = append(, "EXCLUDEEMPTY")
		}
	}
	 = append(, "FILTER")
	for ,  := range  {
		 = append(, )
	}
	if  != nil {
		if .ExcludeEmpty && (.GroupByLabel != nil || .Reducer != nil) {
			 := NewMapStringSliceInterfaceCmd(, ...)
			.SetErr(errTSExcludeEmptyGroupBy)
			return 
		}
		if  > 1 && (.GroupByLabel != nil || .Reducer != nil) {
			 := NewMapStringSliceInterfaceCmd(, ...)
			.SetErr(errTSMultiAggregationGroupBy)
			return 
		}
		if .GroupByLabel != nil {
			 = append(, "GROUPBY", .GroupByLabel)
		}
		if .Reducer != nil {
			 = append(, "REDUCE", .Reducer)
		}
	}
	 := NewMapStringSliceInterfaceCmd(, ...)
	_ = (, )
	return 
}

// TSMRevRange - Returns a range of samples from multiple time-series keys in reverse order.
// For more information - https://redis.io/commands/ts.mrevrange/
func ( cmdable) ( context.Context,  int,  int,  []string) *MapStringSliceInterfaceCmd {
	 := []interface{}{"TS.MREVRANGE", , , "FILTER"}
	for ,  := range  {
		 = append(, )
	}
	 := NewMapStringSliceInterfaceCmd(, ...)
	_ = (, )
	return 
}

// TSMRevRangeWithArgs - Returns a range of samples from multiple time-series keys in reverse order.
// Options are set via TSMRevRangeOptions.
// For more information - https://redis.io/commands/ts.mrevrange/
func ( cmdable) ( context.Context,  int,  int,  []string,  *TSMRevRangeOptions) *MapStringSliceInterfaceCmd {
	 := []interface{}{"TS.MREVRANGE", , }
	 := 0
	if  != nil {
		if .Latest {
			 = append(, "LATEST")
		}
		if .FilterByTS != nil {
			 = append(, "FILTER_BY_TS")
			for ,  := range .FilterByTS {
				 = append(, )
			}
		}
		if .FilterByValue != nil {
			 = append(, "FILTER_BY_VALUE")
			for ,  := range .FilterByValue {
				 = append(, )
			}
		}
		if .WithLabels {
			 = append(, "WITHLABELS")
		}
		if .SelectedLabels != nil {
			 = append(, "SELECTED_LABELS")
			 = append(, .SelectedLabels...)
		}
		if .Count != 0 {
			 = append(, "COUNT", .Count)
		}
		if .Align != nil {
			 = append(, "ALIGN", .Align)
		}
		, ,  := formatAggregationArgs(.Aggregator, .Aggregators)
		if  != nil {
			 := NewMapStringSliceInterfaceCmd(, ...)
			.SetErr()
			return 
		}
		 = 
		if  != "" {
			 = append(, "AGGREGATION", )
		}
		if .BucketDuration != 0 {
			 = append(, .BucketDuration)
		}
		if .BucketTimestamp != nil {
			 = append(, "BUCKETTIMESTAMP", .BucketTimestamp)
		}
		if .Empty {
			 = append(, "EMPTY")
		}
		if .ExcludeEmpty {
			 = append(, "EXCLUDEEMPTY")
		}
	}
	 = append(, "FILTER")
	for ,  := range  {
		 = append(, )
	}
	if  != nil {
		if .ExcludeEmpty && (.GroupByLabel != nil || .Reducer != nil) {
			 := NewMapStringSliceInterfaceCmd(, ...)
			.SetErr(errTSExcludeEmptyGroupBy)
			return 
		}
		if  > 1 && (.GroupByLabel != nil || .Reducer != nil) {
			 := NewMapStringSliceInterfaceCmd(, ...)
			.SetErr(errTSMultiAggregationGroupBy)
			return 
		}
		if .GroupByLabel != nil {
			 = append(, "GROUPBY", .GroupByLabel)
		}
		if .Reducer != nil {
			 = append(, "REDUCE", .Reducer)
		}
	}
	 := NewMapStringSliceInterfaceCmd(, ...)
	_ = (, )
	return 
}

// TSMGet - Returns the last sample of multiple time-series keys.
// For more information - https://redis.io/commands/ts.mget/
func ( cmdable) ( context.Context,  []string) *MapStringSliceInterfaceCmd {
	 := []interface{}{"TS.MGET", "FILTER"}
	for ,  := range  {
		 = append(, )
	}
	 := NewMapStringSliceInterfaceCmd(, ...)
	_ = (, )
	return 
}

// TSMGetWithArgs - Returns the last sample of multiple time-series keys with additional options.
// This function allows for specifying additional options such as:
// Latest, WithLabels and SelectedLabels.
// For more information - https://redis.io/commands/ts.mget/
func ( cmdable) ( context.Context,  []string,  *TSMGetOptions) *MapStringSliceInterfaceCmd {
	 := []interface{}{"TS.MGET"}
	if  != nil {
		if .Latest {
			 = append(, "LATEST")
		}
		if .WithLabels {
			 = append(, "WITHLABELS")
		}
		if .SelectedLabels != nil {
			 = append(, "SELECTED_LABELS")
			 = append(, .SelectedLabels...)
		}
	}
	 = append(, "FILTER")
	for ,  := range  {
		 = append(, )
	}
	 := NewMapStringSliceInterfaceCmd(, ...)
	_ = (, )
	return 
}

// TSNRangePivotRow represents a single row in the pivot response from TS.NRANGE / TS.NREVRANGE.
// Timestamp is the row's timestamp. Without aggregation, Values holds one float64 per input key
// in input-key order. With aggregation, Values holds one float64 per requested (key, aggregator)
// pair, flattened in input-key order with each key's aggregators in spec order.
// Missing samples and missing aggregation buckets are represented as NaN.
type TSNRangePivotRow struct {
	Timestamp int64
	Values    []float64
}

type TSNRangePivotRowSliceCmd struct {
	baseCmd
	val []TSNRangePivotRow
}

func newTSNRangePivotRowSliceCmd( context.Context,  ...interface{}) *TSNRangePivotRowSliceCmd {
	return &TSNRangePivotRowSliceCmd{
		baseCmd: baseCmd{
			ctx:     ,
			args:    ,
			cmdType: CmdTypeTSNRangePivotRowSlice,
		},
	}
}

func ( *TSNRangePivotRowSliceCmd) () string {
	.await()
	return cmdString(, .val)
}

func ( *TSNRangePivotRowSliceCmd) ( []TSNRangePivotRow) {
	.val = 
}

func ( *TSNRangePivotRowSliceCmd) () ([]TSNRangePivotRow, error) {
	.await()
	return .val, .err
}

func ( *TSNRangePivotRowSliceCmd) () []TSNRangePivotRow {
	.await()
	return .val
}

func ( *TSNRangePivotRowSliceCmd) ( *proto.Reader) error {
	,  := .ReadArrayLen()
	if  != nil {
		return 
	}
	.val = make([]TSNRangePivotRow, )
	for  := 0;  < ; ++ {
		// Each row is a 2-element array: [timestamp, [value_0, value_1, ...]]
		if _,  = .ReadArrayLen();  != nil {
			return 
		}
		,  := .ReadInt()
		if  != nil {
			return 
		}
		.val[].Timestamp = 

		,  := .ReadArrayLen()
		if  != nil {
			return 
		}
		.val[].Values = make([]float64, )
		for  := 0;  < ; ++ {
			,  := .ReadString()
			if  != nil {
				return 
			}
			.val[].Values[],  = util.ParseStringToFloat()
			if  != nil {
				return 
			}
		}
	}
	return nil
}

func ( *TSNRangePivotRowSliceCmd) () Cmder {
	var  []TSNRangePivotRow
	if .val != nil {
		 = make([]TSNRangePivotRow, len(.val))
		copy(, .val)
		for  := range .val {
			if .val[].Values != nil {
				[].Values = make([]float64, len(.val[].Values))
				copy([].Values, .val[].Values)
			}
		}
	}
	return &TSNRangePivotRowSliceCmd{
		baseCmd: .cloneBaseCmd(),
		val:     ,
	}
}

// buildNRangeAggregationArgs validates and returns one aggregator spec string per key for
// TS.NRANGE / TS.NREVRANGE. The number of specs must equal the number of keys. Each spec
// lists one or more aggregators for its key and is emitted as a single comma-joined wire
// token; specs for different keys are separate wire tokens.
func buildNRangeAggregationArgs( []string,  [][]Aggregator) ([]string, error) {
	if len() != len() {
		return nil, fmt.Errorf("redis: TS.NRANGE/TS.NREVRANGE requires exactly %d aggregator spec(s), got %d", len(), len())
	}
	 := make([]string, len())
	for ,  := range  {
		if len() == 0 {
			return nil, fmt.Errorf("redis: empty timeseries aggregator spec at index %d", )
		}
		 := make([]string, len())
		for ,  := range  {
			if  == Invalid {
				return nil, fmt.Errorf("redis: invalid timeseries aggregator at index %d[%d]: Invalid (%d)", , , )
			}
			 := .String()
			if  == "" {
				return nil, fmt.Errorf("redis: invalid timeseries aggregator at index %d[%d]: %d", , , )
			}
			[] = 
		}
		[] = strings.Join(, ",")
	}
	return , nil
}

// appendNRangeOptions appends optional TS.NRANGE / TS.NREVRANGE arguments to args.
func appendNRangeOptions(
	 []interface{},
	 []string,
	 bool,
	 []int,
	 []float64,
	 int,
	 interface{},
	 [][]Aggregator,
	 int,
	 interface{},
	 bool,
) ([]interface{}, error) {
	if  {
		 = append(, "LATEST")
	}
	if len() > 0 {
		 = append(, "FILTER_BY_TS")
		for ,  := range  {
			 = append(, )
		}
	}
	if len() > 0 {
		if len() != 2 {
			return , fmt.Errorf("redis: FILTER_BY_VALUE requires exactly 2 elements [min, max], got %d", len())
		}
		 = append(, "FILTER_BY_VALUE", [0], [1])
	}
	if  != 0 {
		 = append(, "COUNT", )
	}
	if  != nil {
		 = append(, "ALIGN", )
	}
	if len() > 0 {
		,  := buildNRangeAggregationArgs(, )
		if  != nil {
			return , 
		}
		 = append(, "AGGREGATION")
		for ,  := range  {
			 = append(, )
		}
		if  != 0 {
			 = append(, )
		}
		if  != nil {
			 = append(, "BUCKETTIMESTAMP", )
		}
		if  {
			 = append(, "EMPTY")
		}
	}
	return , nil
}

// TSNRange - Queries multiple time-series keys and returns a pivot response in forward (ascending) order.
// For more information - https://redis.io/commands/ts.nrange/
func ( cmdable) ( context.Context,  []string,  interface{},  interface{}) *TSNRangePivotRowSliceCmd {
	 := make([]interface{}, 0, 3+len())
	 = append(, "TS.NRANGE", len())
	for ,  := range  {
		 = append(, )
	}
	 = append(, , )
	 := newTSNRangePivotRowSliceCmd(, ...)
	.SetFirstKeyPos(2)
	_ = (, )
	return 
}

// TSNRangeWithArgs - Queries multiple time-series keys and returns a pivot response in forward (ascending) order with additional options.
// This function allows for specifying additional options such as:
// Latest, FilterByTS, FilterByValue, Count, Align, Aggregators, BucketDuration, BucketTimestamp and Empty.
// Aggregators must contain exactly one spec per key; each spec lists one or more aggregators
// for its key and is emitted as a single comma-joined wire token.
// For more information - https://redis.io/commands/ts.nrange/
func ( cmdable) ( context.Context,  []string,  interface{},  interface{},  *TSNRangeOptions) *TSNRangePivotRowSliceCmd {
	 := make([]interface{}, 0, 3+len())
	 = append(, "TS.NRANGE", len())
	for ,  := range  {
		 = append(, )
	}
	 = append(, , )
	if  != nil {
		var  error
		,  = appendNRangeOptions(, ,
			.Latest, .FilterByTS, .FilterByValue,
			.Count, .Align, .Aggregators,
			.BucketDuration, .BucketTimestamp, .Empty)
		if  != nil {
			 := newTSNRangePivotRowSliceCmd(, ...)
			.SetErr()
			return 
		}
	}
	 := newTSNRangePivotRowSliceCmd(, ...)
	.SetFirstKeyPos(2)
	_ = (, )
	return 
}

// TSNRevRange - Queries multiple time-series keys and returns a pivot response in reverse (descending) order.
// For more information - https://redis.io/commands/ts.nrevrange/
func ( cmdable) ( context.Context,  []string,  interface{},  interface{}) *TSNRangePivotRowSliceCmd {
	 := make([]interface{}, 0, 3+len())
	 = append(, "TS.NREVRANGE", len())
	for ,  := range  {
		 = append(, )
	}
	 = append(, , )
	 := newTSNRangePivotRowSliceCmd(, ...)
	.SetFirstKeyPos(2)
	_ = (, )
	return 
}

// TSNRevRangeWithArgs - Queries multiple time-series keys and returns a pivot response in reverse (descending) order with additional options.
// This function allows for specifying additional options such as:
// Latest, FilterByTS, FilterByValue, Count, Align, Aggregators, BucketDuration, BucketTimestamp and Empty.
// Aggregators must contain exactly one spec per key; each spec lists one or more aggregators
// for its key and is emitted as a single comma-joined wire token.
// For more information - https://redis.io/commands/ts.nrevrange/
func ( cmdable) ( context.Context,  []string,  interface{},  interface{},  *TSNRevRangeOptions) *TSNRangePivotRowSliceCmd {
	 := make([]interface{}, 0, 3+len())
	 = append(, "TS.NREVRANGE", len())
	for ,  := range  {
		 = append(, )
	}
	 = append(, , )
	if  != nil {
		var  error
		,  = appendNRangeOptions(, ,
			.Latest, .FilterByTS, .FilterByValue,
			.Count, .Align, .Aggregators,
			.BucketDuration, .BucketTimestamp, .Empty)
		if  != nil {
			 := newTSNRangePivotRowSliceCmd(, ...)
			.SetErr()
			return 
		}
	}
	 := newTSNRangePivotRowSliceCmd(, ...)
	.SetFirstKeyPos(2)
	_ = (, )
	return 
}