Integrations

Sidekiq with Upstash Redis

You can use Sidekiq with Upstash Redis. Sidekiq is a Ruby based queue library with a Redis-based queue storage so you can use with Upstash Redis.

Example Application

bundle init bundle add sidekiq
require "sidekiq"require "sidekiq/api" connection_url = ENV['UPSTASH_REDIS_LINK'] Sidekiq.configure_client do |config|    config.redis = {url: connection_url}end Sidekiq.configure_server do |config|    config.redis = {url: connection_url}end class EmailService    include Sidekiq::Worker    def perform(id, type)        # Logic goes here. Let's assume sending email by printing to console.        puts "Emailed to: " +  id + ": " + "'Congrats on " + type + " plan.'"    endend def updateEmail(id, newType)    jobFound = false     a = Sidekiq::ScheduledSet.new    a.each do |job|        if job.args[0] == id            job.delete            jobFound = true        end    end     if jobFound        EmailService.perform_async(id, ("starting using our service and upgrading it to " + newType))    else        EmailService.perform_async(id, ("upgrading to " + newType))    endend def sendEmail(id, type)    case type    when "free"        # if free, delay for 10 seconds.        EmailService.perform_in("10", id, "free")    when "paid"        # if paid, delay for 5 seconds.        EmailService.perform_in("5", id, "paid")    when "enterprise"        # if enterprise, immediately queue.        EmailService.perform_async(id, "enterprise")    when "enterprise10k"        EmailService.perform_async(id, "enterprise10k")    else        puts "Only plans are: `free`, `paid` and `enterprise`"    endend def clearSchedules()    Sidekiq::ScheduledSet.new.clear    Sidekiq::Queue.new.clearend

Billing Optimization

Sidekiq accesses Redis regularly, even when there is no queue activity. This can incur extra costs because Upstash charges per request on the Pay-As-You-Go plan. With the introduction of our Fixed plans, we recommend switching to a Fixed plan to avoid increased command count and high costs in Sidekiq use cases.

Loading search…