Merge pull request #738 from fxk2006/fix_SessionRedis

This commit is contained in:
John Guo 2020-06-16 20:41:53 +08:00 committed by GitHub
commit 55f9b121de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -8,10 +8,11 @@ package gsession
import (
"encoding/json"
"time"
"github.com/gogf/gf/container/gmap"
"github.com/gogf/gf/database/gredis"
"github.com/gogf/gf/internal/intlog"
"time"
"github.com/gogf/gf/os/gtimer"
)
@ -147,7 +148,7 @@ func (s *StorageRedis) SetSession(id string, data *gmap.StrAnyMap, ttl time.Dura
if err != nil {
return err
}
_, err = s.redis.DoVar("SETEX", s.key(id), ttl.Seconds(), content)
_, err = s.redis.DoVar("SETEX", s.key(id), int64(ttl.Seconds()), content)
return err
}

View File

@ -7,11 +7,12 @@
package gsession
import (
"time"
"github.com/gogf/gf/container/gmap"
"github.com/gogf/gf/database/gredis"
"github.com/gogf/gf/internal/intlog"
"github.com/gogf/gf/util/gconv"
"time"
)
// StorageRedisHashTable implements the Session Storage interface with redis hash table.
@ -134,7 +135,7 @@ func (s *StorageRedisHashTable) GetSession(id string, ttl time.Duration, data *g
// This copy all session data map from memory to storage.
func (s *StorageRedisHashTable) SetSession(id string, data *gmap.StrAnyMap, ttl time.Duration) error {
intlog.Printf("StorageRedisHashTable.SetSession: %s, %v", id, ttl)
_, err := s.redis.Do("EXPIRE", s.key(id), ttl.Seconds())
_, err := s.redis.Do("EXPIRE", s.key(id), int64(ttl.Seconds()))
return err
}
@ -143,7 +144,7 @@ func (s *StorageRedisHashTable) SetSession(id string, data *gmap.StrAnyMap, ttl
// It just adds the session id to the async handling queue.
func (s *StorageRedisHashTable) UpdateTTL(id string, ttl time.Duration) error {
intlog.Printf("StorageRedisHashTable.UpdateTTL: %s, %v", id, ttl)
_, err := s.redis.Do("EXPIRE", s.key(id), ttl.Seconds())
_, err := s.redis.Do("EXPIRE", s.key(id), int64(ttl.Seconds()))
return err
}