code: func (tx *Tx) Commit() error {
  	if tx.funcd {
  		panic("managed tx commit not allowed")
  	}
  	if tx.db == nil {
  		return ErrTxClosed
  	} else if !tx.writable {
  		return ErrTxNotWritable
  	}
  	var err error
  	if tx.db.persist && (len(tx.wc.commitItems) > 0 || tx.wc.rbkeys != nil) {
  		tx.db.buf = tx.db.buf[:0]
  		// write a flushdb if a deleteAll was called.
  		if tx.wc.rbkeys != nil {
  			tx.db.buf = append(tx.db.buf, "*1\r\n$7\r\nflushdb\r\n"...)
  		}
  		// Each committed record is written to disk
  		for key, item := range tx.wc.commitItems {
  			if item == nil {
  				tx.db.buf = (&dbItem{key: key}).writeDeleteTo(tx.db.buf)
  			} else {
  				tx.db.buf = item.writeSetTo(tx.db.buf)
  			}
  		}
  		// Flushing the buffer only once per transaction.
  		// If this operation fails then the write did failed and we must
  		// rollback.
  		if _, err = tx.db.file.Write(tx.db.buf); err != nil {
  			tx.rollbackInner()
  		}
  		if tx.db.config.SyncPolicy == Always {
  			_ = tx.db.file.Sync()
  		}
  		// Increment the number of flushes. The background syncing uses this.
  		tx.db.flushes++
  	}
  	// Unlock the database and allow for another writable transaction.
  	tx.unlock()
  	// Clear the db field to disable this transaction from future use.
  	tx.db = nil
  	return err
  }
docs: // Commit writes all changes to disk.
  // An error is returned when a write error occurs, or when a Commit() is called
  // from a read-only transaction.