~singpolyma/jmp-pay

ref: 6b4d0a87bf73edfa1fe40868ca915d3152c7ffef jmp-pay/lib/redis_addresses.rb -rw-r--r-- 1.1 KiB
6b4d0a87Stephen Paul Weber Update rubocop 1 year, 4 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