~singpolyma/jmp-pay

ref: 68ed9c34b0d4a2eaa0e49def372deabe4eb55daf jmp-pay/lib/redis_addresses.rb -rw-r--r-- 1.1 KiB
68ed9c34Stephen Paul Weber Run billing 3 at a time 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

require "redis"

# This returns a hash
# The keys are the bitcoin addresses, the values are all of the keys which
#   contain that address
# If there are no duplicates, then each value will be a singleton list
def get_addresses_with_users(redis)
	addrs = Hash.new { |h, k| h[k] = [] }

	# I picked 1000 because it made a relatively trivial case take 15 seconds
	#   instead of forever.
	# Basically it's "how long does each command take"
	# The lower it is (default is 10), it will go back and forth to the client a
	#   ton
	redis.scan_each(match: "jmp_customer_btc_addresses-*", count: 1000) do |key|
		redis.smembers(key).each do |addr|
			addrs[addr] << key
		end
	end

	addrs
end

module RedisBtcAddresses
	def self.each_user(redis)
		# I picked 1000 because it made a relatively trivial case take
		# 15 seconds instead of forever.
		# Basically it's "how long does each command take"
		# The lower it is (default is 10), it will go back and forth
		# to the client a ton
		redis.scan_each(
			match: "jmp_customer_btc_addresses-*",
			count: 1000
		) do |key|
			yield key, redis.smembers(key)
		end
	end
end