tidwall / redcon

Redis compatible server framework for Go
MIT License
2.19k stars 158 forks source link

how does hmget return values? sorry i'm not sure how to use appendbulk etc without examples. #33

Closed gitmko0 closed 4 years ago

gitmko0 commented 4 years ago

how does hmget return values? sorry i'm not sure how to use appendbulk etc without examples.

tidwall commented 4 years ago

According to the Redis website, the hmget command returns an array of bulk strings.

So you would first use AppendArray followed by a number of AppendBulkString (or AppendBulk for byte slices).

Here's an example of how to create a valid Redis response for the HMGET command from an array of Go strings.

strs := []string{ "hello", "world", "planet" }

var resp []byte
resp = redcon.AppendArray(resp, len(strs))
for _, str := range strs {
    resp = redcon.AppendBulkString(resp, str)
}