2014-09-02 13:55:12 +04:00
|
|
|
package ledis
|
|
|
|
|
2015-03-14 04:10:00 +03:00
|
|
|
// import (
|
|
|
|
// "errors"
|
|
|
|
// "fmt"
|
|
|
|
// )
|
2014-09-02 13:55:12 +04:00
|
|
|
|
2015-03-14 04:10:00 +03:00
|
|
|
// var (
|
|
|
|
// ErrNestMulti = errors.New("nest multi not supported")
|
|
|
|
// ErrMultiDone = errors.New("multi has been closed")
|
|
|
|
// )
|
2014-09-02 13:55:12 +04:00
|
|
|
|
2015-03-14 04:10:00 +03:00
|
|
|
// type Multi struct {
|
|
|
|
// *DB
|
|
|
|
// }
|
2014-09-02 13:55:12 +04:00
|
|
|
|
2015-03-14 04:10:00 +03:00
|
|
|
// func (db *DB) IsInMulti() bool {
|
|
|
|
// return db.status == DBInMulti
|
|
|
|
// }
|
2014-09-02 13:55:12 +04:00
|
|
|
|
2015-03-14 04:10:00 +03:00
|
|
|
// // begin a mutli to execute commands,
|
|
|
|
// // it will block any other write operations before you close the multi, unlike transaction, mutli can not rollback
|
|
|
|
// func (db *DB) Multi() (*Multi, error) {
|
|
|
|
// if db.IsInMulti() {
|
|
|
|
// return nil, ErrNestMulti
|
|
|
|
// }
|
2014-09-02 13:55:12 +04:00
|
|
|
|
2015-03-14 04:10:00 +03:00
|
|
|
// m := new(Multi)
|
2014-09-02 13:55:12 +04:00
|
|
|
|
2015-03-14 04:10:00 +03:00
|
|
|
// m.DB = new(DB)
|
|
|
|
// m.DB.status = DBInMulti
|
2014-09-02 13:55:12 +04:00
|
|
|
|
2015-03-14 04:10:00 +03:00
|
|
|
// m.DB.l = db.l
|
2014-09-02 13:55:12 +04:00
|
|
|
|
2015-03-14 04:10:00 +03:00
|
|
|
// m.l.wLock.Lock()
|
2014-09-02 13:55:12 +04:00
|
|
|
|
2015-03-14 04:10:00 +03:00
|
|
|
// m.DB.sdb = db.sdb
|
2014-09-02 13:55:12 +04:00
|
|
|
|
2015-03-14 04:10:00 +03:00
|
|
|
// m.DB.bucket = db.sdb
|
2014-09-02 13:55:12 +04:00
|
|
|
|
2015-03-14 04:10:00 +03:00
|
|
|
// m.DB.index = db.index
|
2014-09-02 13:55:12 +04:00
|
|
|
|
2015-03-14 04:10:00 +03:00
|
|
|
// m.DB.kvBatch = m.newBatch()
|
|
|
|
// m.DB.listBatch = m.newBatch()
|
|
|
|
// m.DB.hashBatch = m.newBatch()
|
|
|
|
// m.DB.zsetBatch = m.newBatch()
|
|
|
|
// // m.DB.binBatch = m.newBatch()
|
|
|
|
// m.DB.setBatch = m.newBatch()
|
2014-09-02 13:55:12 +04:00
|
|
|
|
2015-03-14 04:10:00 +03:00
|
|
|
// m.DB.lbkeys = db.lbkeys
|
2014-10-16 13:51:52 +04:00
|
|
|
|
2015-03-14 04:10:00 +03:00
|
|
|
// return m, nil
|
|
|
|
// }
|
2014-09-02 13:55:12 +04:00
|
|
|
|
2015-03-14 04:10:00 +03:00
|
|
|
// func (m *Multi) newBatch() *batch {
|
|
|
|
// return m.l.newBatch(m.bucket.NewWriteBatch(), &multiBatchLocker{}, nil)
|
|
|
|
// }
|
2014-09-02 13:55:12 +04:00
|
|
|
|
2015-03-14 04:10:00 +03:00
|
|
|
// func (m *Multi) Close() error {
|
|
|
|
// if m.bucket == nil {
|
|
|
|
// return ErrMultiDone
|
|
|
|
// }
|
|
|
|
// m.l.wLock.Unlock()
|
|
|
|
// m.bucket = nil
|
|
|
|
// return nil
|
|
|
|
// }
|
2014-09-02 13:55:12 +04:00
|
|
|
|
2015-03-14 04:10:00 +03:00
|
|
|
// func (m *Multi) Select(index int) error {
|
|
|
|
// if index < 0 || index >= int(m.l.cfg.Databases) {
|
|
|
|
// return fmt.Errorf("invalid db index %d", index)
|
|
|
|
// }
|
2014-09-02 13:55:12 +04:00
|
|
|
|
2015-03-14 04:10:00 +03:00
|
|
|
// m.DB.index = uint8(index)
|
|
|
|
// return nil
|
|
|
|
// }
|