improve package gredis

This commit is contained in:
John Guo
2021-01-16 20:37:59 +08:00
parent 2c5e6b379f
commit aefa54f04b
3 changed files with 14 additions and 10 deletions

View File

@ -1,4 +1,4 @@
// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
@ -68,8 +68,10 @@ func NewStorageFile(path ...string) *StorageFile {
// Batch updates the TTL for session ids timely.
gtimer.AddSingleton(DefaultStorageFileLoopInterval, func() {
//intlog.Print("StorageFile.timer start")
var id string
var err error
var (
id string
err error
)
for {
if id = s.updatingIdSet.Pop(); id == "" {
break
@ -221,7 +223,7 @@ func (s *StorageFile) SetSession(id string, data *gmap.StrAnyMap, ttl time.Durat
// It just adds the session id to the async handling queue.
func (s *StorageFile) UpdateTTL(id string, ttl time.Duration) error {
intlog.Printf("StorageFile.UpdateTTL: %s, %v", id, ttl)
if ttl >= DefaultStorageRedisLoopInterval {
if ttl >= DefaultStorageFileLoopInterval {
s.updatingIdSet.Add(id)
}
return nil

View File

@ -1,4 +1,4 @@
// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
@ -26,7 +26,7 @@ type StorageRedis struct {
var (
// DefaultStorageRedisLoopInterval is the interval updating TTL for session ids
// in last duration.
DefaultStorageRedisLoopInterval = time.Minute
DefaultStorageRedisLoopInterval = 10 * time.Second
)
// NewStorageRedis creates and returns a redis storage object for session.
@ -45,9 +45,11 @@ func NewStorageRedis(redis *gredis.Redis, prefix ...string) *StorageRedis {
// Batch updates the TTL for session ids timely.
gtimer.AddSingleton(DefaultStorageRedisLoopInterval, func() {
intlog.Print("StorageRedis.timer start")
var id string
var err error
var ttlSeconds int
var (
id string
err error
ttlSeconds int
)
for {
if id, ttlSeconds = s.updatingIdMap.Pop(); id == "" {
break

View File

@ -1,4 +1,4 @@
// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,