From c4d2f411e6cd830e10992039190d0208eb225b4f Mon Sep 17 00:00:00 2001 From: Raghu Saxena Date: Wed, 26 Apr 2023 19:13:30 +0800 Subject: [PATCH] Add the ZADDS --- src/main.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index f8246fe..6940062 100644 --- a/src/main.rs +++ b/src/main.rs @@ -101,10 +101,11 @@ async fn announce(req: HttpRequest, data: web::Data) -> HttpResponse { post_announce_pipeline.cmd("ZREM").arg(&leechers_key).arg(&parsed.ip_port).ignore(); // We dont care about the return value } } else if parsed.is_seeding { + // ZADD it regardless to update timestamp for the guy (in redis) + post_announce_pipeline.cmd("ZADD").arg(&seeders_key).arg(time_now_ms).arg(&parsed.ip_port).ignore(); // New seeder if let Exists::No = is_seeder_v2 { - post_announce_pipeline.cmd("ZADD").arg(&seeders_key).arg(time_now_ms).arg(&parsed.ip_port).ignore(); seed_count_mod += 1; } @@ -119,10 +120,14 @@ async fn announce(req: HttpRequest, data: web::Data) -> HttpResponse { // Increment the downloaded count for the infohash stats post_announce_pipeline.cmd("HINCRBY").arg(&parsed.info_hash).arg("downloaded").arg(1u32).ignore(); } - } else if let Exists::No = is_leecher_v2 { - post_announce_pipeline.cmd("ZADD").arg(&leechers_key).arg(time_now_ms).arg(&parsed.ip_port).ignore(); + } else { + // ZADD it regardless to update timestamp for the guy (in redis) + post_announce_pipeline.cmd("ZADD").arg(&leechers_key).arg(time_now_ms).arg(&parsed.ip_port).ignore(); + + if let Exists::No = is_leecher_v2 { leech_count_mod += 1; - }; + }; + } // Cache miss = query redis // no change = update cache