fix expire fail while target key length of 1 bit

This commit is contained in:
silentsai 2014-08-15 15:42:25 +08:00
parent 6c9d38fab7
commit 57b5b33ebb
2 changed files with 28 additions and 5 deletions

View File

@ -231,15 +231,20 @@ func (db *DB) bSetMeta(t *tx, key []byte, tailSeq uint32, tailOff uint32) {
} }
func (db *DB) bUpdateMeta(t *tx, key []byte, seq uint32, off uint32) (tailSeq uint32, tailOff uint32, err error) { func (db *DB) bUpdateMeta(t *tx, key []byte, seq uint32, off uint32) (tailSeq uint32, tailOff uint32, err error) {
var ts, to int32 var tseq, toff int32
if ts, to, err = db.bGetMeta(key); err != nil { var update bool = false
if tseq, toff, err = db.bGetMeta(key); err != nil {
return return
} else if tseq < 0 {
update = true
} else { } else {
tailSeq = uint32(MaxInt32(ts, 0)) tailSeq = uint32(MaxInt32(tseq, 0))
tailOff = uint32(MaxInt32(to, 0)) tailOff = uint32(MaxInt32(toff, 0))
update = (seq > tailSeq || (seq == tailSeq && off > tailOff))
} }
if seq > tailSeq || (seq == tailSeq && off > tailOff) { if update {
db.bSetMeta(t, key, seq, off) db.bSetMeta(t, key, seq, off)
tailSeq = seq tailSeq = seq
tailOff = off tailOff = off

View File

@ -41,6 +41,7 @@ func TestBinary(t *testing.T) {
testOpXor(t) testOpXor(t)
testOpNot(t) testOpNot(t)
testMSetBit(t) testMSetBit(t)
testBitExpire(t)
} }
func testSimple(t *testing.T) { func testSimple(t *testing.T) {
@ -518,3 +519,20 @@ func testMSetBit(t *testing.T) {
return return
} }
func testBitExpire(t *testing.T) {
db := getTestDB()
db.FlushAll()
key := []byte("test_b_ttl")
db.BSetBit(key, 0, 1)
if res, err := db.BExpire(key, 100); res != 1 || err != nil {
t.Fatal(false)
}
if ttl, err := db.BTTL(key); ttl != 100 || err != nil {
t.Fatal(false)
}
}