Exemple #1
0
func (ev *HistoryEvent) persistEvent(c redis.Client) {
	// Get new ever-incrementing event id
	id, err := c.Incr(HISTORY_KEY)
	if err != nil {
		log.Err(err.Error())
		return
	}

	// Persist to object internally
	ev.Id = id

	// New key
	historyKey := HISTORY_BASE + ":id:" + string(id)
	ev.HistoryKey = historyKey

	// Persist values to history key
	ev.PersistAtomicHistoryKV(c, "timestamp", []byte(ev.Timestamp.String()))
	// TODO: FIXME: More keys

	// Build additional indices...
	// 1. Master index.
	_, err = c.Zadd(HISTORY_LIST, float64(ev.Timestamp.Unix()), []byte(historyKey))
	if err != nil {
		log.Err(err.Error())
	}

	// 2. Date index
	log.Info("Logging to " + HISTORY_LIST + ":date:" + ev.Timestamp.Format("%Y-%m-%d"))
	_, err = c.Zadd(HISTORY_LIST+":date:"+ev.Timestamp.Format("%Y-%m-%d"), float64(ev.Timestamp.Unix()), []byte(historyKey))
	if err != nil {
		log.Err(err.Error())
	}

	// 3. Host index
	log.Info("Logging to " + HISTORY_LIST + ":host:" + ev.Host)
	_, err = c.Zadd(HISTORY_LIST+":host:"+ev.Host, float64(ev.Timestamp.Unix()), []byte(historyKey))
	if err != nil {
		log.Err(err.Error())
	}

	// 4. Check index
	log.Info("Logging to " + HISTORY_LIST + ":check:" + ev.Check)
	_, err = c.Zadd(HISTORY_LIST+":check:"+ev.Check, float64(ev.Timestamp.Unix()), []byte(historyKey))
	if err != nil {
		log.Err(err.Error())
	}

}