func update(collection string, condition mongo.Mongo, docs interface{}) { Safe(collection, func(c *mgo.Collection) { b, _ := json.Marshal(docs) fmt.Println("[CHAOS]update data is: ", string(b)) err := c.Update(Reflect(condition), bson.M{"$set": docs}) common.AssertPrint(err) }) }
func query(collection string, result interface{}, condition mongo.Mongo) { Safe(collection, func(c *mgo.Collection) { bsonMap := Reflect(condition) err := c.Find(&bsonMap).One(result) common.AssertPrint(err) b, _ := json.Marshal(result) fmt.Println("[CHAOS]query result is: ", string(b)) }) }
func Rpop(queue string) string { var result string Safe(func(c redis.Conn) { rst := simpleMultiArgsCmd(c, "RPOP", queue) data, err := redis.String(rst[0].Interface(), nil) common.AssertPrint(err) result = data }) return result }
func Lpush(queue string, value ...string) bool { result := false Safe(func(c redis.Conn) { rst := simpleMultiArgsCmd(c, "LPUSH", queue, value...) ok, err := redis.Bool(rst[0].Interface().(int64), nil) common.AssertPrint(err) result = ok }) return result }