mirror of
https://github.com/kataras/iris.git
synced 2025-03-14 08:16:28 +01:00
Merge pull request #1064 from akiraho/master
various fixes on redis as sessions db Former-commit-id: 0fb804f095c37d340eeaf595806329a67c5b43ac
This commit is contained in:
commit
197fb5d113
|
@ -43,6 +43,7 @@ func (lt *LifeTime) Revive(onExpire func()) {
|
||||||
// Shift resets the lifetime based on "d".
|
// Shift resets the lifetime based on "d".
|
||||||
func (lt *LifeTime) Shift(d time.Duration) {
|
func (lt *LifeTime) Shift(d time.Duration) {
|
||||||
if d > 0 && lt.timer != nil {
|
if d > 0 && lt.timer != nil {
|
||||||
|
lt.Time = time.Now().Add(d)
|
||||||
lt.timer.Reset(d)
|
lt.timer.Reset(d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package service
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gomodule/redigo/redis"
|
"github.com/gomodule/redigo/redis"
|
||||||
"github.com/kataras/iris/core/errors"
|
"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.
|
// TTL returns the seconds to expire, if the key has expiration and error if action failed.
|
||||||
// Read more at: https://redis.io/commands/ttl
|
// 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()
|
c := r.pool.Get()
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
redisVal, err := c.Do("TTL", r.Config.Prefix+key)
|
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)
|
seconds = redisVal.(int64)
|
||||||
// if -1 means the key has unlimited life time.
|
// if -1 means the key has unlimited life time.
|
||||||
hasExpiration = seconds == -1
|
hasExpiration = seconds > -1
|
||||||
// if -2 means key does not exist.
|
// if -2 means key does not exist.
|
||||||
ok = (c.Err() != nil || seconds == -2)
|
found = ! (c.Err() != nil || seconds == -2)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Service) updateTTLConn(c redis.Conn, key string, newSecondsLifeTime int64) error {
|
func (r *Service) updateTTLConn(c redis.Conn, key string, newSecondsLifeTime int64) error {
|
||||||
reply, err := c.Do("EXPIRE", r.Config.Prefix+key, newSecondsLifeTime)
|
reply, err := c.Do("EXPIRE", r.Config.Prefix+key, newSecondsLifeTime)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -201,7 +201,7 @@ func (r *Service) getKeysConn(c redis.Conn, prefix string) ([]string, error) {
|
||||||
if keysSliceAsBytes, ok := keysInterface[1].([]interface{}); ok {
|
if keysSliceAsBytes, ok := keysInterface[1].([]interface{}); ok {
|
||||||
keys := make([]string, len(keysSliceAsBytes), len(keysSliceAsBytes))
|
keys := make([]string, len(keysSliceAsBytes), len(keysSliceAsBytes))
|
||||||
for i, k := range keysSliceAsBytes {
|
for i, k := range keysSliceAsBytes {
|
||||||
keys[i] = fmt.Sprintf("%s", k)
|
keys[i] = fmt.Sprintf("%s", k)[len(r.Config.Prefix):]
|
||||||
}
|
}
|
||||||
|
|
||||||
return keys, nil
|
return keys, nil
|
||||||
|
|
Loading…
Reference in New Issue
Block a user