本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
633B

  1. package driver
  2. type BatchPuter interface {
  3. BatchPut([]Write) error
  4. }
  5. type Write struct {
  6. Key []byte
  7. Value []byte
  8. }
  9. type WriteBatch struct {
  10. batch BatchPuter
  11. wb []Write
  12. }
  13. func (w *WriteBatch) Put(key, value []byte) {
  14. if value == nil {
  15. value = []byte{}
  16. }
  17. w.wb = append(w.wb, Write{key, value})
  18. }
  19. func (w *WriteBatch) Delete(key []byte) {
  20. w.wb = append(w.wb, Write{key, nil})
  21. }
  22. func (w *WriteBatch) Commit() error {
  23. return w.batch.BatchPut(w.wb)
  24. }
  25. func (w *WriteBatch) Rollback() error {
  26. w.wb = w.wb[0:0]
  27. return nil
  28. }
  29. func NewWriteBatch(puter BatchPuter) IWriteBatch {
  30. return &WriteBatch{puter, []Write{}}
  31. }
上海开阖软件有限公司 沪ICP备12045867号-1