ledisdb/store/mdb/batch.go

36 lines
519 B
Go
Raw Normal View History

2014-07-25 13:58:00 +04:00
package mdb
type Write struct {
Key []byte
Value []byte
}
type WriteBatch struct {
2014-07-25 15:41:04 +04:00
db *MDB
2014-07-25 13:58:00 +04:00
wb []Write
}
2014-07-25 15:41:04 +04:00
func (w *WriteBatch) Close() error {
2014-07-25 13:58:00 +04:00
return nil
}
2014-07-25 15:41:04 +04:00
func (w *WriteBatch) Put(key, value []byte) {
2014-07-29 04:58:13 +04:00
if value == nil {
value = []byte{}
}
2014-07-25 13:58:00 +04:00
w.wb = append(w.wb, Write{key, value})
}
2014-07-25 15:41:04 +04:00
func (w *WriteBatch) Delete(key []byte) {
2014-07-25 13:58:00 +04:00
w.wb = append(w.wb, Write{key, nil})
}
2014-07-25 15:41:04 +04:00
func (w *WriteBatch) Commit() error {
2014-07-25 13:58:00 +04:00
return w.db.BatchPut(w.wb)
}
2014-07-25 15:41:04 +04:00
func (w *WriteBatch) Rollback() error {
2014-07-25 19:40:10 +04:00
w.wb = w.wb[0:0]
2014-07-25 13:58:00 +04:00
return nil
}