impr: command - set shortcut for simple cases

This commit is contained in:
Anton
2024-04-26 10:14:22 +05:00
parent 65d8134596
commit 4eb6ded8b9

View File

@@ -66,7 +66,18 @@ func parseSet(b baseCmd) (*Set, error) {
}
func (cmd *Set) Run(w Writer, red Redka) (any, error) {
// Build and run the command.
if !cmd.ifNX && !cmd.ifXX && !cmd.get && !cmd.keepTTL && cmd.at.IsZero() {
// Simple SET without additional options (except ttl).
err := red.Str().SetExpires(cmd.key, cmd.value, cmd.ttl)
if err != nil {
w.WriteError(cmd.Error(err))
return false, err
}
w.WriteString("OK")
return true, nil
}
// SET with additional options.
op := red.Str().SetWith(cmd.key, cmd.value)
if cmd.ifXX {
op = op.IfExists()