class RedisClient

Defined in:

redis_client.cr

Constant Summary

CONNECTION_TIMEOUT = 5
Log = JosieHealth::Utils::Log
OAUTH_STATE_TTL = 600
READ_TIMEOUT = 10
RETRY_ATTEMPTS = 3
RETRY_DELAY = 500.milliseconds
VWRAPPED_JOB_TTL = 900

TTL constants

Constructors

Instance Method Summary

Constructor Detail

def self.new #

Instance Method Detail

def clear_vwrapped_active(user : String) : Bool #

def close #

Close connection


def consume_irc_auth(token : String) : Hash(String, String) | Nil #

def consume_oauth_state(state : String) : Hash(String, String) | Nil #

Get and delete OAuth state (one-time use)


def count_user_keys(user_id : String) : Int32 #

Count user's API keys (for rate limiting)


def delete_all_user_data(user_id : String) : Hash(String, Int32) #

Delete all data for a user - returns count of deleted items


def delete_dose(user : String, timestamp : String) : Bool #

Delete a specific dose by timestamp


def fetch_csv_content : String #

Get all doses for a user in CSV format


def get_alias(user_id : String, alias_name : String) : String | Nil #

def get_all_dose_keys : Array(String) #

Get all dose keys from Redis


def get_all_user_dose_keys(user : String) : Array(String) #

def get_api_key_data(key_hash : String) : Hash(String, String) | Nil #

Get full API key data


def get_api_key_user(key_hash : String) : String | Nil #

Get user_id from API key hash, returns nil if key not found


def get_dose(user : String, timestamp : String) : Hash(String, String) | Nil #

Get a specific dose by timestamp


def get_dose_data(dose_key : String) : Hash(String, String) #

Get dose data for a specific key


def get_due_reminders(current_time : Int64 = Time.utc.to_unix) : Array(Hash(String, String)) #

def get_irc_auth_request(token : String) : Hash(String, String) | Nil #

def get_linked_accounts(user : String) : Array(String) #

def get_primary_account(user : String) : String | Nil #

def get_recent_doses(user : String, count : Int32 = 5) : Array(Hash(String, String)) #

Get recent doses for lastdose functionality


def get_user_aliases(user_id : String) : Hash(String, String) #

def get_user_by_discord_id(discord_id : String) : String | Nil #

Get user_id from Discord ID


def get_user_by_irc(network : String, nick : String) : String | Nil #

def get_user_data_stats(user_id : String) : Hash(String, Int32) #

Get counts of all user data


def get_user_doses(user : String, limit : Int32 = 100) : Array(Hash(String, String)) #

Get doses for a specific user


def get_user_labs(user : String, limit : Int32 = 100) : Array(Hash(String, String)) #

Get labs for a user


def get_user_reminders(user_id : String) : Array(Hash(String, String)) #

def get_user_timezone(user_id : String) : String | Nil #

def get_user_vitals(user : String, limit : Int32 = 100) : Array(Hash(String, String)) #

Get vitals for a user


def is_vwrapped_active(user : String) : Bool #

def link_accounts(primary_user : String, secondary_user : String, method : String) #

def list_user_keys(user_id : String) : Array(Hash(String, String)) #

List all keys for a user (returns metadata only, not the key itself)


def mark_irc_auth_verified(token : String, nick : String, account_name : String) #

def migrate_doses(from_user : String, to_user : String) : Int32 #

def ping : Bool #

Health check


def remove_alias(user_id : String, alias_name : String) : Bool #

def remove_last_dose(user : String) : Bool #

Remove last dose for undose functionality


def remove_reminder(reminder_id : String) : Bool #

def reschedule_reminder(reminder_id : String, new_trigger_time : Int64) : Bool #

def revoke_api_key(key_hash : String) : Bool #

Revoke an API key by its hash


def revoke_api_key_by_prefix(user_id : String, prefix : String) : Bool #

Revoke an API key by prefix (first 8 chars of hash)


def set_alias(user_id : String, alias_name : String, doses_string : String) #

def set_user_timezone(user_id : String, timezone : String) #

def set_vwrapped_active(user : String, ttl_seconds : Int32 = VWRAPPED_JOB_TTL) : Bool #

Video job tracking


def store_api_key(key_hash : String, user_id : String, discord_id : String, name : String = "default") : Bool #

Store a new API key (key_hash is SHA256 of the raw key)


def store_discord_mapping(discord_id : String, user_id : String) #

Store mapping from Discord ID to user_id


def store_dose(timestamp : String, user : String, substance : String, amount : String, route : String, note_text : String = "", normalized_substance : String | Nil = nil, normalized_route : String | Nil = nil, categories : String | Nil = nil, dose_classification : String | Nil = nil, local_timestamp : String | Nil = nil) #

Store a dose entry in Redis


def store_irc_auth_request(token : String, data : Hash(String, String)) #

def store_irc_user_mapping(network : String, nick : String, user_id : String) #

def store_lab(timestamp : String, user : String, test_type : String, value : String, unit : String, reference_range : String, notes : String) #

Store lab entry in Redis


def store_oauth_state(state : String, data : Hash(String, String), ttl_seconds : Int32 = OAUTH_STATE_TTL) #

Store OAuth state token (for CSRF protection)


def store_reminder(user_id : String, message : String, trigger_time : Int64, channel_id : String, discord_user_id : String, callback_url : String, recurrence : String = "") : String #

def store_vitals(timestamp : String, user : String, pulse : Int32 | Nil, systolic_bp : Int32 | Nil, diastolic_bp : Int32 | Nil, blood_oxygen : Int32 | Nil, temperature : Float64 | Nil, notes : String) #

Store vitals entry in Redis


def update_dose(user : String, timestamp : String, fields : Hash(String, String)) : Bool #

Update specific fields of a dose


def update_dose_data(dose_key : String, data : Hash(String, String)) #

Update dose data (for migrations)


def update_key_last_used(key_hash : String) #

Update last_used timestamp for an API key


def update_last_dose_annotation(user : String, note_text : String) : Bool #

Update annotation on the last dose for a user