{
  "schema_version": 2,
  "id": "integrate/resque",
  "title": "Redis with Resque",
  "url": "https://redis.io/docs/latest/integrate/resque/",
  "summary": "Run Ruby background jobs with Resque and Redis.",
  "tags": [
    "docs",
    "integrate",
    "oss",
    "rs",
    "rc"
  ],
  "last_updated": "2026-11-17T16:15:30Z",
  "children": [],
  "page_type": "content",
  "content_hash": "68895266b2201f858062236b4d2e6a447729b083776317ac267c4e8231bdfd83",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "[Resque](https://github.com/resque/resque) is a Ruby library for creating background jobs, placing them\non queues, and processing them later with workers. Redis is its only data store. See the [job queue use case](https://redis.io/docs/latest/develop/use-cases/job-queue) for when to choose\nthis pattern."
    },
    {
      "id": "requirements",
      "title": "Requirements",
      "role": "content",
      "text": "The examples on this page were run with Resque 3.2 on Ruby 4.0 against Redis 7.2. Resque 3.2\nuses the [redis-rb](https://redis.io/docs/latest/develop/clients/ruby) client. Install the gem:\n\n[code example]\n\nYou also need a running Redis server. You can run one locally with\n[Redis Open Source](https://redis.io/docs/latest/operate/oss_and_stack/install/archive/install-redis),\nuse [Docker](https://hub.docker.com/_/redis), or connect to\n[Redis Cloud](https://redis.io/cloud/)."
    },
    {
      "id": "define-and-enqueue-a-job",
      "title": "Define and enqueue a job",
      "role": "content",
      "text": "A Resque job is a Ruby class with a `perform` class method and a `@queue` instance variable\nthat names its queue. Set the Redis connection with `Resque.redis`:\n\n[code example]\n\nCall `Resque.enqueue` with the class and its arguments. Resque stores the arguments as JSON,\nso use only simple types:\n\n[code example]"
    },
    {
      "id": "run-a-worker",
      "title": "Run a worker",
      "role": "content",
      "text": "Resque workers run through a rake task. Add a `Rakefile` that loads your jobs and the Resque\ntasks:\n\n[code example]\n\nThen start a worker for the queue:\n\n[code example]\n\nThe `resque` command-line tool doesn't start workers. It lists them (`resque list`) and\nremoves or kills a registered worker."
    },
    {
      "id": "what-resque-stores-in-redis",
      "title": "What Resque stores in Redis",
      "role": "content",
      "text": "| Key | Type | Contents |\n|-----|------|----------|\n| `resque:queue:<name>` | list | Waiting jobs, as JSON with the `class` and `args`. |\n| `resque:queues` | set | The names of the queues. |\n| `resque:workers` | set | The registered workers. |\n| `resque:worker:<id>` | string | The job that the worker is processing now, while it works. |\n| `resque:stat:processed` | string | A counter of processed jobs. |\n| `resque:failed` | list | One JSON entry for each failed job. |"
    },
    {
      "id": "failed-jobs",
      "title": "Failed jobs",
      "role": "content",
      "text": "When a job raises an error, Resque doesn't retry it. It adds an entry to `resque:failed`\nwith the error, the `exception` class, the `backtrace`, the `failed_at` time, the `queue`,\nthe `worker`, and the original `payload`. In a test run, a job that raised `smtp down`\nproduced an entry with `payload` `FlakyJob` and the error message `smtp down`, and the job did\nnot run again."
    },
    {
      "id": "what-happens-to-a-job-when-a-worker-is-killed",
      "title": "What happens to a job when a worker is killed",
      "role": "content",
      "text": "Resque forks a child process for each job. After a worker and its child were stopped with\n`kill -9` partway through a job:\n\n- The queue was empty and `resque:failed` stayed empty for the 30 seconds that the test ran,\n  and the job did not run again. The dead worker remained registered.\n- Resque finds dead workers by their heartbeat. A worker started afterward unregistered the\n  dead one and moved its job to `resque:failed` as `Resque::DirtyExit` (\"Job still being\n  processed\") once the dead worker's heartbeat was older than the prune interval.\n\nThe defaults are a heartbeat every 60 seconds and a prune interval of 300 seconds, so by\ndefault a killed worker's job fails after about five minutes. With\n`Resque.heartbeat_interval = 2` and `Resque.prune_interval = 6`, the job was in\n`resque:failed` 5 seconds after the kill. Either way, Resque doesn't re-run the job for you,\nso write jobs that are safe to run twice and decide what to do with entries in\n`resque:failed`."
    },
    {
      "id": "more-information",
      "title": "More information",
      "role": "content",
      "text": "- [Resque on GitHub](https://github.com/resque/resque)"
    }
  ],
  "examples": [
    {
      "id": "requirements-ex0",
      "language": "bash",
      "code": "bundle add resque",
      "section_id": "requirements"
    },
    {
      "id": "define-and-enqueue-a-job-ex0",
      "language": "ruby",
      "code": "# jobs.rb\nrequire \"resque\"\n\nResque.redis = \"<your-redis-host>:6379\"\n\nclass WelcomeEmail\n  @queue = :default\n\n  def self.perform(user_id, greeting)\n    puts \"Sending welcome to #{user_id}: #{greeting}\"\n  end\nend",
      "section_id": "define-and-enqueue-a-job"
    },
    {
      "id": "define-and-enqueue-a-job-ex1",
      "language": "ruby",
      "code": "Resque.enqueue(WelcomeEmail, 42, \"hello\")",
      "section_id": "define-and-enqueue-a-job"
    },
    {
      "id": "run-a-worker-ex0",
      "language": "ruby",
      "code": "# Rakefile\nrequire_relative \"jobs\"\nrequire \"resque/tasks\"",
      "section_id": "run-a-worker"
    },
    {
      "id": "run-a-worker-ex1",
      "language": "bash",
      "code": "QUEUE=default INTERVAL=1 bundle exec rake resque:work",
      "section_id": "run-a-worker"
    }
  ]
}
