From e9bc3436d5dc22f40ca5966648ec6676ecaaeaeb Mon Sep 17 00:00:00 2001 From: ofekshenawa Date: Mon, 14 Aug 2023 17:22:00 +0300 Subject: [PATCH 1/5] Add gears commands and tests --- command.go | 64 +++++++++++++++++++ commands.go | 2 + redis_gears.go | 149 ++++++++++++++++++++++++++++++++++++++++++++ redis_gears_test.go | 135 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 350 insertions(+) create mode 100644 redis_gears.go create mode 100644 redis_gears_test.go diff --git a/command.go b/command.go index b6df28fbe..ae74a1690 100644 --- a/command.go +++ b/command.go @@ -3713,6 +3713,70 @@ func (cmd *MapStringStringSliceCmd) readReply(rd *proto.Reader) error { return nil } +//----------------------------------------------------------------------- + +type MapStringInterfaceSliceCmd struct { + baseCmd + + val []map[string]interface{} +} + +var _ Cmder = (*MapStringInterfaceSliceCmd)(nil) + +func NewMapStringInterfaceSliceCmd(ctx context.Context, args ...interface{}) *MapStringInterfaceSliceCmd { + return &MapStringInterfaceSliceCmd{ + baseCmd: baseCmd{ + ctx: ctx, + args: args, + }, + } +} + +func (cmd *MapStringInterfaceSliceCmd) SetVal(val []map[string]interface{}) { + cmd.val = val +} + +func (cmd *MapStringInterfaceSliceCmd) Val() []map[string]interface{} { + return cmd.val +} + +func (cmd *MapStringInterfaceSliceCmd) Result() ([]map[string]interface{}, error) { + return cmd.Val(), cmd.Err() +} + +func (cmd *MapStringInterfaceSliceCmd) String() string { + return cmdString(cmd, cmd.val) +} + +func (cmd *MapStringInterfaceSliceCmd) readReply(rd *proto.Reader) error { + n, err := rd.ReadArrayLen() + if err != nil { + return err + } + + cmd.val = make([]map[string]interface{}, n) + for i := 0; i < n; i++ { + nn, err := rd.ReadMapLen() + if err != nil { + return err + } + cmd.val[i] = make(map[string]interface{}, nn) + for f := 0; f < nn; f++ { + k, err := rd.ReadString() + if err != nil { + return err + } + + v, err := rd.ReadReply() + if err != nil { + return err + } + cmd.val[i][k] = v + } + } + return nil +} + //------------------------------------------------------------------------------ type KeyValuesCmd struct { diff --git a/commands.go b/commands.go index 34f4d2c22..c26d61aa3 100644 --- a/commands.go +++ b/commands.go @@ -504,6 +504,8 @@ type Cmdable interface { ACLLogReset(ctx context.Context) *StatusCmd ModuleLoadex(ctx context.Context, conf *ModuleLoadexConfig) *StringCmd + + gearsCmdable } type StatefulCmdable interface { diff --git a/redis_gears.go b/redis_gears.go new file mode 100644 index 000000000..2ea803e4c --- /dev/null +++ b/redis_gears.go @@ -0,0 +1,149 @@ +package redis + +import ( + "context" + "fmt" + "strings" +) + +type gearsCmdable interface { + TFunctionLoad(ctx context.Context, lib string) *StatusCmd + TFunctionLoadArgs(ctx context.Context, lib string, options *TFunctionLoadOptions) *StatusCmd + TFunctionDelete(ctx context.Context, libName string) *StatusCmd + TFunctionList(ctx context.Context) *MapStringInterfaceSliceCmd + TFunctionListArgs(ctx context.Context, options *TFunctionListOptions) *MapStringInterfaceSliceCmd + TFCall(ctx context.Context, libName string, funcName string, numKeys int) *Cmd + TFCallArgs(ctx context.Context, libName string, funcName string, numKeys int, options *TFCallOptions) *Cmd +} +type TFunctionLoadOptions struct { + Replace bool + Config string +} + +type TFunctionListOptions struct { + Withcode bool + Verbose int + Library string +} + +type TFCallOptions struct { + Keys []string + Arguments []string +} + +func (c cmdable) TFunctionLoad(ctx context.Context, lib string) *StatusCmd { + args := []interface{}{"TFUNCTION", "LOAD", lib} + cmd := NewStatusCmd(ctx, args...) + _ = c(ctx, cmd) + return cmd +} + +func (c cmdable) TFunctionLoadArgs(ctx context.Context, lib string, options *TFunctionLoadOptions) *StatusCmd { + args := []interface{}{"TFUNCTION", "LOAD"} + if options != nil { + if options.Replace { + args = append(args, "REPLACE") + } + if options.Config != "" { + args = append(args, "CONFIG", options.Config) + } + } + args = append(args, lib) + cmd := NewStatusCmd(ctx, args...) + _ = c(ctx, cmd) + return cmd +} + +func (c cmdable) TFunctionDelete(ctx context.Context, libName string) *StatusCmd { + args := []interface{}{"TFUNCTION", "DELETE", libName} + cmd := NewStatusCmd(ctx, args...) + _ = c(ctx, cmd) + return cmd +} + +func (c cmdable) TFunctionList(ctx context.Context) *MapStringInterfaceSliceCmd { + args := []interface{}{"TFUNCTION", "LIST"} + cmd := NewMapStringInterfaceSliceCmd(ctx, args...) + _ = c(ctx, cmd) + return cmd +} + +func (c cmdable) TFunctionListArgs(ctx context.Context, options *TFunctionListOptions) *MapStringInterfaceSliceCmd { + args := []interface{}{"TFUNCTION", "LIST"} + if options != nil { + if options.Withcode { + args = append(args, "WITHCODE") + } + if options.Verbose != 0 { + v := strings.Repeat("v", options.Verbose) + args = append(args, v) + } + if options.Library != "" { + args = append(args, "LIBRARY", options.Library) + + } + } + cmd := NewMapStringInterfaceSliceCmd(ctx, args...) + _ = c(ctx, cmd) + return cmd +} + +func (c cmdable) TFCall(ctx context.Context, libName string, funcName string, numKeys int) *Cmd { + lf := fmt.Sprintf("%s.%s", libName, funcName) + args := []interface{}{"TFCALL", lf, numKeys} + cmd := NewCmd(ctx, args...) + _ = c(ctx, cmd) + return cmd +} + +func (c cmdable) TFCallArgs(ctx context.Context, libName string, funcName string, numKeys int, options *TFCallOptions) *Cmd { + lf := fmt.Sprintf("%s.%s", libName, funcName) + args := []interface{}{"TFCALL", lf, numKeys} + if options != nil { + if options.Keys != nil { + for _, key := range options.Keys { + + args = append(args, key) + } + } + if options.Arguments != nil { + for _, key := range options.Arguments { + + args = append(args, key) + } + } + } + cmd := NewCmd(ctx, args...) + _ = c(ctx, cmd) + return cmd +} + +func (c cmdable) TFCallASync(ctx context.Context, libName string, funcName string, numKeys int) *Cmd { + lf := fmt.Sprintf("%s.%s", libName, funcName) + args := []interface{}{"TFCALLASYNC", lf, numKeys} + cmd := NewCmd(ctx, args...) + _ = c(ctx, cmd) + return cmd +} + +func (c cmdable) TFCallASyncArgs(ctx context.Context, libName string, funcName string, numKeys int, options *TFCallOptions) *Cmd { + lf := fmt.Sprintf("%s.%s", libName, funcName) + args := []interface{}{"TFCALLASYNC", lf, numKeys} + if options != nil { + if options.Keys != nil { + for _, key := range options.Keys { + + args = append(args, key) + } + } + if options.Arguments != nil { + for _, key := range options.Arguments { + + args = append(args, key) + } + } + } + cmd := NewCmd(ctx, args...) + _ = c(ctx, cmd) + return cmd +} diff --git a/redis_gears_test.go b/redis_gears_test.go new file mode 100644 index 000000000..0b7ca4423 --- /dev/null +++ b/redis_gears_test.go @@ -0,0 +1,135 @@ +package redis_test + +import ( + "context" + "fmt" + + . "github.com/bsm/ginkgo/v2" + . "github.com/bsm/gomega" + "github.com/redis/go-redis/v9" +) + +func libCode(libName string) string { + return fmt.Sprintf("#!js api_version=1.0 name=%s\n redis.registerFunction('foo', ()=>{{return 'bar'}})", libName) +} + +func libCodeWithConfig(libName string) string { + lib := `#!js api_version=1.0 name=%s + + var last_update_field_name = "__last_update__" + + if (redis.config.last_update_field_name !== undefined) { + if (typeof redis.config.last_update_field_name != 'string') { + throw "last_update_field_name must be a string"; + } + last_update_field_name = redis.config.last_update_field_name + } + + redis.registerFunction("hset", function(client, key, field, val){ + // get the current time in ms + var curr_time = client.call("time")[0]; + return client.call('hset', key, field, val, last_update_field_name, curr_time); + });` + return fmt.Sprintf(lib, libName) +} + +var _ = Describe("Redis Gears commands", Label("gears"), func() { + ctx := context.TODO() + var client *redis.Client + + BeforeEach(func() { + client = redis.NewClient(&redis.Options{Addr: ":6379"}) + Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred()) + }) + + AfterEach(func() { + Expect(client.Close()).NotTo(HaveOccurred()) + }) + + It("should TFunctionLoad, TFunctionLoadArgs and TFunctionDelete ", Label("gears", "tfunctionload"), func() { + + resultAdd, err := client.TFunctionLoad(ctx, libCode("libtflo1")).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultAdd).To(BeEquivalentTo("OK")) + opt := &redis.TFunctionLoadOptions{Replace: true, Config: `{"last_update_field_name":"last_update"}`} + resultAdd, err = client.TFunctionLoadArgs(ctx, libCodeWithConfig("libtflo1"), opt).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultAdd).To(BeEquivalentTo("OK")) + resultAdd, err = client.TFunctionDelete(ctx, "libtflo1").Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultAdd).To(BeEquivalentTo("OK")) + + }) + It("should TFunctionList", Label("gears", "tfunctionlist"), func() { + var resultAdd interface{} + resultAdd, err := client.TFunctionLoad(ctx, libCode("libtfli1")).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultAdd).To(BeEquivalentTo("OK")) + resultAdd, err = client.TFunctionList(ctx).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultAdd).To(BeEquivalentTo("OK")) + // opt := &redis.TFunctionListOptions{Withcode: false, Verbose: 0} + // resultAdd, err = client.TFunctionListArgs(ctx, opt).Result() + // Expect(err).NotTo(HaveOccurred()) + // Expect(resultAdd).To(BeEquivalentTo("OK")) + resultAdd, err = client.TFunctionDelete(ctx, "libtfli1").Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultAdd).To(BeEquivalentTo("OK")) + + }) + + It("should TFCall", Label("gears", "tfcall"), func() { + var resultAdd interface{} + resultAdd, err := client.TFunctionLoad(ctx, libCode("libtfc1")).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultAdd).To(BeEquivalentTo("OK")) + resultAdd, err = client.TFCall(ctx, "libtfc1", "foo", 0).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultAdd).To(BeEquivalentTo("bar")) + resultAdd, err = client.TFunctionDelete(ctx, "libtfc1").Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultAdd).To(BeEquivalentTo("OK")) + }) + + It("should TFCallArgs", Label("gears", "tfcallargs"), func() { + var resultAdd interface{} + resultAdd, err := client.TFunctionLoad(ctx, libCode("libtfca1")).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultAdd).To(BeEquivalentTo("OK")) + opt := &redis.TFCallOptions{Arguments: []string{"foo", "bar"}} + resultAdd, err = client.TFCallArgs(ctx, "libtfca1", "foo", 0, opt).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultAdd).To(BeEquivalentTo("bar")) + resultAdd, err = client.TFunctionDelete(ctx, "libtfca1").Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultAdd).To(BeEquivalentTo("OK")) + }) + + It("should TFCallASync", Label("gears", "tfcallasync"), func() { + var resultAdd interface{} + resultAdd, err := client.TFunctionLoad(ctx, libCode("libtfc1")).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultAdd).To(BeEquivalentTo("OK")) + resultAdd, err = client.TFCallASync(ctx, "libtfc1", "foo", 0).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultAdd).To(BeEquivalentTo("bar")) + resultAdd, err = client.TFunctionDelete(ctx, "libtfc1").Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultAdd).To(BeEquivalentTo("OK")) + }) + + It("should TFCallASyncArgs", Label("gears", "tfcallasyncargs"), func() { + var resultAdd interface{} + resultAdd, err := client.TFunctionLoad(ctx, libCode("libtfca1")).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultAdd).To(BeEquivalentTo("OK")) + opt := &redis.TFCallOptions{Arguments: []string{"foo", "bar"}} + resultAdd, err = client.TFCallASyncArgs(ctx, "libtfca1", "foo", 0, opt).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultAdd).To(BeEquivalentTo("bar")) + resultAdd, err = client.TFunctionDelete(ctx, "libtfca1").Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultAdd).To(BeEquivalentTo("OK")) + }) + +}) From 379a1aa38f07e2a41fe4939bbe6ef2c1a22e3ffa Mon Sep 17 00:00:00 2001 From: ofekshenawa Date: Wed, 16 Aug 2023 14:12:50 +0300 Subject: [PATCH 2/5] Fix tfunctionlist and add docstrings --- command.go | 5 +++-- redis_gears.go | 10 ++++++++++ redis_gears_test.go | 18 +++++++++++------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/command.go b/command.go index ae74a1690..1bd4d5db1 100644 --- a/command.go +++ b/command.go @@ -3766,10 +3766,11 @@ func (cmd *MapStringInterfaceSliceCmd) readReply(rd *proto.Reader) error { if err != nil { return err } - v, err := rd.ReadReply() if err != nil { - return err + if err != Nil { + return err + } } cmd.val[i][k] = v } diff --git a/redis_gears.go b/redis_gears.go index 2ea803e4c..7a8d3e12d 100644 --- a/redis_gears.go +++ b/redis_gears.go @@ -31,6 +31,8 @@ type TFCallOptions struct { Arguments []string } +// TFunctionLoad - load a new JavaScript library into Redis. +// For more information - https://redis.io/commands/tfunction-load/ func (c cmdable) TFunctionLoad(ctx context.Context, lib string) *StatusCmd { args := []interface{}{"TFUNCTION", "LOAD", lib} cmd := NewStatusCmd(ctx, args...) @@ -54,6 +56,8 @@ func (c cmdable) TFunctionLoadArgs(ctx context.Context, lib string, options *TFu return cmd } +// TFunctionDelete - delete a JavaScript library from Redis. +// For more information - https://redis.io/commands/tfunction-delete/ func (c cmdable) TFunctionDelete(ctx context.Context, libName string) *StatusCmd { args := []interface{}{"TFUNCTION", "DELETE", libName} cmd := NewStatusCmd(ctx, args...) @@ -61,6 +65,8 @@ func (c cmdable) TFunctionDelete(ctx context.Context, libName string) *StatusCmd return cmd } +// TFunctionList - list the functions with additional information about each function. +// For more information - https://redis.io/commands/tfunction-list/ func (c cmdable) TFunctionList(ctx context.Context) *MapStringInterfaceSliceCmd { args := []interface{}{"TFUNCTION", "LIST"} cmd := NewMapStringInterfaceSliceCmd(ctx, args...) @@ -88,6 +94,8 @@ func (c cmdable) TFunctionListArgs(ctx context.Context, options *TFunctionListOp return cmd } +// TFCall - invoke a function. +// For more information - https://redis.io/commands/tfcall/ func (c cmdable) TFCall(ctx context.Context, libName string, funcName string, numKeys int) *Cmd { lf := fmt.Sprintf("%s.%s", libName, funcName) args := []interface{}{"TFCALL", lf, numKeys} @@ -118,6 +126,8 @@ func (c cmdable) TFCallArgs(ctx context.Context, libName string, funcName string return cmd } +// TFCallASync - invoke an asynchronous JavaScript function (coroutine). +// For more information - https://redis.io/commands/tfcallasync/ func (c cmdable) TFCallASync(ctx context.Context, libName string, funcName string, numKeys int) *Cmd { lf := fmt.Sprintf("%s.%s", libName, funcName) args := []interface{}{"TFCALLASYNC", lf, numKeys} diff --git a/redis_gears_test.go b/redis_gears_test.go index 0b7ca4423..ba92d4a78 100644 --- a/redis_gears_test.go +++ b/redis_gears_test.go @@ -61,21 +61,25 @@ var _ = Describe("Redis Gears commands", Label("gears"), func() { }) It("should TFunctionList", Label("gears", "tfunctionlist"), func() { - var resultAdd interface{} resultAdd, err := client.TFunctionLoad(ctx, libCode("libtfli1")).Result() Expect(err).NotTo(HaveOccurred()) Expect(resultAdd).To(BeEquivalentTo("OK")) - resultAdd, err = client.TFunctionList(ctx).Result() + resultAdd, err = client.TFunctionLoad(ctx, libCode("libtfli2")).Result() Expect(err).NotTo(HaveOccurred()) Expect(resultAdd).To(BeEquivalentTo("OK")) - // opt := &redis.TFunctionListOptions{Withcode: false, Verbose: 0} - // resultAdd, err = client.TFunctionListArgs(ctx, opt).Result() - // Expect(err).NotTo(HaveOccurred()) - // Expect(resultAdd).To(BeEquivalentTo("OK")) + resultList, err := client.TFunctionList(ctx).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultList[0]["engine"]).To(BeEquivalentTo("js")) + opt := &redis.TFunctionListOptions{Withcode: true, Verbose: 2} + resultListArgs, err := client.TFunctionListArgs(ctx, opt).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultListArgs[0]["code"]).To(BeEquivalentTo(libCode("libtfli1"))) resultAdd, err = client.TFunctionDelete(ctx, "libtfli1").Result() Expect(err).NotTo(HaveOccurred()) Expect(resultAdd).To(BeEquivalentTo("OK")) - + resultAdd, err = client.TFunctionDelete(ctx, "libtfli2").Result() + Expect(err).NotTo(HaveOccurred()) + Expect(resultAdd).To(BeEquivalentTo("OK")) }) It("should TFCall", Label("gears", "tfcall"), func() { From e76c2259fb718304a2eb3cbe530fa2f9f59d9ca0 Mon Sep 17 00:00:00 2001 From: ofekshenawa Date: Wed, 16 Aug 2023 15:00:08 +0300 Subject: [PATCH 3/5] fixes --- .github/wordlist.txt | 3 ++- redis_gears.go | 14 +++++++------- redis_gears_test.go | 10 +++++----- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/wordlist.txt b/.github/wordlist.txt index 294988d52..32aba8317 100644 --- a/.github/wordlist.txt +++ b/.github/wordlist.txt @@ -52,4 +52,5 @@ uri URI url variadic -RedisStack \ No newline at end of file +RedisStack +RedisGears \ No newline at end of file diff --git a/redis_gears.go b/redis_gears.go index 7a8d3e12d..88b45efc2 100644 --- a/redis_gears.go +++ b/redis_gears.go @@ -97,15 +97,15 @@ func (c cmdable) TFunctionListArgs(ctx context.Context, options *TFunctionListOp // TFCall - invoke a function. // For more information - https://redis.io/commands/tfcall/ func (c cmdable) TFCall(ctx context.Context, libName string, funcName string, numKeys int) *Cmd { - lf := fmt.Sprintf("%s.%s", libName, funcName) + lf := libName + "." + funcName args := []interface{}{"TFCALL", lf, numKeys} cmd := NewCmd(ctx, args...) - _ = c(ctx, cmd) + c(ctx, cmd) return cmd } func (c cmdable) TFCallArgs(ctx context.Context, libName string, funcName string, numKeys int, options *TFCallOptions) *Cmd { - lf := fmt.Sprintf("%s.%s", libName, funcName) + lf := libName + "." + funcName args := []interface{}{"TFCALL", lf, numKeys} if options != nil { if options.Keys != nil { @@ -126,9 +126,9 @@ func (c cmdable) TFCallArgs(ctx context.Context, libName string, funcName string return cmd } -// TFCallASync - invoke an asynchronous JavaScript function (coroutine). -// For more information - https://redis.io/commands/tfcallasync/ -func (c cmdable) TFCallASync(ctx context.Context, libName string, funcName string, numKeys int) *Cmd { +// TFCallASYNC - invoke an asynchronous JavaScript function (coroutine). +// For more information - https://redis.io/commands/TFCallASYNC/ +func (c cmdable) TFCallASYNC(ctx context.Context, libName string, funcName string, numKeys int) *Cmd { lf := fmt.Sprintf("%s.%s", libName, funcName) args := []interface{}{"TFCALLASYNC", lf, numKeys} cmd := NewCmd(ctx, args...) @@ -136,7 +136,7 @@ func (c cmdable) TFCallASync(ctx context.Context, libName string, funcName strin return cmd } -func (c cmdable) TFCallASyncArgs(ctx context.Context, libName string, funcName string, numKeys int, options *TFCallOptions) *Cmd { +func (c cmdable) TFCallASYNCArgs(ctx context.Context, libName string, funcName string, numKeys int, options *TFCallOptions) *Cmd { lf := fmt.Sprintf("%s.%s", libName, funcName) args := []interface{}{"TFCALLASYNC", lf, numKeys} if options != nil { diff --git a/redis_gears_test.go b/redis_gears_test.go index ba92d4a78..d02487cb7 100644 --- a/redis_gears_test.go +++ b/redis_gears_test.go @@ -33,7 +33,7 @@ func libCodeWithConfig(libName string) string { return fmt.Sprintf(lib, libName) } -var _ = Describe("Redis Gears commands", Label("gears"), func() { +var _ = Describe("RedisGears commands", Label("gears"), func() { ctx := context.TODO() var client *redis.Client @@ -109,12 +109,12 @@ var _ = Describe("Redis Gears commands", Label("gears"), func() { Expect(resultAdd).To(BeEquivalentTo("OK")) }) - It("should TFCallASync", Label("gears", "tfcallasync"), func() { + It("should TFCallASYNC", Label("gears", "TFCallASYNC"), func() { var resultAdd interface{} resultAdd, err := client.TFunctionLoad(ctx, libCode("libtfc1")).Result() Expect(err).NotTo(HaveOccurred()) Expect(resultAdd).To(BeEquivalentTo("OK")) - resultAdd, err = client.TFCallASync(ctx, "libtfc1", "foo", 0).Result() + resultAdd, err = client.TFCallASYNC(ctx, "libtfc1", "foo", 0).Result() Expect(err).NotTo(HaveOccurred()) Expect(resultAdd).To(BeEquivalentTo("bar")) resultAdd, err = client.TFunctionDelete(ctx, "libtfc1").Result() @@ -122,13 +122,13 @@ var _ = Describe("Redis Gears commands", Label("gears"), func() { Expect(resultAdd).To(BeEquivalentTo("OK")) }) - It("should TFCallASyncArgs", Label("gears", "tfcallasyncargs"), func() { + It("should TFCallASYNCArgs", Label("gears", "TFCallASYNCargs"), func() { var resultAdd interface{} resultAdd, err := client.TFunctionLoad(ctx, libCode("libtfca1")).Result() Expect(err).NotTo(HaveOccurred()) Expect(resultAdd).To(BeEquivalentTo("OK")) opt := &redis.TFCallOptions{Arguments: []string{"foo", "bar"}} - resultAdd, err = client.TFCallASyncArgs(ctx, "libtfca1", "foo", 0, opt).Result() + resultAdd, err = client.TFCallASYNCArgs(ctx, "libtfca1", "foo", 0, opt).Result() Expect(err).NotTo(HaveOccurred()) Expect(resultAdd).To(BeEquivalentTo("bar")) resultAdd, err = client.TFunctionDelete(ctx, "libtfca1").Result() From e3adf82a56756f6deeb65cc1f184a1a9072d1ea0 Mon Sep 17 00:00:00 2001 From: ofekshenawa Date: Wed, 16 Aug 2023 15:01:21 +0300 Subject: [PATCH 4/5] fixes --- redis_gears.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/redis_gears.go b/redis_gears.go index 88b45efc2..cdf081be7 100644 --- a/redis_gears.go +++ b/redis_gears.go @@ -36,7 +36,7 @@ type TFCallOptions struct { func (c cmdable) TFunctionLoad(ctx context.Context, lib string) *StatusCmd { args := []interface{}{"TFUNCTION", "LOAD", lib} cmd := NewStatusCmd(ctx, args...) - _ = c(ctx, cmd) + c(ctx, cmd) return cmd } @@ -52,7 +52,7 @@ func (c cmdable) TFunctionLoadArgs(ctx context.Context, lib string, options *TFu } args = append(args, lib) cmd := NewStatusCmd(ctx, args...) - _ = c(ctx, cmd) + c(ctx, cmd) return cmd } @@ -61,7 +61,7 @@ func (c cmdable) TFunctionLoadArgs(ctx context.Context, lib string, options *TFu func (c cmdable) TFunctionDelete(ctx context.Context, libName string) *StatusCmd { args := []interface{}{"TFUNCTION", "DELETE", libName} cmd := NewStatusCmd(ctx, args...) - _ = c(ctx, cmd) + c(ctx, cmd) return cmd } @@ -70,7 +70,7 @@ func (c cmdable) TFunctionDelete(ctx context.Context, libName string) *StatusCmd func (c cmdable) TFunctionList(ctx context.Context) *MapStringInterfaceSliceCmd { args := []interface{}{"TFUNCTION", "LIST"} cmd := NewMapStringInterfaceSliceCmd(ctx, args...) - _ = c(ctx, cmd) + c(ctx, cmd) return cmd } @@ -90,7 +90,7 @@ func (c cmdable) TFunctionListArgs(ctx context.Context, options *TFunctionListOp } } cmd := NewMapStringInterfaceSliceCmd(ctx, args...) - _ = c(ctx, cmd) + c(ctx, cmd) return cmd } @@ -122,7 +122,7 @@ func (c cmdable) TFCallArgs(ctx context.Context, libName string, funcName string } } cmd := NewCmd(ctx, args...) - _ = c(ctx, cmd) + c(ctx, cmd) return cmd } @@ -132,7 +132,7 @@ func (c cmdable) TFCallASYNC(ctx context.Context, libName string, funcName strin lf := fmt.Sprintf("%s.%s", libName, funcName) args := []interface{}{"TFCALLASYNC", lf, numKeys} cmd := NewCmd(ctx, args...) - _ = c(ctx, cmd) + c(ctx, cmd) return cmd } @@ -154,6 +154,6 @@ func (c cmdable) TFCallASYNCArgs(ctx context.Context, libName string, funcName s } } cmd := NewCmd(ctx, args...) - _ = c(ctx, cmd) + c(ctx, cmd) return cmd } From 6c9e0cd9b22e7fdb19256f4d2bbf86de1d10df51 Mon Sep 17 00:00:00 2001 From: ofekshenawa Date: Wed, 16 Aug 2023 15:04:37 +0300 Subject: [PATCH 5/5] add tfcallasync to gearsCmdable --- redis_gears.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/redis_gears.go b/redis_gears.go index cdf081be7..5fafea403 100644 --- a/redis_gears.go +++ b/redis_gears.go @@ -14,6 +14,8 @@ type gearsCmdable interface { TFunctionListArgs(ctx context.Context, options *TFunctionListOptions) *MapStringInterfaceSliceCmd TFCall(ctx context.Context, libName string, funcName string, numKeys int) *Cmd TFCallArgs(ctx context.Context, libName string, funcName string, numKeys int, options *TFCallOptions) *Cmd + TFCallASYNC(ctx context.Context, libName string, funcName string, numKeys int) *Cmd + TFCallASYNCArgs(ctx context.Context, libName string, funcName string, numKeys int, options *TFCallOptions) *Cmd } type TFunctionLoadOptions struct { Replace bool @@ -36,7 +38,7 @@ type TFCallOptions struct { func (c cmdable) TFunctionLoad(ctx context.Context, lib string) *StatusCmd { args := []interface{}{"TFUNCTION", "LOAD", lib} cmd := NewStatusCmd(ctx, args...) - c(ctx, cmd) + _ = c(ctx, cmd) return cmd } @@ -52,7 +54,7 @@ func (c cmdable) TFunctionLoadArgs(ctx context.Context, lib string, options *TFu } args = append(args, lib) cmd := NewStatusCmd(ctx, args...) - c(ctx, cmd) + _ = c(ctx, cmd) return cmd } @@ -61,7 +63,7 @@ func (c cmdable) TFunctionLoadArgs(ctx context.Context, lib string, options *TFu func (c cmdable) TFunctionDelete(ctx context.Context, libName string) *StatusCmd { args := []interface{}{"TFUNCTION", "DELETE", libName} cmd := NewStatusCmd(ctx, args...) - c(ctx, cmd) + _ = c(ctx, cmd) return cmd } @@ -70,7 +72,7 @@ func (c cmdable) TFunctionDelete(ctx context.Context, libName string) *StatusCmd func (c cmdable) TFunctionList(ctx context.Context) *MapStringInterfaceSliceCmd { args := []interface{}{"TFUNCTION", "LIST"} cmd := NewMapStringInterfaceSliceCmd(ctx, args...) - c(ctx, cmd) + _ = c(ctx, cmd) return cmd } @@ -90,7 +92,7 @@ func (c cmdable) TFunctionListArgs(ctx context.Context, options *TFunctionListOp } } cmd := NewMapStringInterfaceSliceCmd(ctx, args...) - c(ctx, cmd) + _ = c(ctx, cmd) return cmd } @@ -100,7 +102,7 @@ func (c cmdable) TFCall(ctx context.Context, libName string, funcName string, nu lf := libName + "." + funcName args := []interface{}{"TFCALL", lf, numKeys} cmd := NewCmd(ctx, args...) - c(ctx, cmd) + _ = c(ctx, cmd) return cmd } @@ -122,7 +124,7 @@ func (c cmdable) TFCallArgs(ctx context.Context, libName string, funcName string } } cmd := NewCmd(ctx, args...) - c(ctx, cmd) + _ = c(ctx, cmd) return cmd } @@ -132,7 +134,7 @@ func (c cmdable) TFCallASYNC(ctx context.Context, libName string, funcName strin lf := fmt.Sprintf("%s.%s", libName, funcName) args := []interface{}{"TFCALLASYNC", lf, numKeys} cmd := NewCmd(ctx, args...) - c(ctx, cmd) + _ = c(ctx, cmd) return cmd } @@ -154,6 +156,6 @@ func (c cmdable) TFCallASYNCArgs(ctx context.Context, libName string, funcName s } } cmd := NewCmd(ctx, args...) - c(ctx, cmd) + _ = c(ctx, cmd) return cmd }