Write a command in RESP3 proto. Used to write commands to redis. Currently only supports string arrays.
(w io.Writer, cmd []string)
| 219 | // Write a command in RESP3 proto. Used to write commands to redis. |
| 220 | // Currently only supports string arrays. |
| 221 | func Write(w io.Writer, cmd []string) error { |
| 222 | if _, err := fmt.Fprintf(w, "*%d\r\n", len(cmd)); err != nil { |
| 223 | return err |
| 224 | } |
| 225 | for _, c := range cmd { |
| 226 | if _, err := fmt.Fprintf(w, "$%d\r\n%s\r\n", len(c), c); err != nil { |
| 227 | return err |
| 228 | } |
| 229 | } |
| 230 | return nil |
| 231 | } |
| 232 | |
| 233 | // Parse into interfaces. `b` must contain exactly a single command (which can be nested). |
| 234 | func Parse(b string) (any, error) { |