mirror of
https://github.com/nalgeon/redka.git
synced 2025-10-13 19:54:59 +08:00
34 lines
612 B
Go
34 lines
612 B
Go
package conn
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/nalgeon/redka/internal/parser"
|
|
"github.com/nalgeon/redka/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 cmd, 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
|
|
}
|