Skip to content

Instantly share code, notes, and snippets.

@danLeBrown
Last active July 9, 2023 21:00
Show Gist options
  • Save danLeBrown/5597b8ae1458c14f98a83e420ed837ed to your computer and use it in GitHub Desktop.
Save danLeBrown/5597b8ae1458c14f98a83e420ed837ed to your computer and use it in GitHub Desktop.
Queues implementation using Bull JS & Redis

Queues implementation using Bull JS & Redis

Introduction

Here are some of the identified suffixes for the keys you will find in Redis and the values they hold:

  • :id - this key references the progression of the job ID. It is used to generate the next job ID
  • :stalled-check - the time (probably of insertion) of the last stalled job
  • :completed - the ids of completed jobs
  • :failed - the ids of failed jobs

Some examples of the (full) keys you will find in Redis:

  • "SyfqZ5J89Kxw4eOX:transfer:stalled-check"
  • "tgURfiHK6N:notification:id"
  • "tgURfiHK6N:notification:2"
  • "tgURfiHK6N:funding:id"
  • "tgURfiHK6N:transfer:stalled-check"
  • "tgURfiHK6N:notification:failed"
  • "SyfqZ5J89Kxw4eOX:webhook:stalled-check"
  • "SyfqZ5J89Kxw4eOX:funding:stalled-check"
  • "tgURfiHK6N:webhook:stalled-check"

From the above, you can tell that the keys are in this format: <QUEUE_PREFIX>:<QUEUE_NAME>:<SUFFIX>

Using Redis

Redis CLI

To know the type of a key, use the TYPE command:

redis-cli
TYPE tgURfiHK6N:notification:failed

If the key exists, it will return the type of the key, otherwise it will return none.

Here are some of the types you will find:

  • string - the value is a string
  • zset - the value is a sorted set of strings
  • hash - the value is a hash map of strings to strings
  1. To get the contents of a string key, use the GET command:
GET tgURfiHK6N:notification:failed
  1. To get the contents of a zset key, use the ZRANGE command:
ZRANGE tgURfiHK6N:notification:failed 0 -1
  1. To get the contents of a hash key, use the HGETALL command:
HGETALL tgURfiHK6N:notification:failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment