func MongoInit() { var err error db = common.Param.MongoDB session, err = mgo.Dial(common.Path.MongoUrl) common.AssertPanic(err) session.SetMode(mgo.Monotonic, true) }
func insert(collection string, docs interface{}) { Safe(collection, func(c *mgo.Collection) { fmt.Println(&docs) err := c.Insert(&docs) common.AssertPanic(err) }) }
func GetRedisConn(network, address string) redis.Conn { if len(redisPoll) == 0 { redisPoll = make(chan redis.Conn, MAX_POOL_SIZE) go func() { for i := 0; i < MAX_POOL_SIZE/2; i++ { c, err := redis.Dial(network, address) common.AssertPanic(err) putRedis(c) } }() } // 可能会造成阻塞? return <-redisPoll }
func del(collection string, condition mongo.Mongo) { Safe(collection, func(c *mgo.Collection) { err := c.Remove(Reflect(condition)) common.AssertPanic(err) }) }