mirror of
https://github.com/nalgeon/redka.git
synced 2025-10-05 16:06:50 +08:00
35 lines
634 B
Go
35 lines
634 B
Go
package command
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/nalgeon/redka"
|
|
"github.com/tidwall/redcon"
|
|
)
|
|
|
|
// Echo returns the given string.
|
|
// ECHO message
|
|
// https://redis.io/commands/echo
|
|
type Echo struct {
|
|
baseCmd
|
|
parts []string
|
|
}
|
|
|
|
func parseEcho(b baseCmd) (*Echo, error) {
|
|
cmd := &Echo{baseCmd: b}
|
|
if len(b.args) < 1 {
|
|
return cmd, ErrInvalidArgNum(b.name)
|
|
}
|
|
cmd.parts = make([]string, len(b.args))
|
|
for i := 0; i < len(b.args); i++ {
|
|
cmd.parts[i] = string(cmd.args[i])
|
|
}
|
|
return cmd, nil
|
|
}
|
|
|
|
func (c *Echo) Run(w redcon.Conn, _ redka.Redka) (any, error) {
|
|
out := strings.Join(c.parts, " ")
|
|
w.WriteAny(out)
|
|
return out, nil
|
|
}
|