forked from mirror/ledisdb
37 lines
545 B
Go
37 lines
545 B
Go
package mdb
|
|
|
|
type batchPut interface {
|
|
BatchPut([]Write) error
|
|
}
|
|
|
|
type Write struct {
|
|
Key []byte
|
|
Value []byte
|
|
}
|
|
|
|
type WriteBatch struct {
|
|
batch batchPut
|
|
wb []Write
|
|
}
|
|
|
|
func (w *WriteBatch) Close() error {
|
|
return nil
|
|
}
|
|
|
|
func (w *WriteBatch) Put(key, value []byte) {
|
|
w.wb = append(w.wb, Write{key, value})
|
|
}
|
|
|
|
func (w *WriteBatch) Delete(key []byte) {
|
|
w.wb = append(w.wb, Write{key, nil})
|
|
}
|
|
|
|
func (w *WriteBatch) Commit() error {
|
|
return w.batch.BatchPut(w.wb)
|
|
}
|
|
|
|
func (w *WriteBatch) Rollback() error {
|
|
w.wb = w.wb[0:0]
|
|
return nil
|
|
}
|