Skip to content

Commit

Permalink
Remove redis-namespace gem (#7971)
Browse files Browse the repository at this point in the history
changelog: Internal, Redis, Remove redis-namespace gem
  • Loading branch information
mitchellhenke committed Mar 14, 2023
1 parent 50ddb2b commit 9036caf
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 21 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ gem 'rack-headers_filter'
gem 'rack-timeout', require: false
gem 'redacted_struct'
gem 'redis', '>= 3.2.0'
gem 'redis-namespace'
gem 'redis-session-store', github: '18F/redis-session-store', tag: 'v0.12-18f'
gem 'retries'
gem 'rotp', '~> 6.1'
Expand Down
3 changes: 0 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,6 @@ GEM
redis-client (>= 0.9.0)
redis-client (0.14.0)
connection_pool
redis-namespace (1.8.1)
redis (>= 3.0.4)
regexp_parser (2.6.1)
reline (0.2.7)
io-console (~> 0.5)
Expand Down Expand Up @@ -802,7 +800,6 @@ DEPENDENCIES
rails-erd (>= 1.6.0)
redacted_struct
redis (>= 3.2.0)
redis-namespace
redis-session-store!
retries
rotp (~> 6.1)
Expand Down
7 changes: 2 additions & 5 deletions app/services/irs_attempts_api/redis_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ module IrsAttemptsApi
class RedisClient
cattr_accessor :redis_pool do
ConnectionPool.new(size: IdentityConfig.store.redis_irs_attempt_api_pool_size) do
Redis::Namespace.new(
'irs-attempt-api',
redis: Redis.new(url: IdentityConfig.store.redis_irs_attempt_api_url),
)
Redis.new(url: IdentityConfig.store.redis_irs_attempt_api_url)
end
end

Expand All @@ -29,7 +26,7 @@ def read_events(timestamp:, batch_size: 5000)
end

def key(timestamp)
timestamp.in_time_zone('UTC').change(min: 0, sec: 0).iso8601
'irs-attempt-api:' + timestamp.in_time_zone('UTC').change(min: 0, sec: 0).iso8601
end

def self.clear_attempts!
Expand Down
2 changes: 1 addition & 1 deletion app/services/redis_rate_limiter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ def increment(now = Time.zone.now)
# @return [String]
def build_key(now)
rounded_seconds = (now.to_i / interval) * interval
"redis-rate-limiter:#{key}:#{rounded_seconds}"
"throttle:redis-rate-limiter:#{key}:#{rounded_seconds}"
end
end
4 changes: 2 additions & 2 deletions app/services/throttle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ def increment_to_throttled!

def key
if @user
"throttle:#{@user.id}:#{throttle_type}"
"throttle:throttle:#{@user.id}:#{throttle_type}"
else
"throttle:#{@target}:#{throttle_type}"
"throttle:throttle:#{@target}:#{throttle_type}"
end
end

Expand Down
5 changes: 1 addition & 4 deletions config/initializers/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
end

REDIS_THROTTLE_POOL = ConnectionPool.new(size: IdentityConfig.store.redis_throttle_pool_size) do
Redis::Namespace.new(
'throttle',
redis: Redis.new(url: IdentityConfig.store.redis_throttle_url),
)
Redis.new(url: IdentityConfig.store.redis_throttle_url)
end
4 changes: 2 additions & 2 deletions spec/jobs/risc_delivery_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

RSpec.describe RiscDeliveryJob do
around do |ex|
REDIS_THROTTLE_POOL.with { |namespaced| namespaced.redis.flushdb }
REDIS_THROTTLE_POOL.with { |client| client.flushdb }
ex.run
REDIS_THROTTLE_POOL.with { |namespaced| namespaced.redis.flushdb }
REDIS_THROTTLE_POOL.with { |client| client.flushdb }
end

describe '#perform' do
Expand Down
2 changes: 1 addition & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Analytics
Telephony::Test::Message.clear_messages
Telephony::Test::Call.clear_calls
PushNotification::LocalEventQueue.clear!
REDIS_THROTTLE_POOL.with { |namespaced| namespaced.redis.flushdb }
REDIS_THROTTLE_POOL.with { |client| client.flushdb }
end

config.before(:each) do
Expand Down
4 changes: 2 additions & 2 deletions spec/services/redis_rate_limiter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
let(:now) { Time.zone.now }

around do |ex|
REDIS_THROTTLE_POOL.with { |namespaced| namespaced.redis.flushdb }
REDIS_THROTTLE_POOL.with { |client| client.flushdb }
ex.run
REDIS_THROTTLE_POOL.with { |namespaced| namespaced.redis.flushdb }
REDIS_THROTTLE_POOL.with { |client| client.flushdb }
end

let(:key) { 'some-unique-identifier' }
Expand Down

0 comments on commit 9036caf

Please sign in to comment.