-
Notifications
You must be signed in to change notification settings - Fork 7
/
redis_mgr.go
48 lines (40 loc) · 846 Bytes
/
redis_mgr.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
package go_redis_orm
import (
"errors"
)
var g_redismgr *RedisMgr
type RedisMgr struct {
dbs map[string]IClient
newRedis NewRedisType
}
func NewRedisMgr() *RedisMgr {
return &RedisMgr{
dbs: make(map[string]IClient),
}
}
func (this *RedisMgr) Create(dbName string, addrs []string, password string, dbindex int) error {
if _, ok := this.dbs[dbName]; ok {
return nil
}
if this.newRedis == nil {
return errors.New("no set new handler!")
}
db, err := this.newRedis(dbName, addrs, password, dbindex)
if err != nil {
return err
}
this.dbs[dbName] = db
return nil
}
func (this *RedisMgr) Get(dbName string) IClient {
if db, ok := this.dbs[dbName]; ok {
return db
}
return nil
}
func (this *RedisMgr) SetNewRedisHandler(handler NewRedisType) {
this.newRedis = handler
}
func init() {
g_redismgr = NewRedisMgr()
}