from __future__ import absolute_import # For 'redis'

import redis

from ..job import Job
from .. import app_settings

class RedisBackend(object):
    KEY = 'django_lightweight_queue'

    def __init__(self):
        self.client = redis.Redis(
            host=app_settings.REDIS_HOST,
            port=app_settings.REDIS_PORT,
        )

    def enqueue(self, job):
        self.client.rpush(self.KEY, job.to_json())

    def dequeue(self, timeout):
        data = self.client.blpop(self.KEY, timeout)

        if data is not None:
            return Job.from_json(data)

from __future__ import absolute_import # For 'redis'

import redis

from ..job import Job
from .. import app_settings

class RedisBackend(object):
    KEY = 'django_lightweight_queue'

    def __init__(self):
        self.client = redis.Redis(
            host=app_settings.REDIS_HOST,
            port=app_settings.REDIS_PORT,
        )

    def enqueue(self, job):
        self.client.rpush(self.KEY, job.to_json())

    def dequeue(self, timeout):
        try:
            key, data = self.client.blpop(self.KEY, timeout)

            return Job.from_json(data)
        except TypeError:
            pass

Fix Redis backend; BLPOP takes multiple lists.
Fix Redis backend; BLPOP takes multiple lists.

Signed-off-by: Chris Lamb <711c73f64afdce07b7e38039a96d2224209e9a6c@thread.com>

  from __future__ import absolute_import # For 'redis'
  
  import redis
  
  from ..job import Job
  from .. import app_settings
  
  class RedisBackend(object):
      KEY = 'django_lightweight_queue'
  
      def __init__(self):
          self.client = redis.Redis(
              host=app_settings.REDIS_HOST,
              port=app_settings.REDIS_PORT,
          )
  
      def enqueue(self, job):
          self.client.rpush(self.KEY, job.to_json())
  
      def dequeue(self, timeout):
+         try:
-         data = self.client.blpop(self.KEY, timeout)
+             key, data = self.client.blpop(self.KEY, timeout)
  
-         if data is not None:
              return Job.from_json(data)
+         except TypeError:
+             pass
  
Fix Redis backend; BLPOP takes multiple lists.
## Code Before:
from __future__ import absolute_import # For 'redis'

import redis

from ..job import Job
from .. import app_settings

class RedisBackend(object):
    KEY = 'django_lightweight_queue'

    def __init__(self):
        self.client = redis.Redis(
            host=app_settings.REDIS_HOST,
            port=app_settings.REDIS_PORT,
        )

    def enqueue(self, job):
        self.client.rpush(self.KEY, job.to_json())

    def dequeue(self, timeout):
        data = self.client.blpop(self.KEY, timeout)

        if data is not None:
            return Job.from_json(data)

## Instruction:
Fix Redis backend; BLPOP takes multiple lists.
## Code After:
from __future__ import absolute_import # For 'redis'

import redis

from ..job import Job
from .. import app_settings

class RedisBackend(object):
    KEY = 'django_lightweight_queue'

    def __init__(self):
        self.client = redis.Redis(
            host=app_settings.REDIS_HOST,
            port=app_settings.REDIS_PORT,
        )

    def enqueue(self, job):
        self.client.rpush(self.KEY, job.to_json())

    def dequeue(self, timeout):
        try:
            key, data = self.client.blpop(self.KEY, timeout)

            return Job.from_json(data)
        except TypeError:
            pass
