From aefa54f04b75454c17393ce5e8b3c64c887fb4d8 Mon Sep 17 00:00:00 2001 From: John Guo Date: Sat, 16 Jan 2021 20:37:59 +0800 Subject: [PATCH] improve package gredis --- os/gsession/gsession_storage_file.go | 10 ++++++---- os/gsession/gsession_storage_redis.go | 12 +++++++----- os/gsession/gsession_storage_redis_hashtable.go | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/os/gsession/gsession_storage_file.go b/os/gsession/gsession_storage_file.go index b97dd820a..f1df7d8db 100644 --- a/os/gsession/gsession_storage_file.go +++ b/os/gsession/gsession_storage_file.go @@ -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 diff --git a/os/gsession/gsession_storage_redis.go b/os/gsession/gsession_storage_redis.go index 567fe2036..bd5714e66 100644 --- a/os/gsession/gsession_storage_redis.go +++ b/os/gsession/gsession_storage_redis.go @@ -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 diff --git a/os/gsession/gsession_storage_redis_hashtable.go b/os/gsession/gsession_storage_redis_hashtable.go index b7eec2970..15eb825a3 100644 --- a/os/gsession/gsession_storage_redis_hashtable.go +++ b/os/gsession/gsession_storage_redis_hashtable.go @@ -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,