예제 #1
0
파일: modelset.py 프로젝트: 89sos98/redisco
 def _add_zfilters(self):
     k, v = self._zfilters[0].items()[0]
     try:
         att, op = k.split('__')
     except ValueError:
         raise ValueError("zfilter should have an operator.")
     index = self.model_class._key[att]
     desc = self.model_class._attributes[att]
     zset = SortedSet(index)
     limit, offset = self._get_limit_and_offset()
     if isinstance(v, (tuple, list,)):
         min, max = v
         min = float(desc.typecast_for_storage(min))
         max = float(desc.typecast_for_storage(max))
     else:
         v = float(desc.typecast_for_storage(v))
     if op == 'lt':
         return zset.lt(v, limit, offset)
     elif op == 'gt':
         return zset.gt(v, limit, offset)
     elif op == 'gte':
         return zset.ge(v, limit, offset)
     elif op == 'lte':
         return zset.le(v, limit, offset)
     elif op == 'in':
         return zset.between(min, max, limit, offset)
예제 #2
0
    def _add_zfilters(self):
        """
        This function is the internals of the zfilter function.
        It will create a SortedSet and will compare the scores to
        the value provided.

        :return: a SortedSet with the ids.

        """

        k, v = self._zfilters[0].items()[0]
        try:
            att, op = k.split('__')
        except ValueError:
            raise ValueError("zfilter should have an operator.")
        index = self.model_class._key[att]
        desc = self.model_class._attributes[att]
        zset = SortedSet(index, db=self.db)
        limit, offset = self._get_limit_and_offset()
        if isinstance(v, (tuple, list,)):
            min, max = v
            min = float(desc.typecast_for_storage(min))
            max = float(desc.typecast_for_storage(max))
        else:
            v = float(desc.typecast_for_storage(v))
        if op == 'lt':
            return zset.lt(v, limit, offset)
        elif op == 'gt':
            return zset.gt(v, limit, offset)
        elif op == 'gte':
            return zset.ge(v, limit, offset)
        elif op == 'lte':
            return zset.le(v, limit, offset)
        elif op == 'in':
            return zset.between(min, max, limit, offset)
예제 #3
0
 def _add_zfilters(self):
     k, v = self._zfilters[0].items()[0]
     try:
         att, op = k.split('__')
     except ValueError:
         raise ValueError("zfilter should have an operator.")
     index = self.model_class._key[att]
     desc = self.model_class._attributes[att]
     zset = SortedSet(index)
     limit, offset = self._get_limit_and_offset()
     if isinstance(v, (
             tuple,
             list,
     )):
         min, max = v
         min = float(desc.typecast_for_storage(min))
         max = float(desc.typecast_for_storage(max))
     else:
         v = float(desc.typecast_for_storage(v))
     if op == 'lt':
         return zset.lt(v, limit, offset)
     elif op == 'gt':
         return zset.gt(v, limit, offset)
     elif op == 'gte':
         return zset.ge(v, limit, offset)
     elif op == 'lte':
         return zset.le(v, limit, offset)
     elif op == 'in':
         return zset.between(min, max, limit, offset)
예제 #4
0
    def _add_zfilters(self, s):
        """
        This function is the internals of the zfilter function.
        It will create a SortedSet and will compare the scores to
        the value provided.

        :return: a SortedSet with the ids.

        """
        k, v = self._zfilters[0].items()[0]
        try:
            att, op = k.split('__')
        except ValueError:
            raise ValueError("zfilter should have an operator.")
        index = self.model_class._key[att]
        desc = self.model_class._attributes[att]
        zset = SortedSet(index, db=self.db)
        limit, offset = self._get_limit_and_offset()
        new_set_key = "~%s.%s" % ("+".join([self.key, att, op]), id(self))
        new_set_key_temp = "#%s.%s" % ("+".join([self.key, att, op]), id(self))
        members = []
        if isinstance(v, (
                tuple,
                list,
        )):
            min, max = v
            min = float(desc.typecast_for_storage(min))
            max = float(desc.typecast_for_storage(max))
        else:
            v = float(desc.typecast_for_storage(v))
        if op == 'lt':
            members = zset.lt(v, limit, offset)
        elif op == 'gt':
            members = zset.gt(v, limit, offset)
        elif op == 'gte':
            members = zset.ge(v, limit, offset)
        elif op == 'le':
            members = zset.le(v, limit, offset)
        elif op == 'lte':
            members = zset.le(v, limit, offset)
        elif op == 'in':
            members = zset.between(min, max, limit, offset)

        temp_set = Set(new_set_key_temp)
        if members:
            temp_set.add(*members)
        temp_set.set_expire()

        s.intersection(new_set_key, temp_set)
        new_set = Set(new_set_key)
        new_set.set_expire()
        return new_set
예제 #5
0
파일: modelset.py 프로젝트: Lipvun/redisco
    def _add_zfilters(self, s):
        """
        This function is the internals of the zfilter function.
        It will create a SortedSet and will compare the scores to
        the value provided.

        :return: a SortedSet with the ids.

        """
        k, v = self._zfilters[0].items()[0]
        try:
            att, op = k.split('__')
        except ValueError:
            raise ValueError("zfilter should have an operator.")
        index = self.model_class._key[att]
        desc = self.model_class._attributes[att]
        zset = SortedSet(index, db=self.db)
        limit, offset = self._get_limit_and_offset()
        new_set_key = "~%s.%s" % ("+".join([self.key, att, op]), id(self))
        new_set_key_temp = "#%s.%s" % ("+".join([self.key, att, op]), id(self))
        members = []
        if isinstance(v, (tuple, list,)):
            min, max = v
            min = float(desc.typecast_for_storage(min))
            max = float(desc.typecast_for_storage(max))
        else:
            v = float(desc.typecast_for_storage(v))
        if op == 'lt':
            members = zset.lt(v, limit, offset)
        elif op == 'gt':
            members = zset.gt(v, limit, offset)
        elif op == 'gte':
            members = zset.ge(v, limit, offset)
        elif op == 'le':
            members = zset.le(v, limit, offset)
        elif op == 'lte':
            members = zset.le(v, limit, offset)
        elif op == 'in':
            members = zset.between(min, max, limit, offset)

        temp_set = Set(new_set_key_temp)
        if members:
            temp_set.add(*members)
        temp_set.set_expire()

        s.intersection(new_set_key, temp_set)
        new_set = Set(new_set_key)
        new_set.set_expire()
        return new_set