When a Lua script returns a table array during an Eval call, how can it be converted to a []string in go?
The redis cli returns bulk replies in the following format.
1) val1
2) val2
Will go-redis eval function return the bulk entries as
["val1", "val2"]
Redis returns Lua table arrays as RESP2 arrays. The Go client then will map that response to Go native types. The relevant documentation for
go-redisis found here: Lua and Go types.The tl;dr is that Lua tables are indeed mapped to a bulk reply, and the Go client maps that to a slice of interface:
[]interface{}.Both
go-redisscriptRunandEvalreturn a*Cmd. You can use methods on this type to retrieve the output as Go types.Resultgives(interface{}, error), which you can type-assert to whatever you want, otherwise,StringSliceis a convenience getter to retrieve[]stringright away.So it looks like:
If the values aren't actually all strings, use
Sliceto get the[]interface{}slice, and then inspect the elements individually.