Skip to content

Commit

Permalink
Migrate gem redis-rb to redis-client
Browse files Browse the repository at this point in the history
  • Loading branch information
tricknotes committed Oct 21, 2024
1 parent 56d9e38 commit 9578bce
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ gem 'omniauth-rails_csrf_protection'
gem 'pg'
gem 'propshaft'
gem 'puma', require: false
gem 'redis'
gem 'redis-client'
gem 'roadie-rails'

group :development do
Expand Down
4 changes: 1 addition & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,6 @@ GEM
rake (13.2.1)
rdoc (6.7.0)
psych (>= 4.0.0)
redis (5.3.0)
redis-client (>= 0.22.0)
redis-client (0.22.2)
connection_pool
regexp_parser (2.9.2)
Expand Down Expand Up @@ -348,7 +346,7 @@ DEPENDENCIES
propshaft
puma
rails (~> 7.2.0)
redis
redis-client
roadie-rails
rspec-its
rspec-rails
Expand Down
17 changes: 8 additions & 9 deletions app/models/daily_mail_scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class << self
def schedule(users)
statuses = users.flat_map {|user| [user.id, Status::SCHEDULED] }

redis.hmset TABLE_NAME, *statuses
redis.call 'HMSET', TABLE_NAME, *statuses
end

def send_mail_to_scheduled_users
Expand Down Expand Up @@ -52,11 +52,11 @@ def send_mail_to_scheduled_users
end

def clear!
redis.del TABLE_NAME
redis.call 'DEL', TABLE_NAME
end

def scheduled_users
user_ids = redis.hkeys(TABLE_NAME)
user_ids = redis.call('HKEYS', TABLE_NAME)

User.find(user_ids)
end
Expand All @@ -65,25 +65,24 @@ def scheduled_users

def redis
@redis ||= begin
uri = URI.parse(Settings.redis_url)
Redis.new(host: uri.host, port: uri.port, password: uri.password)
RedisClient.config(url: Settings.redis_url).new_client
end
end

def status_for_user(user)
redis.hmget(TABLE_NAME, user.id).first
redis.call('HMGET', TABLE_NAME, user.id).first
end

def start_processing(user)
redis.hmset(TABLE_NAME, user.id, Status::PROCESSIONG)
redis.call('HMSET', TABLE_NAME, user.id, Status::PROCESSIONG)
end

def finish_sending_mail(user)
redis.hdel(TABLE_NAME, user.id)
redis.call('HDEL', TABLE_NAME, user.id)
end

def schedule_as_retry(user)
redis.hmset(TABLE_NAME, user.id, Status::FAILED)
redis.call('HMSET', TABLE_NAME, user.id, Status::FAILED)
end

def user_has_starred?(user, term)
Expand Down

0 comments on commit 9578bce

Please sign in to comment.