func SetMirrorState(r *database.Redis, id string, state bool, reason string) error { conn := r.Get() defer conn.Close() key := fmt.Sprintf("MIRROR_%s", id) previousState, err := redis.Bool(conn.Do("HGET", key, "up")) if err != nil { return err } var args []interface{} args = append(args, key, "up", state, "excludeReason", reason) if state != previousState { args = append(args, "stateSince", time.Now().Unix()) } _, err = conn.Do("HMSET", args...) if err == nil && state != previousState { // Publish update database.Publish(conn, database.MIRROR_UPDATE, id) } return err }
func SetMirrorEnabled(r *database.Redis, id string, state bool) error { conn := r.Get() defer conn.Close() key := fmt.Sprintf("MIRROR_%s", id) _, err := conn.Do("HMSET", key, "enabled", state) // Publish update if err == nil { database.Publish(conn, database.MIRROR_UPDATE, id) } return err }