diff --git a/src/common/db/mongo.go b/src/common/db/mongo.go deleted file mode 100644 index 2da6ff3e0..000000000 --- a/src/common/db/mongo.go +++ /dev/null @@ -1,51 +0,0 @@ -package db - -import ( - "Open_IM/src/common/config" - "errors" - "fmt" - "gopkg.in/mgo.v2" - "sync" - "time" -) - -type mongoDB struct { - sync.RWMutex - dbMap map[string]*mgo.Session -} - -func (m *mongoDB) mgoSession(dbName string) *mgo.Session { - m.Lock() - defer m.Unlock() - if _, ok := m.dbMap[dbName]; !ok { - if err := m.newMgoSession(dbName); err != nil { - panic(err) - return nil - } - } - return m.dbMap[dbName] -} - -func (m *mongoDB) newMgoSession(dbName string) error { - dailInfo := &mgo.DialInfo{ - Addrs: config.Config.Mongo.DBAddress, - Direct: config.Config.Mongo.DBDirect, - Timeout: time.Second * time.Duration(config.Config.Mongo.DBTimeout), - Database: dbName, - Source: config.Config.Mongo.DBSource, - Username: config.Config.Mongo.DBUserName, - Password: config.Config.Mongo.DBPassword, - PoolLimit: config.Config.Mongo.DBMaxPoolSize, - } - session, err := mgo.DialWithInfo(dailInfo) - if err != nil { - return errors.New(fmt.Sprintf("mongo DialWithInfo fail, err= %s", err.Error())) - } - - if m.dbMap == nil { - m.dbMap = make(map[string]*mgo.Session) - } - - m.dbMap[dbName] = session - return nil -} diff --git a/src/common/db/redis.go b/src/common/db/redis.go deleted file mode 100644 index 31c2e86c4..000000000 --- a/src/common/db/redis.go +++ /dev/null @@ -1,52 +0,0 @@ -package db - -import ( - "Open_IM/src/common/config" - log2 "Open_IM/src/common/log" - "github.com/garyburd/redigo/redis" - "time" -) - -type redisDB struct { - pool *redis.Pool -} - -func (r *redisDB) newPool() { - r.pool = &redis.Pool{ - MaxIdle: config.Config.Redis.DBMaxIdle, - MaxActive: config.Config.Redis.DBMaxActive, - - IdleTimeout: time.Duration(config.Config.Redis.DBIdleTimeout) * time.Second, - Dial: func() (redis.Conn, error) { - return redis.Dial( - "tcp", - config.Config.Redis.DBAddress[0], - redis.DialReadTimeout(time.Duration(1000)*time.Millisecond), - redis.DialWriteTimeout(time.Duration(1000)*time.Millisecond), - redis.DialConnectTimeout(time.Duration(1000)*time.Millisecond), - redis.DialDatabase(0), - redis.DialPassword(config.Config.Redis.DBPassWord), - ) - }, - } -} - -func (r *redisDB) Exec(cmd string, key interface{}, args ...interface{}) (interface{}, error) { - con := r.pool.Get() - if err := con.Err(); err != nil { - log2.Error("", "", "redis cmd = %v, err = %v", cmd, err) - return nil, err - } - defer con.Close() - - params := make([]interface{}, 0) - params = append(params, key) - - if len(args) > 0 { - for _, v := range args { - params = append(params, v) - } - } - - return con.Do(cmd, params...) -}