forked from ebhomengo/niki
1
0
Fork 0
niki/vendor/github.com/redis/go-redis/v9/gears_commands.go

258 lines
4.6 KiB
Go
Raw Normal View History

2024-02-18 10:42:21 +00:00
package redis
import (
"context"
"fmt"
"strings"
)
type GearsCmdable interface {
TFunctionLoad(ctx context.Context, lib string) *StatusCmd
2024-02-18 10:42:21 +00:00
TFunctionLoadArgs(ctx context.Context, lib string, options *TFunctionLoadOptions) *StatusCmd
2024-02-18 10:42:21 +00:00
TFunctionDelete(ctx context.Context, libName string) *StatusCmd
2024-02-18 10:42:21 +00:00
TFunctionList(ctx context.Context) *MapStringInterfaceSliceCmd
2024-02-18 10:42:21 +00:00
TFunctionListArgs(ctx context.Context, options *TFunctionListOptions) *MapStringInterfaceSliceCmd
2024-02-18 10:42:21 +00:00
TFCall(ctx context.Context, libName string, funcName string, numKeys int) *Cmd
2024-02-18 10:42:21 +00:00
TFCallArgs(ctx context.Context, libName string, funcName string, numKeys int, options *TFCallOptions) *Cmd
2024-02-18 10:42:21 +00:00
TFCallASYNC(ctx context.Context, libName string, funcName string, numKeys int) *Cmd
2024-02-18 10:42:21 +00:00
TFCallASYNCArgs(ctx context.Context, libName string, funcName string, numKeys int, options *TFCallOptions) *Cmd
}
type TFunctionLoadOptions struct {
Replace bool
Config string
2024-02-18 10:42:21 +00:00
}
type TFunctionListOptions struct {
Withcode bool
Verbose int
Library string
2024-02-18 10:42:21 +00:00
}
type TFCallOptions struct {
Keys []string
2024-02-18 10:42:21 +00:00
Arguments []string
}
// TFunctionLoad - load a new JavaScript library into Redis.
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/tfunction-load/
2024-02-18 10:42:21 +00:00
func (c cmdable) TFunctionLoad(ctx context.Context, lib string) *StatusCmd {
2024-02-18 10:42:21 +00:00
args := []interface{}{"TFUNCTION", "LOAD", lib}
2024-02-18 10:42:21 +00:00
cmd := NewStatusCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) TFunctionLoadArgs(ctx context.Context, lib string, options *TFunctionLoadOptions) *StatusCmd {
2024-02-18 10:42:21 +00:00
args := []interface{}{"TFUNCTION", "LOAD"}
2024-02-18 10:42:21 +00:00
if options != nil {
2024-02-18 10:42:21 +00:00
if options.Replace {
2024-02-18 10:42:21 +00:00
args = append(args, "REPLACE")
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
if options.Config != "" {
2024-02-18 10:42:21 +00:00
args = append(args, "CONFIG", options.Config)
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
args = append(args, lib)
2024-02-18 10:42:21 +00:00
cmd := NewStatusCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
// TFunctionDelete - delete a JavaScript library from Redis.
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/tfunction-delete/
2024-02-18 10:42:21 +00:00
func (c cmdable) TFunctionDelete(ctx context.Context, libName string) *StatusCmd {
2024-02-18 10:42:21 +00:00
args := []interface{}{"TFUNCTION", "DELETE", libName}
2024-02-18 10:42:21 +00:00
cmd := NewStatusCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
// TFunctionList - list the functions with additional information about each function.
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/tfunction-list/
2024-02-18 10:42:21 +00:00
func (c cmdable) TFunctionList(ctx context.Context) *MapStringInterfaceSliceCmd {
2024-02-18 10:42:21 +00:00
args := []interface{}{"TFUNCTION", "LIST"}
2024-02-18 10:42:21 +00:00
cmd := NewMapStringInterfaceSliceCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) TFunctionListArgs(ctx context.Context, options *TFunctionListOptions) *MapStringInterfaceSliceCmd {
2024-02-18 10:42:21 +00:00
args := []interface{}{"TFUNCTION", "LIST"}
2024-02-18 10:42:21 +00:00
if options != nil {
2024-02-18 10:42:21 +00:00
if options.Withcode {
2024-02-18 10:42:21 +00:00
args = append(args, "WITHCODE")
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
if options.Verbose != 0 {
2024-02-18 10:42:21 +00:00
v := strings.Repeat("v", options.Verbose)
2024-02-18 10:42:21 +00:00
args = append(args, v)
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
if options.Library != "" {
2024-02-18 10:42:21 +00:00
args = append(args, "LIBRARY", options.Library)
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
cmd := NewMapStringInterfaceSliceCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
// TFCall - invoke a function.
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/tfcall/
2024-02-18 10:42:21 +00:00
func (c cmdable) TFCall(ctx context.Context, libName string, funcName string, numKeys int) *Cmd {
2024-02-18 10:42:21 +00:00
lf := libName + "." + funcName
2024-02-18 10:42:21 +00:00
args := []interface{}{"TFCALL", lf, numKeys}
2024-02-18 10:42:21 +00:00
cmd := NewCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) TFCallArgs(ctx context.Context, libName string, funcName string, numKeys int, options *TFCallOptions) *Cmd {
2024-02-18 10:42:21 +00:00
lf := libName + "." + funcName
2024-02-18 10:42:21 +00:00
args := []interface{}{"TFCALL", lf, numKeys}
2024-02-18 10:42:21 +00:00
if options != nil {
2024-02-18 10:42:21 +00:00
for _, key := range options.Keys {
2024-02-18 10:42:21 +00:00
args = append(args, key)
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
for _, key := range options.Arguments {
2024-02-18 10:42:21 +00:00
args = append(args, key)
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
cmd := NewCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
// TFCallASYNC - invoke an asynchronous JavaScript function (coroutine).
2024-02-18 10:42:21 +00:00
// For more information - https://redis.io/commands/TFCallASYNC/
2024-02-18 10:42:21 +00:00
func (c cmdable) TFCallASYNC(ctx context.Context, libName string, funcName string, numKeys int) *Cmd {
2024-02-18 10:42:21 +00:00
lf := fmt.Sprintf("%s.%s", libName, funcName)
2024-02-18 10:42:21 +00:00
args := []interface{}{"TFCALLASYNC", lf, numKeys}
2024-02-18 10:42:21 +00:00
cmd := NewCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}
func (c cmdable) TFCallASYNCArgs(ctx context.Context, libName string, funcName string, numKeys int, options *TFCallOptions) *Cmd {
2024-02-18 10:42:21 +00:00
lf := fmt.Sprintf("%s.%s", libName, funcName)
2024-02-18 10:42:21 +00:00
args := []interface{}{"TFCALLASYNC", lf, numKeys}
2024-02-18 10:42:21 +00:00
if options != nil {
2024-02-18 10:42:21 +00:00
for _, key := range options.Keys {
2024-02-18 10:42:21 +00:00
args = append(args, key)
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
for _, key := range options.Arguments {
2024-02-18 10:42:21 +00:00
args = append(args, key)
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
cmd := NewCmd(ctx, args...)
2024-02-18 10:42:21 +00:00
_ = c(ctx, cmd)
2024-02-18 10:42:21 +00:00
return cmd
2024-02-18 10:42:21 +00:00
}