# Path: falconswagger/models/orm/redis_base.py
# class ModelRedisBaseMeta(ModelLoggerMetaMixin, ModelOrmHttpMetaMixin):
# 
#     def __init__(cls, name, base_classes, attributes):
#         cls._set_logger()
# 
#         if hasattr(cls, '__schema__'):
#             cls._set_routes()
#         else:
#             cls._set_key()
# 
#     def _to_list(cls, objs):
#         return objs if isinstance(objs, list) else [objs]
# 
#     def get_filters_names_key(cls):
#         return cls.__key__ + '_filters_names'
# 
#     def get_key(cls, filters_names=None):
#         if not filters_names or filters_names == cls.__key__:
#             return cls.__key__
# 
#         return '{}_{}'.format(cls.__key__, filters_names)
# 
#     def get_instance_key(cls, instance, id_names=None):
#         if isinstance(instance, dict):
#             ids_ = [str(v) for v in ModelRedisBaseMeta.get_ids_values(cls, instance, id_names)]
#         else:
#             ids_ = [str(v) for v in cls.get_ids_values(instance, id_names)]
# 
#         return cls.__keys_separator__.decode().join(ids_).encode()
# 
#     def get_ids_values(cls, obj, keys=None):
#         if keys is None:
#             keys = cls.__id_names__
# 
#         return tuple([dict.get(obj, key) for key in sorted(keys)])
# 
# class ModelRedisBase(object):
#     __session__ = None
#     __authorizer__ = None
#     __api__ = None
#     __id_names__ = None
# 
#     def get_key(self, id_names=None):
#         return type(self).get_instance_key(self, id_names)


from falconswagger.models.orm.redis_base import ModelRedisBaseMeta, ModelRedisBase
from collections import OrderedDict
from copy import deepcopy
from types import MethodType
import msgpack
        return cls.get_instance_key(id_, id_.keys())

    def delete(cls, session, ids, **kwargs):
        keys = [cls._build_key(id_) for id_ in cls._to_list(ids)]
        if keys:
            session.redis_bind.hdel(cls.__key__, *keys)

    def get(cls, session, ids=None, limit=None, offset=None, **kwargs):
        if limit is not None and offset is not None:
            limit += offset

        elif ids is None and limit is None and offset is None:
            return cls._unpack_objs(session.redis_bind.hgetall(cls.__key__))

        if ids is None:
            keys = [k for k in session.redis_bind.hkeys(cls.__key__)][offset:limit]
            if keys:
                return cls._unpack_objs(session.redis_bind.hmget(cls.__key__, *keys))
            else:
                return []
        else:
            ids = [cls._build_key(id_) for id_ in cls._to_list(ids)]
            return cls._unpack_objs(session.redis_bind.hmget(cls.__key__, *ids[offset:limit]))

    def _unpack_objs(cls, objs):
        if isinstance(objs, dict):
            objs = objs.values()
        return [msgpack.loads(obj, encoding='utf-8') for obj in objs if obj is not None]



# Path: falconswagger/models/orm/redis_base.py
# class ModelRedisBaseMeta(ModelLoggerMetaMixin, ModelOrmHttpMetaMixin):
# 
#     def __init__(cls, name, base_classes, attributes):
#         cls._set_logger()
# 
#         if hasattr(cls, '__schema__'):
#             cls._set_routes()
#         else:
#             cls._set_key()
# 
#     def _to_list(cls, objs):
#         return objs if isinstance(objs, list) else [objs]
# 
#     def get_filters_names_key(cls):
#         return cls.__key__ + '_filters_names'
# 
#     def get_key(cls, filters_names=None):
#         if not filters_names or filters_names == cls.__key__:
#             return cls.__key__
# 
#         return '{}_{}'.format(cls.__key__, filters_names)
# 
#     def get_instance_key(cls, instance, id_names=None):
#         if isinstance(instance, dict):
#             ids_ = [str(v) for v in ModelRedisBaseMeta.get_ids_values(cls, instance, id_names)]
#         else:
#             ids_ = [str(v) for v in cls.get_ids_values(instance, id_names)]
# 
#         return cls.__keys_separator__.decode().join(ids_).encode()
# 
#     def get_ids_values(cls, obj, keys=None):
#         if keys is None:
#             keys = cls.__id_names__
# 
#         return tuple([dict.get(obj, key) for key in sorted(keys)])
# 
# class ModelRedisBase(object):
#     __session__ = None
#     __authorizer__ = None
#     __api__ = None
#     __id_names__ = None
# 
#     def get_key(self, id_names=None):
#         return type(self).get_instance_key(self, id_names)


# Path: falconswagger/models/orm/redis.py
from falconswagger.models.orm.redis_base import ModelRedisBaseMeta, ModelRedisBase
from collections import OrderedDict
from copy import deepcopy
from types import MethodType
import msgpack

        return cls.get_instance_key(id_, id_.keys())

    def delete(cls, session, ids, **kwargs):
        keys = [cls._build_key(id_) for id_ in cls._to_list(ids)]
        if keys:
            session.redis_bind.hdel(cls.__key__, *keys)

    def get(cls, session, ids=None, limit=None, offset=None, **kwargs):
        if limit is not None and offset is not None:
            limit += offset

        elif ids is None and limit is None and offset is None:
            return cls._unpack_objs(session.redis_bind.hgetall(cls.__key__))

        if ids is None:
            keys = [k for k in session.redis_bind.hkeys(cls.__key__)][offset:limit]
            if keys:
                return cls._unpack_objs(session.redis_bind.hmget(cls.__key__, *keys))
            else:
                return []
        else:
            ids = [cls._build_key(id_) for id_ in cls._to_list(ids)]
            return cls._unpack_objs(session.redis_bind.hmget(cls.__key__, *ids[offset:limit]))

    def _unpack_objs(cls, objs):
        if isinstance(objs, dict):
            objs = objs.values()
        return [msgpack.loads(obj, encoding='utf-8') for obj in objs if obj is not None]



class _ModelRedis(dict, ModelRedisBase):