ledisdb/store/writebatch.go

42 lines
712 B
Go
Raw Normal View History

2014-07-25 13:58:00 +04:00
package store
import (
"github.com/siddontang/ledisdb/store/driver"
)
2014-10-15 06:18:20 +04:00
type WriteBatch struct {
2014-10-16 05:35:35 +04:00
wb driver.IWriteBatch
2014-10-15 06:18:20 +04:00
st *Stat
putNum int64
deleteNum int64
2014-10-16 05:35:35 +04:00
db *DB
2014-10-15 06:18:20 +04:00
}
func (wb *WriteBatch) Put(key []byte, value []byte) {
wb.putNum++
2014-10-16 05:35:35 +04:00
wb.wb.Put(key, value)
2014-10-15 06:18:20 +04:00
}
func (wb *WriteBatch) Delete(key []byte) {
wb.deleteNum++
2014-10-16 05:35:35 +04:00
wb.wb.Delete(key)
2014-10-15 06:18:20 +04:00
}
func (wb *WriteBatch) Commit() error {
wb.st.BatchCommitNum.Add(1)
wb.st.PutNum.Add(wb.putNum)
wb.st.DeleteNum.Add(wb.deleteNum)
wb.putNum = 0
wb.deleteNum = 0
2014-10-16 05:35:35 +04:00
if wb.db == nil || !wb.db.needSyncCommit() {
return wb.wb.Commit()
} else {
return wb.wb.SyncCommit()
}
2014-10-15 06:18:20 +04:00
}
func (wb *WriteBatch) Rollback() error {
2014-10-16 05:35:35 +04:00
return wb.wb.Rollback()
2014-07-25 13:58:00 +04:00
}