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

Method TTL

structure/string.go:376–400  ·  view source on GitHub ↗

TTL returns the time to live of a key

(key string)

Source from the content-addressed store, hash-verified

374
375// TTL returns the time to live of a key
376func (s *StringStructure) TTL(key string) (int64, error) {
377 k := stringToBytesWithKey(key)
378
379 // Get the value
380 value, err := s.db.Get(k)
381 if err != nil {
382 return -1, err
383 }
384
385 _, expire, err := decodeStringValue(value)
386 if err != nil {
387 return -1, err
388 }
389
390 if expire == 0 {
391 return 0, nil
392 }
393
394 // Calculate the remaining time to live
395 now := time.Now().UnixNano() / int64(time.Second)
396 expire = expire / int64(time.Second)
397 ttl := expire - now
398
399 return ttl, nil
400}
401
402// Size returns the size of a value
403func (s *StringStructure) Size(key string) (string, error) {

Callers

nothing calls this directly

Calls 3

stringToBytesWithKeyFunction · 0.85
decodeStringValueFunction · 0.85
GetMethod · 0.65

Tested by

no test coverage detected