redis_addresses.rb

 1# frozen_string_literal: true
 2
 3require "redis"
 4
 5# This returns a hash
 6# The keys are the bitcoin addresses, the values are all of the keys which
 7#   contain that address
 8# If there are no duplicates, then each value will be a singleton list
 9def get_addresses_with_users(redis)
10	addrs = Hash.new { |h, k| h[k] = [] }
11
12	# I picked 1000 because it made a relatively trivial case take 15 seconds
13	#   instead of forever.
14	# Basically it's "how long does each command take"
15	# The lower it is (default is 10), it will go back and forth to the client a
16	#   ton
17	redis.scan_each(match: "jmp_customer_btc_addresses-*", count: 1000) do |key|
18		redis.smembers(key).each do |addr|
19			addrs[addr] << key
20		end
21	end
22
23	addrs
24end
25
26module RedisBtcAddresses
27	def self.each_user(redis)
28		# I picked 1000 because it made a relatively trivial case take
29		# 15 seconds instead of forever.
30		# Basically it's "how long does each command take"
31		# The lower it is (default is 10), it will go back and forth
32		# to the client a ton
33		redis.scan_each(
34			match: "jmp_customer_btc_addresses-*",
35			count: 1000
36		) do |key|
37			yield key, redis.smembers(key)
38		end
39	end
40end