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

Function cmdSTRLEN

strings.go:98–124  ·  view source on GitHub ↗

cmdSTRLEN returns the length of the string value stored at key. If the key does not exist, it returns 0.

(m uhaha.Machine, args []string)

Source from the content-addressed store, hash-verified

96
97// cmdSTRLEN returns the length of the string value stored at key.
98// If the key does not exist, it returns 0.
99func cmdSTRLEN(m uhaha.Machine, args []string) (interface{}, error) {
100 // 1. Validate the number of arguments
101 if len(args) != 2 {
102 return nil, uhaha.ErrWrongNumArgs
103 }
104
105 // 2. Get the key name
106 key := []byte(args[1])
107
108 // 3. Check if the key exists
109 exists, err := ldb.Exists(key)
110
111 // If the key does not exist or an error occurs, return 0 and the error
112 if exists == 0 || err != nil {
113 return redcon.SimpleInt(0), err
114 }
115
116 // 4. Get the length of the string value stored at the key
117 n, err := ldb.StrLen(key)
118 if err != nil {
119 // If an error occurs, return 0 and the error
120 return redcon.SimpleInt(0), err
121 }
122
123 // 5. Return the length of the string
124 return redcon.SimpleInt(n), nil
125}
126
127// cmdSETRANGE overwrites part of the string stored at key, starting at the specified offset,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected