Append a value to a key
(ctx *Context, txn *db.Transaction)
| 198 | |
| 199 | // Append a value to a key |
| 200 | func Append(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
| 201 | key := []byte(ctx.Args[0]) |
| 202 | value := []byte(ctx.Args[1]) |
| 203 | str, err := txn.String(key) |
| 204 | if err != nil { |
| 205 | if err == db.ErrTypeMismatch { |
| 206 | return nil, ErrTypeMismatch |
| 207 | } |
| 208 | return nil, errors.New("ERR " + err.Error()) |
| 209 | } |
| 210 | |
| 211 | llen, err := str.Append(value) |
| 212 | if err != nil { |
| 213 | return nil, errors.New("ERR " + err.Error()) |
| 214 | } |
| 215 | return Integer(ctx.Out, int64(llen)), nil |
| 216 | } |
| 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) { |