From e856b2f18aba4f59c137dc9c5ed5ee6d6bcd1da7 Mon Sep 17 00:00:00 2001 From: Denver Gingerich Date: Wed, 1 Feb 2017 18:38:18 +0000 Subject: [PATCH] number keys store JID as val, not list of size one This is for compatibility with jmp-register commit f7ee1fe (whose code is not yet active), and for general simplicity and correctness. We can now use SETNX to mitigate races rather than set-then-check-length. --- sgx-catapult.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sgx-catapult.rb b/sgx-catapult.rb index 0b4b5ddcb48342666f14794408e0ec6f7572fdfc..7176c6e518575662792205200d68fb243820c4e6 100755 --- a/sgx-catapult.rb +++ b/sgx-catapult.rb @@ -30,7 +30,7 @@ require 'goliath/api' require 'goliath/server' require 'log4r' -puts "Soprani.ca/SMS Gateway for XMPP - Catapult v0.015" +puts "Soprani.ca/SMS Gateway for XMPP - Catapult v0.016" if ARGV.size != 9 then puts "Usage: sgx-catapult.rb " + @@ -533,6 +533,7 @@ module SGXcatapult conn = Hiredis::Connection.new conn.connect(ARGV[4], ARGV[5].to_i) + # TODO: use SETNX instead conn.write ["EXISTS", num_key] if conn.read == 1 conn.disconnect @@ -555,7 +556,7 @@ module SGXcatapult next end - conn.write ["RPUSH",num_key,bare_jid] + conn.write ["SET", num_key, bare_jid] if conn.read != 1 conn.disconnect @@ -572,6 +573,8 @@ module SGXcatapult conn.write ["RPUSH",cred_key,api_secret] conn.write ["RPUSH",cred_key,phone_num] + # TODO: confirm cred_key list size == 4 + for n in 1..4 do # TODO: catch/relay RuntimeError result = conn.read @@ -760,8 +763,8 @@ class WebhookHandler < Goliath::API return [200, {}, "OK"] end - conn.write ["LRANGE", num_key, 0, 0] - bare_jid = conn.read[0] + conn.write ["GET", num_key] + bare_jid = conn.read conn.disconnect msg = ''