mirror of
https://github.com/kataras/iris.git
synced 2025-03-14 08:26:26 +01:00
fix / redis service.TTL() returns seconds, hasExpiration, found
Former-commit-id: 25743848458f2a6cf3e78d5ae119d2ba2a822f79
This commit is contained in:
parent
768dd76b62
commit
4e7ca254d9
|
@ -3,7 +3,6 @@ package service
|
|||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gomodule/redigo/redis"
|
||||
"github.com/kataras/iris/core/errors"
|
||||
)
|
||||
|
@ -84,7 +83,7 @@ func (r *Service) Get(key string) (interface{}, error) {
|
|||
|
||||
// TTL returns the seconds to expire, if the key has expiration and error if action failed.
|
||||
// Read more at: https://redis.io/commands/ttl
|
||||
func (r *Service) TTL(key string) (seconds int64, hasExpiration bool, ok bool) {
|
||||
func (r *Service) TTL(key string) (seconds int64, hasExpiration bool, found bool) {
|
||||
c := r.pool.Get()
|
||||
defer c.Close()
|
||||
redisVal, err := c.Do("TTL", r.Config.Prefix+key)
|
||||
|
@ -93,14 +92,15 @@ func (r *Service) TTL(key string) (seconds int64, hasExpiration bool, ok bool) {
|
|||
}
|
||||
seconds = redisVal.(int64)
|
||||
// if -1 means the key has unlimited life time.
|
||||
hasExpiration = seconds == -1
|
||||
hasExpiration = seconds > -1
|
||||
// if -2 means key does not exist.
|
||||
ok = (c.Err() != nil || seconds == -2)
|
||||
found = ! (c.Err() != nil || seconds == -2)
|
||||
return
|
||||
}
|
||||
|
||||
func (r *Service) updateTTLConn(c redis.Conn, key string, newSecondsLifeTime int64) error {
|
||||
reply, err := c.Do("EXPIRE", r.Config.Prefix+key, newSecondsLifeTime)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user