Add idle timeout into session manager
This commit is contained in:
@@ -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())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user