Files
redka/internal/command/echo.go
2024-04-07 00:12:54 +05:00

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
}