Skip to content

Commit

Permalink
Add STRLEN
Browse files Browse the repository at this point in the history
STRLEN returns the length of the string value stored at key.
An error is returned when key holds a non-string value.
  • Loading branch information
naren committed Sep 29, 2015
1 parent a5cc21c commit 099aa3b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package godis

import (
"errors"
"reflect"
"strconv"
"time"
"unicode/utf8"
)

func (g *Godis) getSDS(key string) (*SDS, bool) {
Expand Down Expand Up @@ -132,3 +134,16 @@ func (g *Godis) MSET(items ...string) bool {
}
return true
}

//STRLEN returns the length of the string value stored at key.
//An error is returned when key holds a non-string value.
func (g *Godis) STRLEN(key string) (interface{}, bool) {
val, err := g.GET(key)

if !err && reflect.ValueOf(val).Kind() == reflect.String {

return int64(utf8.RuneCountInString(val)), false
}
return "", true

}

0 comments on commit 099aa3b

Please sign in to comment.