feat(database): support for either Redis or PostgreSQL for video cache

This commit is contained in:
Fijxu
2025-02-18 18:11:05 -03:00
parent 1df1945849
commit bbc5913b8d
2 changed files with 73 additions and 18 deletions

View File

@@ -76,12 +76,8 @@ end
HMAC_KEY = CONFIG.hmac_key
PG_DB = DB.open CONFIG.database_url
REDIS_DB = Redis::PooledClient.new(unixsocket: CONFIG.redis_socket || nil, url: CONFIG.redis_url || nil)
PG_DB = DB.open CONFIG.database_url
if REDIS_DB.ping
puts "Connected to redis"
end
ARCHIVE_URL = URI.parse("https://archive.org")
PUBSUB_URL = URI.parse("https://pubsubhubbub.appspot.com")
REDDIT_URL = URI.parse("https://www.reddit.com")
@@ -156,6 +152,19 @@ end
OUTPUT = CONFIG.output.upcase == "STDOUT" ? STDOUT : File.open(CONFIG.output, mode: "a")
LOGGER = Invidious::LogHandler.new(OUTPUT, CONFIG.log_level, CONFIG.colorize_logs)
REDIS_DB = begin
LOGGER.info "Connecting to Redis compatible DB"
redis = Redis::PooledClient.new(unixsocket: CONFIG.redis_socket || nil, url: CONFIG.redis_url || nil)
if redis.ping
LOGGER.info "Connected to Redis compatible DB via unix domain socket at '#{CONFIG.redis_socket}'" if CONFIG.redis_socket
LOGGER.info "Connected to Redis compatible DB via TCP socket at '#{CONFIG.redis_url}'" if CONFIG.redis_url
end
redis
rescue ex
LOGGER.error "Failed to connect to a Redis compatible DB. Invidious will store the video cache on the PostgresSQL DB"
nil
end
# Check table integrity
Invidious::Database.check_integrity(CONFIG)