diff --git a/internal/sql/provider.go b/internal/sql/provider.go index 9272372..bea14fa 100644 --- a/internal/sql/provider.go +++ b/internal/sql/provider.go @@ -85,13 +85,13 @@ func (p *Provider) Get(id []byte) ([]byte, error) { func (p *Provider) Save(id, data []byte, expiration time.Duration) error { now := time.Now().UnixNano() - n, err := p.Exec(p.config.SQLSave, gotils.B2S(data), now, expiration.Seconds(), gotils.B2S(id)) + n, err := p.Exec(p.config.SQLSave, gotils.B2S(data), now, expiration.Nanoseconds(), gotils.B2S(id)) if err != nil { return err } if n == 0 { // Not exist - _, err = p.Exec(p.config.SQLInsert, gotils.B2S(id), gotils.B2S(data), now, expiration.Seconds()) + _, err = p.Exec(p.config.SQLInsert, gotils.B2S(id), gotils.B2S(data), now, expiration.Nanoseconds()) if err != nil { return err } @@ -105,13 +105,13 @@ func (p *Provider) Save(id, data []byte, expiration time.Duration) error { func (p *Provider) Regenerate(id, newID []byte, expiration time.Duration) error { now := time.Now().UnixNano() - n, err := p.Exec(p.config.SQLRegenerate, gotils.B2S(newID), now, expiration.Seconds(), gotils.B2S(id)) + n, err := p.Exec(p.config.SQLRegenerate, gotils.B2S(newID), now, expiration.Nanoseconds(), gotils.B2S(id)) if err != nil { return err } if n == 0 { // Not exist - _, err = p.Exec(p.config.SQLInsert, gotils.B2S(newID), "", now, expiration.Seconds()) + _, err = p.Exec(p.config.SQLInsert, gotils.B2S(newID), "", now, expiration.Nanoseconds()) if err != nil { return err } diff --git a/providers/memory/provider.go b/providers/memory/provider.go index c14cb00..337a129 100644 --- a/providers/memory/provider.go +++ b/providers/memory/provider.go @@ -51,7 +51,7 @@ func (p *Provider) Get(id []byte) ([]byte, error) { func (p *Provider) Save(id, data []byte, expiration time.Duration) error { item := acquireItem() item.data = data - item.lastActiveTime = time.Now().Unix() + item.lastActiveTime = time.Now().UnixNano() item.expiration = expiration p.db.SetBytes(id, item) @@ -65,7 +65,7 @@ func (p *Provider) Regenerate(id, newID []byte, expiration time.Duration) error data := p.db.GetBytes(id) if data != nil { item := data.(*item) - item.lastActiveTime = time.Now().Unix() + item.lastActiveTime = time.Now().UnixNano() item.expiration = expiration p.db.SetBytes(newID, item) @@ -100,7 +100,7 @@ func (p *Provider) NeedGC() bool { // GC destroys the expired sessions func (p *Provider) GC() { - now := time.Now().Unix() + now := time.Now().UnixNano() for _, kv := range p.db.D { item := kv.Value.(*item) @@ -109,7 +109,7 @@ func (p *Provider) GC() { continue } - if now >= (item.lastActiveTime + int64(item.expiration.Seconds())) { + if now >= (item.lastActiveTime + item.expiration.Nanoseconds()) { p.Destroy(kv.Key) } } diff --git a/providers/mysql/provider.go b/providers/mysql/provider.go index ddd1aaf..3a206ec 100644 --- a/providers/mysql/provider.go +++ b/providers/mysql/provider.go @@ -15,7 +15,7 @@ var initQueries = []string{ id VARCHAR(64) NOT NULL DEFAULT '' COMMENT 'Session id', data TEXT NOT NULL COMMENT 'Session data', last_active BIGINT SIGNED NOT NULL DEFAULT '0' COMMENT 'Last active time', - expiration INT UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Expiration time', + expiration BIGINT UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Expiration time', PRIMARY KEY (id), KEY last_active (last_active), KEY expiration (expiration) diff --git a/providers/postgre/provider.go b/providers/postgre/provider.go index b5883e1..a1c4c0f 100644 --- a/providers/postgre/provider.go +++ b/providers/postgre/provider.go @@ -15,7 +15,7 @@ var initQueries = []string{ id VARCHAR(64) PRIMARY KEY NOT NULL DEFAULT '', data TEXT NOT NULL, last_active BIGINT NOT NULL DEFAULT '0', - expiration INT NOT NULL DEFAULT '0' + expiration BIGINT NOT NULL DEFAULT '0' );`, "CREATE INDEX last_active ON %s (last_active);", "CREATE INDEX expiration ON %s (expiration);", diff --git a/providers/sqlite3/provider.go b/providers/sqlite3/provider.go index 36ef20f..d0dfb1d 100644 --- a/providers/sqlite3/provider.go +++ b/providers/sqlite3/provider.go @@ -15,7 +15,7 @@ var initQueries = []string{ id VARCHAR(64) PRIMARY KEY NOT NULL DEFAULT '', data TEXT NOT NULL, last_active BIGINT NOT NULL DEFAULT '0', - expiration INT NOT NULL DEFAULT '0' + expiration BIGINT NOT NULL DEFAULT '0' );`, "CREATE INDEX last_active ON %s (last_active);", "CREATE INDEX expiration ON %s (expiration);",