# Path: datapackage_pipelines/utilities/extended_json.py
# class json(object):
#     dumps = _dumps
#     loads = _loads
#     dumpl = _dumpl
#     loadl = _loadl
#     dump = _dump
#     load = _load
#     JSONDecodeError = _json.JSONDecodeError


import logging
import redis
from datapackage_pipelines.utilities.extended_json import json




class RedisBackend(object):

    KIND = 'redis'

    def __init__(self, host=None, port=6379):
        self.redis = None
        if host is not None and len(host) > 0:
            conn = redis.StrictRedis(host=host, port=port, db=5)
            try:
                conn.ping()
                self.redis = conn
            except redis.exceptions.ConnectionError:
                logging.warning('Failed to connect to Redis, host:%s, port:%s',
                                host, port)

    def is_init(self):
        return self.redis is not None

    def get_status(self, pipeline_id):
        if self.is_init():
            status = self.redis.get(pipeline_id)
            if status is not None:

# Path: datapackage_pipelines/utilities/extended_json.py
# class json(object):
#     dumps = _dumps
#     loads = _loads
#     dumpl = _dumpl
#     loadl = _loadl
#     dump = _dump
#     load = _load
#     JSONDecodeError = _json.JSONDecodeError


# Path: datapackage_pipelines/status/backend_redis.py
import logging
import redis
from datapackage_pipelines.utilities.extended_json import json





class RedisBackend(object):

    KIND = 'redis'

    def __init__(self, host=None, port=6379):
        self.redis = None
        if host is not None and len(host) > 0:
            conn = redis.StrictRedis(host=host, port=port, db=5)
            try:
                conn.ping()
                self.redis = conn
            except redis.exceptions.ConnectionError:
                logging.warning('Failed to connect to Redis, host:%s, port:%s',
                                host, port)

    def is_init(self):
        return self.redis is not None

    def get_status(self, pipeline_id):
        if self.is_init():
            status = self.redis.get(pipeline_id)
            if status is not None:

                status = json.loads(status.decode('ascii'))