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

Function Strlen

command/strings.go:180–197  ·  view source on GitHub ↗

Strlen returns the length of the string value stored at key

(ctx *Context, txn *db.Transaction)

Source from the content-addressed store, hash-verified

178
179// Strlen returns the length of the string value stored at key
180func Strlen(ctx *Context, txn *db.Transaction) (OnCommit, error) {
181 key := ctx.Args[0]
182 str, err := txn.String([]byte(key))
183 if err != nil {
184 if err == db.ErrTypeMismatch {
185 return nil, ErrTypeMismatch
186 }
187 return nil, errors.New("ERR " + err.Error())
188 }
189
190 if !str.Exist() {
191 return Integer(ctx.Out, int64(0)), nil
192 }
193
194 v, _ := str.Len()
195
196 return Integer(ctx.Out, int64(v)), nil
197}
198
199// Append a value to a key
200func Append(ctx *Context, txn *db.Transaction) (OnCommit, error) {

Callers

nothing calls this directly

Calls 5

IntegerFunction · 0.85
ErrorMethod · 0.65
ExistMethod · 0.65
StringMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected