Skip to content

Commit

Permalink
fix reepeat exec of presist bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zhs committed Nov 15, 2018
1 parent 8ed1e6f commit 1dd8f12
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions command/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ func ExpireAt(ctx *Context, txn *db.Transaction) (OnCommit, error) {
func Persist(ctx *Context, txn *db.Transaction) (OnCommit, error) {
kv := txn.Kv()
key := []byte(ctx.Args[0])
obj, err := txn.Object(key)
if err != nil && err != db.ErrKeyNotFound {
return nil, errors.New("ERR " + err.Error())
}
if err == db.ErrKeyNotFound || obj.ExpireAt == 0 {
return Integer(ctx.Out, 0), nil
}

if err := kv.ExpireAt(key, 0); err != nil {
if err == db.ErrKeyNotFound {
return Integer(ctx.Out, 0), nil
Expand Down
6 changes: 6 additions & 0 deletions command/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@ func TestPerist(t *testing.T) {
Call(ctx)
lines = ctxLines(ctx.Out)
assert.Equal(t, ":-1", lines[0])

ctx = ContextTest("persist", key)
Call(ctx)
lines = ctxLines(ctx.Out)
assert.Equal(t, ":0", lines[0])

}

func TestType(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tools/autotest/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (ac *AutoClient) KeyCase(t *testing.T) {
ac.ek.ExpireAtEqual(t, "zkey-listx", int(at), 1)
ac.ek.PersistEqual(t, "zkey-listx", 1)
time.Sleep(time.Second * 2)
ac.ek.PersistEqual(t, "zkey-listx", 1)
ac.ek.PersistEqual(t, "zkey-listx", 0)
}

//SystemCase check system case
Expand Down

0 comments on commit 1dd8f12

Please sign in to comment.