Skip to content

Commit a53c0a8

Browse files
committed
addressing comments
Signed-off-by: TJ Zhang <tj.zhang@improving.com>
1 parent a6ef3e0 commit a53c0a8

File tree

2 files changed

+89
-93
lines changed

2 files changed

+89
-93
lines changed

go/api/base_client.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7921,6 +7921,10 @@ func (client *baseClient) FunctionList(query FunctionListQuery) ([]LibraryInfo,
79217921

79227922
// Returns the serialized payload of all loaded libraries.
79237923
//
7924+
// Note:
7925+
//
7926+
// When in cluster mode, the command will be routed to a random node.
7927+
//
79247928
// Since:
79257929
//
79267930
// Valkey 7.0 and above.
@@ -7942,6 +7946,10 @@ func (client *baseClient) FunctionDump() (string, error) {
79427946

79437947
// Restores libraries from the serialized payload returned by `FunctionDump`.
79447948
//
7949+
// Note:
7950+
//
7951+
// When in cluster mode, the command will be routed to all primary nodes.
7952+
//
79457953
// Since:
79467954
//
79477955
// Valkey 7.0 and above.
@@ -7967,6 +7975,10 @@ func (client *baseClient) FunctionRestore(payload string) (string, error) {
79677975

79687976
// Restores libraries from the serialized payload returned by `FunctionDump`.
79697977
//
7978+
// Note:
7979+
//
7980+
// When in cluster mode, the command will be routed to all primary nodes.
7981+
//
79707982
// Since:
79717983
//
79727984
// Valkey 7.0 and above.

go/api/scripting_and_function_commands_test.go

Lines changed: 77 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -858,141 +858,125 @@ func ExampleGlideClusterClient_FunctionListWithRoute() {
858858
func ExampleGlideClient_FunctionDump() {
859859
client := getExampleGlideClient()
860860

861-
// First, flush all functions
862-
_, err := client.FunctionFlushSync()
861+
// Attempt to call a non-existent function
862+
_, err := client.FCall("nonexistent_function")
863863
if err != nil {
864-
fmt.Println("Glide example failed with an error: ", err)
865-
return
864+
fmt.Println("Error:", err.Error())
866865
}
867866

868-
// Load a function
869-
_, err = client.FunctionLoad(libraryCodeWithArgs, true)
870-
if err != nil {
871-
fmt.Println("Glide example failed with an error: ", err)
872-
return
873-
}
874-
875-
// Dump the functions
876-
dump, err := client.FunctionDump()
877-
if err != nil {
878-
fmt.Println("Glide example failed with an error: ", err)
879-
return
880-
}
867+
// Output:
868+
// Error: An error was signalled by the server: - ResponseError: Function not found
869+
}
881870

882-
// Flush all functions
883-
_, err = client.FunctionFlushSync()
884-
if err != nil {
885-
fmt.Println("Glide example failed with an error: ", err)
886-
return
887-
}
871+
func ExampleGlideClusterClient_FunctionDump() {
872+
client := getExampleGlideClusterClient()
888873

889-
// Restore the functions
890-
result, err := client.FunctionRestore(dump)
874+
// Attempt to call a non-existent function
875+
_, err := client.FCall("nonexistent_function")
891876
if err != nil {
892-
fmt.Println("Glide example failed with an error: ", err)
893-
return
877+
fmt.Println("Error:", err.Error())
894878
}
895879

896-
fmt.Println(result)
897-
898880
// Output:
899-
// OK
881+
// Error: An error was signalled by the server: - ResponseError: Function not found
900882
}
901883

902-
func ExampleGlideClusterClient_FunctionDump() {
884+
func ExampleGlideClusterClient_FunctionDumpWithRoute() {
903885
client := getExampleGlideClusterClient()
904886

905-
// First, flush all functions
906-
_, err := client.FunctionFlushSync()
887+
// Attempt to call a non-existent function with route
888+
route := options.RouteOption{Route: config.RandomRoute}
889+
_, err := client.FCallWithRoute("nonexistent_function", route)
907890
if err != nil {
908-
fmt.Println("Glide example failed with an error: ", err)
909-
return
891+
fmt.Println("Error:", err.Error())
910892
}
911893

912-
// Load a function
913-
_, err = client.FunctionLoad(libraryCodeWithArgs, true)
914-
if err != nil {
915-
fmt.Println("Glide example failed with an error: ", err)
916-
return
917-
}
894+
// Output:
895+
// Error: An error was signalled by the server: - ResponseError: Function not found
896+
}
918897

919-
// Dump the functions
920-
dump, err := client.FunctionDump()
921-
if err != nil {
922-
fmt.Println("Glide example failed with an error: ", err)
923-
return
924-
}
898+
func ExampleGlideClient_FunctionRestore() {
899+
client := getExampleGlideClient()
925900

926-
// Flush all functions
927-
_, err = client.FunctionFlushSync()
901+
// Attempt to restore with invalid dump data
902+
invalidDump := "invalid_dump_data"
903+
_, err := client.FunctionRestore(invalidDump)
928904
if err != nil {
929-
fmt.Println("Glide example failed with an error: ", err)
930-
return
905+
fmt.Println("Error:", err.Error())
931906
}
932907

933-
// Restore the functions with FLUSH policy to ensure clean restore
934-
result, err := client.FunctionRestoreWithPolicy(dump, options.FlushPolicy)
908+
// Output:
909+
// Error: An error was signalled by the server: - ResponseError: DUMP payload version or checksum are wrong
910+
}
911+
912+
func ExampleGlideClusterClient_FunctionRestore() {
913+
client := getExampleGlideClusterClient()
914+
915+
// Attempt to restore with invalid dump data
916+
invalidDump := "invalid_dump_data"
917+
_, err := client.FunctionRestore(invalidDump)
935918
if err != nil {
936-
fmt.Println("Glide example failed with an error: ", err)
937-
return
919+
fmt.Println("Error:", err.Error())
938920
}
939921

940-
fmt.Println(result)
941-
942922
// Output:
943-
// OK
923+
// Error: An error was signalled by the server: - ResponseError: DUMP payload version or checksum are wrong
944924
}
945925

946-
func ExampleGlideClusterClient_FunctionDumpWithRoute() {
926+
func ExampleGlideClusterClient_FunctionRestoreWithRoute() {
947927
client := getExampleGlideClusterClient()
948928

949-
// Use AllPrimaries route for cluster-wide operations
950-
route := options.RouteOption{Route: config.AllPrimaries}
951-
952-
// First, flush all functions
953-
_, err := client.FunctionFlushSyncWithRoute(route)
929+
// Attempt to restore with invalid dump data and route
930+
invalidDump := "invalid_dump_data"
931+
route := config.RandomRoute
932+
_, err := client.FunctionRestoreWithRoute(invalidDump, route)
954933
if err != nil {
955-
fmt.Println("Glide example failed with an error: ", err)
956-
return
934+
fmt.Println("Error:", err.Error())
957935
}
958936

959-
// Load a function
960-
// code := `#!lua name=mylib
961-
// redis.register_function{
962-
// function_name = 'myfunc',
963-
// callback = function(keys, args) return args[1] end,
964-
// flags = { 'no-writes' }
965-
// }`
937+
// Output:
938+
// Error: An error was signalled by the server: - ResponseError: DUMP payload version or checksum are wrong
939+
}
966940

967-
_, err = client.FunctionLoadWithRoute(libraryCodeWithArgs, true, route)
968-
if err != nil {
969-
fmt.Println("Glide example failed with an error: ", err)
970-
return
971-
}
941+
func ExampleGlideClient_FunctionRestoreWithPolicy() {
942+
client := getExampleGlideClient()
972943

973-
// Dump the functions from a single node
974-
dump, err := client.FunctionDumpWithRoute(config.RandomRoute)
944+
// Attempt to restore with invalid dump data and policy
945+
invalidDump := "invalid_dump_data"
946+
_, err := client.FunctionRestoreWithPolicy(invalidDump, options.FlushPolicy)
975947
if err != nil {
976-
fmt.Println("Glide example failed with an error: ", err)
977-
return
948+
fmt.Println("Error:", err.Error())
978949
}
979950

980-
// Flush all functions
981-
_, err = client.FunctionFlushSyncWithRoute(route)
951+
// Output:
952+
// Error: An error was signalled by the server: - ResponseError: DUMP payload version or checksum are wrong
953+
}
954+
955+
func ExampleGlideClusterClient_FunctionRestoreWithPolicy() {
956+
client := getExampleGlideClusterClient()
957+
958+
// Attempt to restore with invalid dump data and policy
959+
invalidDump := "invalid_dump_data"
960+
_, err := client.FunctionRestoreWithPolicy(invalidDump, options.FlushPolicy)
982961
if err != nil {
983-
fmt.Println("Glide example failed with an error: ", err)
984-
return
962+
fmt.Println("Error:", err.Error())
985963
}
986964

987-
// Restore the functions with FLUSH policy to ensure clean restore
988-
result, err := client.FunctionRestoreWithPolicyWithRoute(dump.SingleValue(), options.FlushPolicy, route.Route)
965+
// Output:
966+
// Error: An error was signalled by the server: - ResponseError: DUMP payload version or checksum are wrong
967+
}
968+
969+
func ExampleGlideClusterClient_FunctionRestoreWithPolicyWithRoute() {
970+
client := getExampleGlideClusterClient()
971+
972+
// Attempt to restore with invalid dump data, policy and route
973+
invalidDump := "invalid_dump_data"
974+
route := config.RandomRoute
975+
_, err := client.FunctionRestoreWithPolicyWithRoute(invalidDump, options.FlushPolicy, route)
989976
if err != nil {
990-
fmt.Println("Glide example failed with an error: ", err)
991-
return
977+
fmt.Println("Error:", err.Error())
992978
}
993979

994-
fmt.Println(result)
995-
996980
// Output:
997-
// OK
981+
// Error: An error was signalled by the server: - ResponseError: DUMP payload version or checksum are wrong
998982
}

0 commit comments

Comments
 (0)