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) {
var ts, to int32
if ts, to, err = db.bGetMeta(key); err != nil {
var tseq, toff int32
var update bool = false
if tseq, toff, err = db.bGetMeta(key); err != nil {
return
} else if tseq < 0 {
update = true
} else {
tailSeq = uint32(MaxInt32(ts, 0))
tailOff = uint32(MaxInt32(to, 0))
tailSeq = uint32(MaxInt32(tseq, 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)
tailSeq = seq
tailOff = off

View File

@ -41,6 +41,7 @@ func TestBinary(t *testing.T) {
testOpXor(t)
testOpNot(t)
testMSetBit(t)
testBitExpire(t)
}
func testSimple(t *testing.T) {
@ -518,3 +519,20 @@ func testMSetBit(t *testing.T) {
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)
}
}