Esempio n. 1
0
func MongoInit() {
	var err error
	db = common.Param.MongoDB
	session, err = mgo.Dial(common.Path.MongoUrl)
	common.AssertPanic(err)
	session.SetMode(mgo.Monotonic, true)
}
Esempio n. 2
0
func insert(collection string, docs interface{}) {
	Safe(collection, func(c *mgo.Collection) {
		fmt.Println(&docs)
		err := c.Insert(&docs)
		common.AssertPanic(err)
	})
}
Esempio n. 3
0
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
}
Esempio n. 4
0
func del(collection string, condition mongo.Mongo) {
	Safe(collection, func(c *mgo.Collection) {
		err := c.Remove(Reflect(condition))
		common.AssertPanic(err)
	})
}