コード例 #1
0
ファイル: mongo.go プロジェクト: zufangzi/chaos
func MongoInit() {
	var err error
	db = common.Param.MongoDB
	session, err = mgo.Dial(common.Path.MongoUrl)
	common.AssertPanic(err)
	session.SetMode(mgo.Monotonic, true)
}
コード例 #2
0
ファイル: mongo.go プロジェクト: zufangzi/chaos
func insert(collection string, docs interface{}) {
	Safe(collection, func(c *mgo.Collection) {
		fmt.Println(&docs)
		err := c.Insert(&docs)
		common.AssertPanic(err)
	})
}
コード例 #3
0
ファイル: redis.go プロジェクト: zufangzi/chaos
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
}
コード例 #4
0
ファイル: mongo.go プロジェクト: zufangzi/chaos
func del(collection string, condition mongo.Mongo) {
	Safe(collection, func(c *mgo.Collection) {
		err := c.Remove(Reflect(condition))
		common.AssertPanic(err)
	})
}