MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / cmdHSETNX

Function cmdHSETNX

hashes.go:216–237  ·  view source on GitHub ↗
(m uhaha.Machine, args []string)

Source from the content-addressed store, hash-verified

214
215 return redcon.SimpleString("OK"), nil
216}
217
218func cmdHSETNX(m uhaha.Machine, args []string) (interface{}, error) {
219 if len(args) != 4 {
220 return nil, uhaha.ErrWrongNumArgs
221 }
222
223 var n int64 = 1
224 v, err := ldb.HGet([]byte(args[1]), []byte(args[2]))
225 if err != nil {
226 return nil, err
227 }
228 if v != nil { //Data exists, return zero
229 n = 0
230 return redcon.SimpleInt(n), nil
231 }
232
233 n, err = ldb.HSet([]byte(args[1]), []byte(args[2]), []byte(args[3]))
234 if err != nil {
235 return nil, err
236 }
237
238 return n, nil
239}
240

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected