GetSet sets the string value of a key and return its old value
(ctx *Context, txn *db.Transaction)
| 217 | |
| 218 | // GetSet sets the string value of a key and return its old value |
| 219 | func GetSet(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
| 220 | key := []byte(ctx.Args[0]) |
| 221 | v := []byte(ctx.Args[1]) |
| 222 | str, err := txn.String(key) |
| 223 | if err != nil { |
| 224 | if err == db.ErrTypeMismatch { |
| 225 | return nil, ErrTypeMismatch |
| 226 | } |
| 227 | return nil, errors.New("ERR " + err.Error()) |
| 228 | } |
| 229 | if !str.Exist() { |
| 230 | return NullBulkString(ctx.Out), nil |
| 231 | } |
| 232 | |
| 233 | value, err := str.GetSet(v) |
| 234 | if err != nil { |
| 235 | return nil, errors.New("ERR " + err.Error()) |
| 236 | } |
| 237 | return BulkString(ctx.Out, string(value)), nil |
| 238 | } |
| 239 | |
| 240 | // GetRange increments the integer value of a keys by the given amount |
| 241 | func GetRange(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
nothing calls this directly
no test coverage detected