-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.go
54 lines (45 loc) · 1.08 KB
/
db.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
42
43
44
45
46
47
48
49
50
51
52
53
54
package redis_pack
import (
"github.com/gomodule/redigo/redis"
"time"
)
var testPool = &redis.Pool{
MaxIdle: 100,
MaxActive: 500,
IdleTimeout: 180 * time.Second,
Dial: func() (redis.Conn, error) { return setDialog("127.0.0.1:6379", "") },
}
var testConn, _ = NewConnectionByPool(testPool)
type dbRds struct {
pool *redis.Pool
}
func (d *dbRds) SelectDb(db int64) *Reply {
c := d.pool.Get()
defer c.Close()
return getReply(c.Do("select", db))
}
func (d *dbRds) Do(commend string, args ...interface{}) *Reply {
c := d.pool.Get()
defer c.Close()
return getReply(c.Do(commend, args...))
}
func (d *dbRds) PipLine(commends []map[string][]any) ([]any, []error) {
conn := d.pool.Get()
defer conn.Close()
for _, cmd := range commends {
for k, v := range cmd {
err := conn.Send(k, v...)
if err != nil {
return nil, []error{err}
}
}
}
conn.Flush()
replies, errs := make([]interface{}, 0), make([]error, 0)
for i := 0; i < len(commends); i++ {
tmp, err := conn.Receive()
replies = append(replies, tmp)
errs = append(errs, err)
}
return replies, errs
}