MCPcopy Create free account
hub / github.com/distributedio/titan / Call

Function Call

command/command.go:86–161  ·  view source on GitHub ↗

Call a command

(ctx *Context)

Source from the content-addressed store, hash-verified

84
85// Call a command
86func Call(ctx *Context) {
87 ctx.Name = strings.ToLower(ctx.Name)
88
89 if ctx.Name != "auth" &&
90 ctx.Server.RequirePass != "" &&
91 ctx.Client.Authenticated == false {
92 resp.ReplyError(ctx.Out, ErrNoAuth.Error())
93 return
94 }
95 // Exec all queued commands if this is an exec command
96 if ctx.Name == "exec" {
97 if len(ctx.Args) != 0 {
98 resp.ReplyError(ctx.Out, ErrWrongArgs(ctx.Name).Error())
99 return
100 }
101 // Exec must begin with multi
102 if !ctx.Client.Multi {
103 resp.ReplyError(ctx.Out, ErrExec.Error())
104 return
105 }
106
107 Exec(ctx)
108 feedMonitors(ctx)
109 return
110 }
111 // Discard all queued commands and return
112 if ctx.Name == "discard" {
113 if !ctx.Client.Multi {
114 resp.ReplyError(ctx.Out, ErrDiscard.Error())
115 return
116 }
117
118 Discard(ctx)
119 feedMonitors(ctx)
120 return
121 }
122
123 cmdInfoCommand, ok := commands[ctx.Name]
124 if !ok {
125 resp.ReplyError(ctx.Out, ErrUnKnownCommand(ctx.Name).Error())
126 return
127 }
128 argc := len(ctx.Args) + 1 // include the command name
129 arity := cmdInfoCommand.Cons.Arity
130
131 if arity > 0 && argc != arity {
132 resp.ReplyError(ctx.Out, ErrWrongArgs(ctx.Name).Error())
133 return
134 }
135
136 if arity < 0 && argc < -arity {
137 resp.ReplyError(ctx.Out, ErrWrongArgs(ctx.Name).Error())
138 return
139 }
140
141 // We now in a multi block, queue the command and return
142 if ctx.Client.Multi {
143 if ctx.Name == "multi" {

Callers 15

initListFunction · 0.85
clearListFunction · 0.85
rpushListFunction · 0.85
TestLLenFunction · 0.85
TestLIndexFunction · 0.85
TestLInsertFunction · 0.85
TestLPopFunction · 0.85
TestLPushFunction · 0.85
TestLPushxFunction · 0.85
TestLRangeFunction · 0.85
TestLSetFunction · 0.85
TestRPushFunction · 0.85

Calls 8

ReplyErrorFunction · 0.92
ReplySimpleStringFunction · 0.92
ErrWrongArgsFunction · 0.85
ExecFunction · 0.85
feedMonitorsFunction · 0.85
DiscardFunction · 0.85
ErrUnKnownCommandFunction · 0.85
ErrorMethod · 0.65

Tested by 15

initListFunction · 0.68
clearListFunction · 0.68
rpushListFunction · 0.68
TestLLenFunction · 0.68
TestLIndexFunction · 0.68
TestLInsertFunction · 0.68
TestLPopFunction · 0.68
TestLPushFunction · 0.68
TestLPushxFunction · 0.68
TestLRangeFunction · 0.68
TestLSetFunction · 0.68
TestRPushFunction · 0.68