mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-10 03:00:29 +08:00
support multi transaction
This commit is contained in:
67
exec_helper.go
Normal file
67
exec_helper.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package godis
|
||||
|
||||
import (
|
||||
"github.com/hdt3213/godis/interface/redis"
|
||||
"github.com/hdt3213/godis/redis/reply"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func execNormalCommand(db *DB, cmdArgs [][]byte) redis.Reply {
|
||||
cmdName := strings.ToLower(string(cmdArgs[0]))
|
||||
cmd, ok := cmdTable[cmdName]
|
||||
if !ok {
|
||||
return reply.MakeErrReply("ERR unknown command '" + cmdName + "'")
|
||||
}
|
||||
if !validateArity(cmd.arity, cmdArgs) {
|
||||
return reply.MakeArgNumErrReply(cmdName)
|
||||
}
|
||||
|
||||
prepare := cmd.prepare
|
||||
write, read := prepare(cmdArgs[1:])
|
||||
db.RWLocks(write, read)
|
||||
defer db.RWUnLocks(write, read)
|
||||
fun := cmd.executor
|
||||
return fun(db, cmdArgs[1:])
|
||||
}
|
||||
|
||||
// ExecWithLock executes normal commands, invoker should provide locks
|
||||
func (db *DB) ExecWithLock(cmdLine [][]byte) redis.Reply {
|
||||
cmdName := strings.ToLower(string(cmdLine[0]))
|
||||
cmd, ok := cmdTable[cmdName]
|
||||
if !ok {
|
||||
return reply.MakeErrReply("ERR unknown command '" + cmdName + "'")
|
||||
}
|
||||
if !validateArity(cmd.arity, cmdLine) {
|
||||
return reply.MakeArgNumErrReply(cmdName)
|
||||
}
|
||||
fun := cmd.executor
|
||||
return fun(db, cmdLine[1:])
|
||||
}
|
||||
|
||||
// GetRelatedKeys analysis related keys
|
||||
func (db *DB) GetRelatedKeys(cmdLine [][]byte) ([]string, []string) {
|
||||
cmdName := strings.ToLower(string(cmdLine[0]))
|
||||
cmd, ok := cmdTable[cmdName]
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
prepare := cmd.prepare
|
||||
if prepare == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return prepare(cmdLine[1:])
|
||||
}
|
||||
|
||||
// GetUndoLogs return rollback commands
|
||||
func (db *DB) GetUndoLogs(cmdLine [][]byte) []CmdLine {
|
||||
cmdName := strings.ToLower(string(cmdLine[0]))
|
||||
cmd, ok := cmdTable[cmdName]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
undo := cmd.undo
|
||||
if undo == nil {
|
||||
return nil
|
||||
}
|
||||
return undo(db, cmdLine[1:])
|
||||
}
|
Reference in New Issue
Block a user