From 44c4cd872931927624f75b7403323382ba617989 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 16 May 2022 15:18:27 -0500 Subject: [PATCH] Need Redis 7 for NX and GET together --- lib/registration_repo.rb | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/registration_repo.rb b/lib/registration_repo.rb index 023f5b69e41130a0795e59f2e84707942c79870b..938e5123990522017ef5bfa514389a9ace8634c1 100644 --- a/lib/registration_repo.rb +++ b/lib/registration_repo.rb @@ -22,23 +22,20 @@ class RegistrationRepo EMPromise.all([ find(jid), - REDIS.set( - jid_key(tel), - Blather::JID.new(jid).stripped.to_s, - "NX", "GET" - ) + REDIS.exists(jid_key(tel)) ]).then { |(oldcreds, oldjid)| - if oldjid && oldjid != jid.stripped.to_s + if oldjid == "1" || (!oldcreds.empty? && oldcreds != creds) raise Conflict, "Another user exists for #{tel}" end - if !oldcreds.empty? && oldcreds != creds - REDIS.set(jid_key(tel), oldjid).then do - raise Conflict, "Another user exists for #{jid}" - end - end - }.then { - REDIS.rpush(cred_key(jid), *creds) + EMPromise.all([ + REDIS.set( + jid_key(tel), + Blather::JID.new(jid).stripped.to_s, + "NX" + ), + REDIS.rpush(cred_key(jid), *creds) + ]) } end