Пример #1
0
func (d *dataAccess) getIncident(incidentId int64, conn redis.Conn) (*models.IncidentState, error) {
	b, err := redis.Bytes(conn.Do("GET", incidentStateKey(incidentId)))
	if err != nil {
		return nil, slog.Wrap(err)
	}
	state := &models.IncidentState{}
	if err = json.Unmarshal(b, state); err != nil {
		return nil, slog.Wrap(err)
	}
	return state, nil
}
Пример #2
0
func (d *dataAccess) GetIncident(id uint64) (*models.Incident, error) {
	defer collect.StartTimer("redis", opentsdb.TagSet{"op": "GetIncident"})()
	conn := d.GetConnection()
	defer conn.Close()
	raw, err := redis.Bytes(conn.Do("HGET", "incidents", id))
	if err != nil {
		return nil, err
	}
	incident := &models.Incident{}
	if err = json.Unmarshal(raw, incident); err != nil {
		return nil, err
	}
	return incident, nil
}
Пример #3
0
func (d *dataAccess) getLastErrorEvent(name string) (*models.AlertError, error) {
	conn := d.GetConnection()
	str, err := redis.Bytes(conn.Do("LINDEX", errorListKey(name), "0"))
	if err != nil {
		if err == redis.ErrNil {
			return nil, nil
		}
		return nil, err
	}
	ev := &models.AlertError{}
	if err = json.Unmarshal(str, ev); err != nil {
		return nil, err
	}
	return ev, nil
}
Пример #4
0
func (d *dataAccess) LoadLastInfos() (map[string]map[string]*LastInfo, error) {
	defer collect.StartTimer("redis", opentsdb.TagSet{"op": "LoadLast"})()
	conn := d.GetConnection()
	defer conn.Close()

	b, err := redis.Bytes(conn.Do("GET", "search:last"))
	if err != nil {
		return nil, err
	}
	var m map[string]map[string]*LastInfo
	err = util.UnmarshalGzipJson(b, &m)
	if err != nil {
		return nil, err
	}
	return m, nil
}