Beispiel #1
0
func (location *LocationInfo) GetLocation(level uint16, hour uint32, page uint16) []LocResult {
	if level != 1 {
		syslog.Error("level ", level, " not completed.")
		return nil
	}

	session := common.MongoGet()
	defer common.MongoPut(session)

	c := session.DB("du").C("location")

	selector := bson.M{"loc": bson.M{"$near": location.Loc}}
	syslog.Debug("selector: ", selector)
	iter := c.Find(selector).Limit(MAX_ROW*LOCAL_MAX_PAGE + 1).Iter()
	result := LocationInfo{}

	retLoc := make([]LocResult, MAX_ROW*30)
	line := 0

	retLoc[line].Uid = location.Uid
	retLoc[line].Xpos = float64(int64(location.Loc[0]*1000000)) / 1000000
	retLoc[line].Ypos = float64(int64(location.Loc[1]*1000000)) / 1000000
	syslog.Debug(retLoc[line].Xpos, retLoc[line].Ypos)
	line++

	for iter.Next(&result) && line < MAX_ROW*30 {
		if result.Uid == location.Uid {
			continue
		}

		syslog.Debug("Uid: ", result.Uid, " Loc: ", result.Loc, " send time: ", result.SendTime, "line:", line)

		retLoc[line].Uid = result.Uid
		retLoc[line].Xpos = float64(int64(result.Loc[0]*1000000)) / 1000000
		retLoc[line].Ypos = float64(int64(result.Loc[1]*1000000)) / 1000000
		//retlocl[line].Xpos = result.Loc[0]
		//retlocl[line].Ypos = result.Loc[1]

		line++
	}

	return retLoc[:line]
}
Beispiel #2
0
func (location *LocationInfo) SaveLocation() error {
	session := common.MongoGet()
	defer common.MongoPut(session)

	c := session.DB("du").C("location")

	selector := bson.M{"uid": location.Uid}
	newLoc := bson.M{"uid": location.Uid, "loc": location.Loc, "sendtime": location.SendTime}
	update := bson.M{"$set": newLoc}
	syslog.Debug("selector: ", selector, " update: ", update)
	if err := c.Update(selector, update); err != nil {
		return errors.As(err, *location)
	}

	return nil
}
Beispiel #3
0
func PipelineGetString(keys []string) []string {
	rClient := get()
	defer put(rClient)

	pipeline := rClient.Client.Pipeline()

	keysNum := 0
	for _, key := range keys {
		if len(key) > 2 {
			syslog.Debug("pipeline key ", key)
			pipeline.Get(key)
			keysNum++
		}
	}

	cmds, err := pipeline.Exec()

	syslog.Debug("pipe result:", cmds, err)

	result := ""

	valList := make([]string, keysNum)
	n := 0
	if err != nil && err != redis.Nil {
		syslog.Debug("redisClient pipeline err %s", err.Error())

		ReconnectRedis(rClient)
	} else {
		syslog.Debug("redisClient pipeline ok")

		for _, cmd := range cmds {
			syslog.Debug(cmd, " ret result:", cmd.(*redis.StringCmd).Val())
			if cmd.(*redis.StringCmd).Err() != nil {
				syslog.Error(cmd.(*redis.StringCmd).Err())
			} else {
				result = cmd.(*redis.StringCmd).Val()
			}
			if len(result) > 0 {
				syslog.Debug(n, result)
				valList[n] = result
				n++
			}
		}
	}

	return valList
}