code: func addEvent(conn redis.Conn, e contract.Event) (id string, err error) {
  	if e.Created == 0 {
  		e.Created = db.MakeTimestamp()
  	}
  
  	if e.ID == "" {
  		e.ID = uuid.New().String()
  	}
  
  	m, err := marshalEvent(e)
  	if err != nil {
  		return "", err
  	}
  
  	_ = conn.Send("MULTI")
  	_ = conn.Send("SET", e.ID, m)
  	_ = conn.Send("ZADD", db.EventsCollection, 0, e.ID)
  	_ = conn.Send("ZADD", db.EventsCollection+":created", e.Created, e.ID)
  	_ = conn.Send("ZADD", db.EventsCollection+":pushed", e.Pushed, e.ID)
  	_ = conn.Send("ZADD", db.EventsCollection+":device:"+e.Device, e.Created, e.ID)
  
  	rids := make([]interface{}, len(e.Readings)*2+1)
  	rids[0] = db.EventsCollection + ":readings:" + e.ID
  	for i, r := range e.Readings {
  		r.Created = e.Created
  		r.Device = e.Device
  
  		if r.Id != "" {
  			_, err = uuid.Parse(r.Id)
  			if err != nil {
  				return "", db.ErrInvalidObjectId
  			}
  		}
  		id, err = addReading(conn, false, r)
  		if err != nil {
  			return id, err
  		}
  		rids[i*2+1] = 0
  		rids[i*2+2] = id
  	}
  	if len(rids) > 1 {
  		_ = conn.Send("ZADD", rids...)
  	}
  
  	_, err = conn.Do("EXEC")
  	return e.ID, err
  }
docs: // ************************** HELPER FUNCTIONS ***************************