TTL returns the time to live of a key
(key string)
| 374 | |
| 375 | // TTL returns the time to live of a key |
| 376 | func (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 |
| 403 | func (s *StringStructure) Size(key string) (string, error) { |
nothing calls this directly
no test coverage detected