| 1234567891011121314151617181920212223242526272829303132333435 |
- // Author: simon (ynwdlxm@163.com)
- // Date: 2025/9/15 18:08
- // Desc: 命令列表
- package database
- import (
- "strings"
- "github.com/runningwater/go-redis/lib/logger"
- )
- // 命令表
- var cmdTable = make(map[string]*command)
- type command struct {
- executor ExecFunc // 执行函数
- arity int // 参数个数, >0表示确切数量, <0表示最少数量, =0表示无参数也不接受参数
- }
- // RegisterCommand 将命令注册到命令表中
- // 参数:
- //
- // name: 命令名称
- // executor: 命令执行函数
- // arity: 命令参数个数,=0表示无参数,>0表示确切的参数个数,<0表示至少有N个参数(N=-arity
- func RegisterCommand(name string, executor ExecFunc, arity int) {
- name = strings.ToLower(name)
- logger.Debug("Register command:", strings.ToUpper(name))
- cmdTable[name] = &command{
- executor: executor,
- arity: arity,
- }
- }
|