Strlen returns the length of the string value stored at key
(ctx *Context, txn *db.Transaction)
| 178 | |
| 179 | // Strlen returns the length of the string value stored at key |
| 180 | func 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 |
| 200 | func Append(ctx *Context, txn *db.Transaction) (OnCommit, error) { |