package redis

import (
	
	

	
)

type GenericCmdable interface {
	Del(ctx context.Context, keys ...string) *IntCmd
	Dump(ctx context.Context, key string) *StringCmd
	Exists(ctx context.Context, keys ...string) *IntCmd
	Expire(ctx context.Context, key string, expiration time.Duration) *BoolCmd
	ExpireAt(ctx context.Context, key string, tm time.Time) *BoolCmd
	ExpireTime(ctx context.Context, key string) *DurationCmd
	ExpireNX(ctx context.Context, key string, expiration time.Duration) *BoolCmd
	ExpireXX(ctx context.Context, key string, expiration time.Duration) *BoolCmd
	ExpireGT(ctx context.Context, key string, expiration time.Duration) *BoolCmd
	ExpireLT(ctx context.Context, key string, expiration time.Duration) *BoolCmd
	Keys(ctx context.Context, pattern string) *StringSliceCmd
	Migrate(ctx context.Context, host, port, key string, db int, timeout time.Duration) *StatusCmd
	Move(ctx context.Context, key string, db int) *BoolCmd
	ObjectFreq(ctx context.Context, key string) *IntCmd
	ObjectRefCount(ctx context.Context, key string) *IntCmd
	ObjectEncoding(ctx context.Context, key string) *StringCmd
	ObjectIdleTime(ctx context.Context, key string) *DurationCmd
	Persist(ctx context.Context, key string) *BoolCmd
	PExpire(ctx context.Context, key string, expiration time.Duration) *BoolCmd
	PExpireAt(ctx context.Context, key string, tm time.Time) *BoolCmd
	PExpireTime(ctx context.Context, key string) *DurationCmd
	PTTL(ctx context.Context, key string) *DurationCmd
	RandomKey(ctx context.Context) *StringCmd
	Rename(ctx context.Context, key, newkey string) *StatusCmd
	RenameNX(ctx context.Context, key, newkey string) *BoolCmd
	Restore(ctx context.Context, key string, ttl time.Duration, value string) *StatusCmd
	RestoreReplace(ctx context.Context, key string, ttl time.Duration, value string) *StatusCmd
	Sort(ctx context.Context, key string, sort *Sort) *StringSliceCmd
	SortRO(ctx context.Context, key string, sort *Sort) *StringSliceCmd
	SortStore(ctx context.Context, key, store string, sort *Sort) *IntCmd
	SortInterfaces(ctx context.Context, key string, sort *Sort) *SliceCmd
	Touch(ctx context.Context, keys ...string) *IntCmd
	TTL(ctx context.Context, key string) *DurationCmd
	Type(ctx context.Context, key string) *StatusCmd
	Copy(ctx context.Context, sourceKey string, destKey string, db int, replace bool) *IntCmd

	Scan(ctx context.Context, cursor uint64, match string, count int64) *ScanCmd
	ScanType(ctx context.Context, cursor uint64, match string, count int64, keyType string) *ScanCmd
}

func ( cmdable) ( context.Context,  ...string) *IntCmd {
	 := make([]interface{}, 1+len())
	[0] = "del"
	for ,  := range  {
		[1+] = 
	}
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  ...string) *IntCmd {
	 := make([]interface{}, 1+len())
	[0] = "unlink"
	for ,  := range  {
		[1+] = 
	}
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string) *StringCmd {
	 := NewStringCmd(, "dump", )
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  ...string) *IntCmd {
	 := make([]interface{}, 1+len())
	[0] = "exists"
	for ,  := range  {
		[1+] = 
	}
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  time.Duration) *BoolCmd {
	return .expire(, , , "")
}

func ( cmdable) ( context.Context,  string,  time.Duration) *BoolCmd {
	return .expire(, , , "NX")
}

func ( cmdable) ( context.Context,  string,  time.Duration) *BoolCmd {
	return .expire(, , , "XX")
}

func ( cmdable) ( context.Context,  string,  time.Duration) *BoolCmd {
	return .expire(, , , "GT")
}

func ( cmdable) ( context.Context,  string,  time.Duration) *BoolCmd {
	return .expire(, , , "LT")
}

func ( cmdable) (
	 context.Context,  string,  time.Duration,  string,
) *BoolCmd {
	 := make([]interface{}, 3, 4)
	[0] = "expire"
	[1] = 
	[2] = formatSec(, )
	if  != "" {
		 = append(, )
	}

	 := NewBoolCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  time.Time) *BoolCmd {
	 := NewBoolCmd(, "expireat", , .Unix())
	_ = (, )
	return 
}

// ExpireTime returns the absolute expiration time of key as a Unix timestamp
// encoded in *DurationCmd (seconds since the epoch), not a remaining TTL.
// Convert with: time.Unix(int64(d/time.Second), 0). Use TTL/PTTL for remaining TTL.
func ( cmdable) ( context.Context,  string) *DurationCmd {
	 := NewDurationCmd(, time.Second, "expiretime", )
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string) *StringSliceCmd {
	 := NewStringSliceCmd(, "keys", )
	_ = (, )
	return 
}

func ( cmdable) ( context.Context, , ,  string,  int,  time.Duration) *StatusCmd {
	 := NewStatusCmd(
		,
		"migrate",
		,
		,
		,
		,
		formatMs(, ),
	)
	.SetFirstKeyPos(3) // the key is not args[1]: route by it
	.setReadTimeout()
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  int) *BoolCmd {
	 := NewBoolCmd(, "move", , )
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string) *IntCmd {
	 := NewIntCmd(, "object", "freq", )
	.SetFirstKeyPos(2) // the key is not args[1]: route by it
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string) *IntCmd {
	 := NewIntCmd(, "object", "refcount", )
	.SetFirstKeyPos(2) // the key is not args[1]: route by it
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string) *StringCmd {
	 := NewStringCmd(, "object", "encoding", )
	.SetFirstKeyPos(2) // the key is not args[1]: route by it
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string) *DurationCmd {
	 := NewDurationCmd(, time.Second, "object", "idletime", )
	.SetFirstKeyPos(2) // the key is not args[1]: route by it
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string) *BoolCmd {
	 := NewBoolCmd(, "persist", )
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  time.Duration) *BoolCmd {
	 := NewBoolCmd(, "pexpire", , formatMs(, ))
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  time.Time) *BoolCmd {
	 := NewBoolCmd(
		,
		"pexpireat",
		,
		.UnixMilli(),
	)
	_ = (, )
	return 
}

// PExpireTime returns the absolute expiration time of key as a Unix timestamp
// encoded in *DurationCmd (milliseconds since the epoch), not a remaining TTL.
// Convert with: time.UnixMilli(int64(d/time.Millisecond)). Use TTL/PTTL for remaining TTL.
func ( cmdable) ( context.Context,  string) *DurationCmd {
	 := NewDurationCmd(, time.Millisecond, "pexpiretime", )
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string) *DurationCmd {
	 := NewDurationCmd(, time.Millisecond, "pttl", )
	_ = (, )
	return 
}

func ( cmdable) ( context.Context) *StringCmd {
	 := NewStringCmd(, "randomkey")
	_ = (, )
	return 
}

func ( cmdable) ( context.Context, ,  string) *StatusCmd {
	 := NewStatusCmd(, "rename", , )
	_ = (, )
	return 
}

func ( cmdable) ( context.Context, ,  string) *BoolCmd {
	 := NewBoolCmd(, "renamenx", , )
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  time.Duration,  string) *StatusCmd {
	 := NewStatusCmd(
		,
		"restore",
		,
		formatMs(, ),
		,
	)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  time.Duration,  string) *StatusCmd {
	 := NewStatusCmd(
		,
		"restore",
		,
		formatMs(, ),
		,
		"replace",
	)
	_ = (, )
	return 
}

type Sort struct {
	By            string
	Offset, Count int64
	Get           []string
	Order         string
	Alpha         bool
}

func ( *Sort) (,  string) []interface{} {
	 := []interface{}{, }

	if .By != "" {
		 = append(, "by", .By)
	}
	if .Offset != 0 || .Count != 0 {
		 = append(, "limit", .Offset, .Count)
	}
	for ,  := range .Get {
		 = append(, "get", )
	}
	if .Order != "" {
		 = append(, .Order)
	}
	if .Alpha {
		 = append(, "alpha")
	}
	return 
}

func ( cmdable) ( context.Context,  string,  *Sort) *StringSliceCmd {
	 := NewStringSliceCmd(, .args("sort_ro", )...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  *Sort) *StringSliceCmd {
	 := NewStringSliceCmd(, .args("sort", )...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context, ,  string,  *Sort) *IntCmd {
	 := .args("sort", )
	if  != "" {
		 = append(, "store", )
	}
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string,  *Sort) *SliceCmd {
	 := NewSliceCmd(, .args("sort", )...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  ...string) *IntCmd {
	 := make([]interface{}, len()+1)
	[0] = "touch"
	for ,  := range  {
		[+1] = 
	}
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string) *DurationCmd {
	 := NewDurationCmd(, time.Second, "ttl", )
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  string) *StatusCmd {
	 := NewStatusCmd(, "type", )
	_ = (, )
	return 
}

func ( cmdable) ( context.Context, ,  string,  int,  bool) *IntCmd {
	 := []interface{}{"copy", , , "DB", }
	if  {
		 = append(, "REPLACE")
	}
	 := NewIntCmd(, ...)
	_ = (, )
	return 
}

//------------------------------------------------------------------------------

func ( cmdable) ( context.Context,  uint64,  string,  int64) *ScanCmd {
	 := []interface{}{"scan", }
	if  != "" {
		 = append(, "match", )
	}
	if  > 0 {
		 = append(, "count", )
	}
	 := NewScanCmd(, , ...)
	if hashtag.Present() {
		.SetFirstKeyPos(3)
	}
	_ = (, )
	return 
}

func ( cmdable) ( context.Context,  uint64,  string,  int64,  string) *ScanCmd {
	 := []interface{}{"scan", }
	if  != "" {
		 = append(, "match", )
	}
	if  > 0 {
		 = append(, "count", )
	}
	if  != "" {
		 = append(, "type", )
	}
	 := NewScanCmd(, , ...)
	if hashtag.Present() {
		.SetFirstKeyPos(3)
	}
	_ = (, )
	return 
}