mirror of
https://github.com/nalgeon/redka.git
synced 2025-10-05 16:06:50 +08:00
34 lines
626 B
Go
34 lines
626 B
Go
package conn
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/nalgeon/redka/redsrv/internal/parser"
|
|
"github.com/nalgeon/redka/redsrv/internal/redis"
|
|
)
|
|
|
|
// Echo returns the given string.
|
|
// ECHO message
|
|
// https://redis.io/commands/echo
|
|
type Echo struct {
|
|
redis.BaseCmd
|
|
parts []string
|
|
}
|
|
|
|
func ParseEcho(b redis.BaseCmd) (Echo, error) {
|
|
cmd := Echo{BaseCmd: b}
|
|
err := parser.New(
|
|
parser.Strings(&cmd.parts),
|
|
).Required(1).Run(cmd.Args())
|
|
if err != nil {
|
|
return Echo{}, err
|
|
}
|
|
return cmd, nil
|
|
}
|
|
|
|
func (c Echo) Run(w redis.Writer, _ redis.Redka) (any, error) {
|
|
out := strings.Join(c.parts, " ")
|
|
w.WriteAny(out)
|
|
return out, nil
|
|
}
|