PSetEx sets the value and expiration in milliseconds of a key
(ctx *Context, txn *db.Transaction)
| 321 | |
| 322 | // PSetEx sets the value and expiration in milliseconds of a key |
| 323 | func PSetEx(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
| 324 | //get the key |
| 325 | key := []byte(ctx.Args[0]) |
| 326 | obj, err := txn.Object(key) |
| 327 | if err != nil && err != db.ErrKeyNotFound { |
| 328 | return nil, errors.New("ERR " + err.Error()) |
| 329 | } |
| 330 | |
| 331 | if err != db.ErrKeyNotFound { |
| 332 | txn.Destory(obj, key) |
| 333 | } |
| 334 | |
| 335 | s := db.NewString(txn, key) |
| 336 | ui, err := strconv.ParseUint(ctx.Args[1], 10, 64) |
| 337 | if err != nil { |
| 338 | return nil, ErrInteger |
| 339 | } |
| 340 | unit := ui * uint64(time.Millisecond) |
| 341 | if err := s.Set([]byte(ctx.Args[2]), int64(unit)); err != nil { |
| 342 | return nil, errors.New("ERR " + err.Error()) |
| 343 | } |
| 344 | |
| 345 | return SimpleString(ctx.Out, OK), nil |
| 346 | } |
| 347 | |
| 348 | //SetRange overwrites part of the string stored at key, starting at the specified offset, for the entire length of value. |
| 349 | func SetRange(ctx *Context, txn *db.Transaction) (OnCommit, error) { |