mirror of https://github.com/tidwall/buntdb.git
fixed set return value
This commit is contained in:
parent
1daaa16172
commit
9301f51db3
|
@ -1152,8 +1152,8 @@ func (tx *Tx) Set(key, value string, opts *SetOptions) (previousValue string,
|
||||||
if _, ok := tx.rollbacks[key]; !ok {
|
if _, ok := tx.rollbacks[key]; !ok {
|
||||||
tx.rollbacks[key] = prev
|
tx.rollbacks[key] = prev
|
||||||
}
|
}
|
||||||
if !item.expired() {
|
if !prev.expired() {
|
||||||
previousValue, replaced = item.val, true
|
previousValue, replaced = prev.val, true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// For commits we simply assign the item to the map. We use this map to
|
// For commits we simply assign the item to the map. We use this map to
|
||||||
|
|
|
@ -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) {
|
func TestJSONIndex(t *testing.T) {
|
||||||
db := testOpen(t)
|
db := testOpen(t)
|
||||||
defer testClose(db)
|
defer testClose(db)
|
||||||
|
|
Loading…
Reference in New Issue