fixed set return value

This commit is contained in:
Josh Baker 2016-08-18 13:21:46 -07:00
parent 1daaa16172
commit 9301f51db3
2 changed files with 27 additions and 2 deletions

View File

@ -1152,8 +1152,8 @@ func (tx *Tx) Set(key, value string, opts *SetOptions) (previousValue string,
if _, ok := tx.rollbacks[key]; !ok {
tx.rollbacks[key] = prev
}
if !item.expired() {
previousValue, replaced = item.val, true
if !prev.expired() {
previousValue, replaced = prev.val, true
}
}
// For commits we simply assign the item to the map. We use this map to

View File

@ -1717,6 +1717,31 @@ func TestCoverShrinkShrink(t *testing.T) {
}
}
func TestPreviousItem(t *testing.T) {
db := testOpen(t)
defer testClose(db)
err := db.Update(func(tx *Tx) error {
_, _, err := tx.Set("hello", "world", nil)
if err != nil {
return err
}
prev, replaced, err := tx.Set("hello", "planet", nil)
if err != nil {
return err
}
if !replaced {
t.Fatal("should be replaced")
}
if prev != "world" {
t.Fatalf("expecting '%v', got '%v'", "world", prev)
}
return nil
})
if err != nil {
t.Fatal(err)
}
}
func TestJSONIndex(t *testing.T) {
db := testOpen(t)
defer testClose(db)