-
Notifications
You must be signed in to change notification settings - Fork 1
/
connection.go
41 lines (34 loc) · 924 Bytes
/
connection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2014 Daniel Theophanes.
// Use of this source code is governed by a zlib-style
// license that can be found in the LICENSE file.
package rdb
import (
"context"
"errors"
)
type Connection struct {
cp *ConnPool
conn DriverConn
done bool
}
var connectionClosed = errors.New("Connection already closed.")
// Query executes a Command on the connection.
func (c *Connection) Query(ctx context.Context, cmd *Command, params ...Param) (*Result, error) {
if c.done {
return nil, connectionClosed
}
return c.cp.query(ctx, true, c.conn, cmd, nil, params...)
}
// Close returns the underlying connection to the Connection Pool.
func (c *Connection) Close() error {
if c.done {
return transactionClosed
}
c.done = true
c.cp.releaseConn(c.conn, c.conn.Status() != StatusReady)
return nil
}
// Return true if the connection has not been closed.
func (c *Connection) Active() bool {
return !c.done
}