mirror of
https://github.com/sot-tech/mochi.git
synced 2026-06-15 00:53:36 -07:00
The rest of the files needed to pass Redis tests
This commit is contained in:
Vendored
+1
@@ -17,6 +17,7 @@ import (
|
||||
var (
|
||||
drivers = make(map[string]Driver)
|
||||
ErrTxDone = errors.New("cache: Transaction has already been committed or rolled back")
|
||||
ErrTxConflict = errors.New("cache: Commit interrupted, update transaction and repeat")
|
||||
)
|
||||
|
||||
type Driver interface {
|
||||
|
||||
Vendored
+11
-2
@@ -106,6 +106,7 @@ func (tx *Tx) initiateWrite() error {
|
||||
return cache.ErrTxDone
|
||||
}
|
||||
if tx.multi != true {
|
||||
tx.multi = true
|
||||
return tx.Send("MULTI")
|
||||
}
|
||||
return nil
|
||||
@@ -126,7 +127,11 @@ func (tx *Tx) Commit() error {
|
||||
return cache.ErrTxDone
|
||||
}
|
||||
if tx.multi == true {
|
||||
_, err := tx.Do("EXEC")
|
||||
execResponse, err := tx.Do("EXEC")
|
||||
if execResponse == nil {
|
||||
tx.multi = false
|
||||
return cache.ErrTxConflict
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -139,7 +144,11 @@ func (tx *Tx) Rollback() error {
|
||||
if tx.done {
|
||||
return cache.ErrTxDone
|
||||
}
|
||||
// Redis doesn't need to do anything. Exec is atomic.
|
||||
// Undoes watches and multi
|
||||
if _, err := tx.Do("DISCARD") ; err != nil {
|
||||
return err
|
||||
}
|
||||
tx.multi = false
|
||||
tx.close()
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user