MCPcopy
hub / github.com/olric-data/olric / ParsePutCommand

Function ParsePutCommand

internal/protocol/dmap.go:118–178  ·  view source on GitHub ↗
(cmd redcon.Command)

Source from the content-addressed store, hash-verified

116}
117
118func ParsePutCommand(cmd redcon.Command) (*Put, error) {
119 if len(cmd.Args) < 4 {
120 return nil, errWrongNumber(cmd.Args)
121 }
122
123 p := NewPut(
124 util.BytesToString(cmd.Args[1]), // DMap
125 util.BytesToString(cmd.Args[2]), // Key
126 cmd.Args[3], // Value
127 )
128
129 args := cmd.Args[4:]
130 for len(args) > 0 {
131 switch arg := strings.ToUpper(util.BytesToString(args[0])); arg {
132 case "NX":
133 p.SetNX()
134 args = args[1:]
135 continue
136 case "XX":
137 p.SetXX()
138 args = args[1:]
139 continue
140 case "PX":
141 px, err := strconv.ParseInt(util.BytesToString(args[1]), 10, 64)
142 if err != nil {
143 return nil, err
144 }
145 p.SetPX(px)
146 args = args[2:]
147 continue
148 case "EX":
149 ex, err := strconv.ParseFloat(util.BytesToString(args[1]), 64)
150 if err != nil {
151 return nil, err
152 }
153 p.SetEX(ex)
154 args = args[2:]
155 continue
156 case "EXAT":
157 exat, err := strconv.ParseFloat(util.BytesToString(args[1]), 64)
158 if err != nil {
159 return nil, err
160 }
161 p.SetEXAT(exat)
162 args = args[2:]
163 continue
164 case "PXAT":
165 pxat, err := strconv.ParseInt(util.BytesToString(args[1]), 10, 64)
166 if err != nil {
167 return nil, err
168 }
169 p.SetPXAT(pxat)
170 args = args[2:]
171 continue
172 default:
173 return nil, errors.New("syntax error")
174 }
175 }

Calls 9

SetNXMethod · 0.95
SetXXMethod · 0.95
SetPXMethod · 0.95
SetEXMethod · 0.95
SetEXATMethod · 0.95
SetPXATMethod · 0.95
BytesToStringFunction · 0.92
errWrongNumberFunction · 0.85
NewPutFunction · 0.85