from opps.db.conf import settings

from redis import ConnectionPool
from redis import Redis as RedisClient


class Redis:
    def __init__(self, key_prefix, key_sufix):
        self.key_prefix = key_prefix
        self.key_sufix = key_sufix
        self.host = settings.OPPS_DB_HOST
        self.port = settings.OPPS_DB_PORT
        self.db = 0

        pool = ConnectionPool(host=self.host,
                              port=self.port,
                              db=self.db)
        self.conn = RedisClient(connection_pool=pool)

    def close(self):
        self.conn = None
        return True

    def key(self):
        return '{}_{}_{}'.format(settings.OPPS_DB_NAME,
                                 self.key_prefix,
                                 self.key_sufix)


from opps.db.conf import settings

from redis import ConnectionPool
from redis import Redis as RedisClient


class Redis:
    def __init__(self, key_prefix, key_sufix):
        self.key_prefix = key_prefix
        self.key_sufix = key_sufix
        self.host = settings.OPPS_DB_HOST
        self.port = settings.OPPS_DB_PORT
        self.db = 0

        pool = ConnectionPool(host=self.host,
                              port=self.port,
                              db=self.db)
        self.conn = RedisClient(connection_pool=pool)

    def close(self):
        self.conn = None
        return True

    def key(self):
        return '{}_{}_{}'.format(settings.OPPS_DB_NAME,
                                 self.key_prefix,
                                 self.key_sufix)

    def save(self, document):
        return self.conn.set(self.key(), document)


Add method save, manager create or update on opps db redis
Add method save, manager create or update on opps db redis

  from opps.db.conf import settings
  
  from redis import ConnectionPool
  from redis import Redis as RedisClient
  
  
  class Redis:
      def __init__(self, key_prefix, key_sufix):
          self.key_prefix = key_prefix
          self.key_sufix = key_sufix
          self.host = settings.OPPS_DB_HOST
          self.port = settings.OPPS_DB_PORT
          self.db = 0
  
          pool = ConnectionPool(host=self.host,
                                port=self.port,
                                db=self.db)
          self.conn = RedisClient(connection_pool=pool)
  
      def close(self):
          self.conn = None
          return True
  
      def key(self):
          return '{}_{}_{}'.format(settings.OPPS_DB_NAME,
                                   self.key_prefix,
                                   self.key_sufix)
  
+     def save(self, document):
+         return self.conn.set(self.key(), document)
  
+ 
Add method save, manager create or update on opps db redis
## Code Before:
from opps.db.conf import settings

from redis import ConnectionPool
from redis import Redis as RedisClient


class Redis:
    def __init__(self, key_prefix, key_sufix):
        self.key_prefix = key_prefix
        self.key_sufix = key_sufix
        self.host = settings.OPPS_DB_HOST
        self.port = settings.OPPS_DB_PORT
        self.db = 0

        pool = ConnectionPool(host=self.host,
                              port=self.port,
                              db=self.db)
        self.conn = RedisClient(connection_pool=pool)

    def close(self):
        self.conn = None
        return True

    def key(self):
        return '{}_{}_{}'.format(settings.OPPS_DB_NAME,
                                 self.key_prefix,
                                 self.key_sufix)


## Instruction:
Add method save, manager create or update on opps db redis
## Code After:
from opps.db.conf import settings

from redis import ConnectionPool
from redis import Redis as RedisClient


class Redis:
    def __init__(self, key_prefix, key_sufix):
        self.key_prefix = key_prefix
        self.key_sufix = key_sufix
        self.host = settings.OPPS_DB_HOST
        self.port = settings.OPPS_DB_PORT
        self.db = 0

        pool = ConnectionPool(host=self.host,
                              port=self.port,
                              db=self.db)
        self.conn = RedisClient(connection_pool=pool)

    def close(self):
        self.conn = None
        return True

    def key(self):
        return '{}_{}_{}'.format(settings.OPPS_DB_NAME,
                                 self.key_prefix,
                                 self.key_sufix)

    def save(self, document):
        return self.conn.set(self.key(), document)

