MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / StrLen

Method StrLen

structure/string.go:141–157  ·  view source on GitHub ↗

StrLen returns the length of the value of a key If the key does not exist, it will return 0 If the key exists, it will return the length of the value If the key is expired, it will be deleted and return 0 If the key is not expired, it will be updated and return the length of the value

(k string)

Source from the content-addressed store, hash-verified

139// If the key is expired, it will be deleted and return 0
140// If the key is not expired, it will be updated and return the length of the value
141func (s *StringStructure) StrLen(k string) (int, error) {
142 key := stringToBytesWithKey(k)
143 // Get the value
144 value, err := s.db.Get(key)
145 if err != nil {
146 return 0, err
147 }
148
149 // Decode the value
150 value, _, err = decodeStringValue(value)
151 if err != nil {
152 return 0, err
153 }
154
155 // Return the length of the value
156 return len(value), nil
157}
158
159// GetSet sets the value of a key and returns its old value
160func (s *StringStructure) GetSet(key string, value interface{}, ttl int64) (interface{}, error) {

Callers

nothing calls this directly

Calls 3

stringToBytesWithKeyFunction · 0.85
decodeStringValueFunction · 0.85
GetMethod · 0.65

Tested by

no test coverage detected