Add idle timeout into session manager

This commit is contained in:
Dan Sosedoff
2022-12-02 14:20:20 -06:00
parent 0a133dc395
commit 16726e2461
4 changed files with 31 additions and 12 deletions

View File

@@ -335,6 +335,10 @@ func (client *Client) ServerVersion() string {
}
func (client *Client) query(query string, args ...interface{}) (*Result, error) {
if client.db == nil {
return nil, nil
}
// Update the last usage time
defer func() {
client.lastQueryTime = time.Now().UTC()
@@ -366,7 +370,7 @@ func (client *Client) query(query string, args ...interface{}) (*Result, error)
result := Result{
Columns: []string{"Rows Affected"},
Rows: []Row{
Row{affected},
{affected},
},
}
@@ -446,6 +450,10 @@ func (c *Client) IsClosed() bool {
return c.closed
}
func (c *Client) LastQueryTime() time.Time {
return c.lastQueryTime
}
func (client *Client) IsIdle() bool {
mins := int(time.Since(client.lastQueryTime).Minutes())