<commit_before>from aioredis.util import wait_convert, _NOTSET, _ScanIter


class SortedSetCommandsMixin:
    """Sorted Sets commands mixin.

    For commands details see: http://redis.io/commands/#sorted_set
    """

    ZSET_EXCLUDE_MIN = 'ZSET_EXCLUDE_MIN'
    ZSET_EXCLUDE_MAX = 'ZSET_EXCLUDE_MAX'
    ZSET_EXCLUDE_BOTH = 'ZSET_EXCLUDE_BOTH'

    ZSET_AGGREGATE_SUM = 'ZSET_AGGREGATE_SUM'
    ZSET_AGGREGATE_MIN = 'ZSET_AGGREGATE_MIN'
    ZSET_AGGREGATE_MAX = 'ZSET_AGGREGATE_MAX'

    ZSET_IF_NOT_EXIST = 'ZSET_IF_NOT_EXIST'  # NX
    ZSET_IF_EXIST = 'ZSET_IF_EXIST'  # XX

    def bzpopmax(self, key, *keys, timeout=0, encoding=_NOTSET):
        """Remove and get an element with the highest score in the sorted set,
        or block until one is available.

        :raises TypeError: if timeout is not int
        :raises ValueError: if timeout is less than 0
        """
        if not isinstance(timeout, int):
            raise TypeError("timeout argument must be int")
        if timeout < 0:
            raise ValueError("timeout must be greater equal 0")
        args = keys + (timeout,)
        return self.execute(b'BZPOPMAX', key, *args, encoding=encoding)

    def bzpopmin(self, key, *keys, timeout=0, encoding=_NOTSET):
        """Remove and get an element with the lowest score in the sorted set,
        or block until one is available.

        :raises TypeError: if timeout is not int
        :raises ValueError: if timeout is less than 0
        """
        if not isinstance(timeout, int):
            raise TypeError("timeout argument must be int")
        if timeout < 0:
            raise ValueError("timeout must be greater equal 0")
        args = keys + (timeout,)
        return self.execute(b'BZPOPMIN', key, *args, encoding=encoding)

    def zadd(self, key, score, member, *pairs, exist=None):
        """Add one or more members to a sorted set or update its score.

        :raises TypeError: score not int or float
        :raises TypeError: length of pairs is not even number
        """
        if not isinstance(score, (int, float)):
            raise TypeError("score argument must be int or float")
        if len(pairs) % 2 != 0:
            raise TypeError("length of pairs must be even number")

        scores = (item for i, item in enumerate(pairs) if i % 2 == 0)
        if any(not isinstance(s, (int, float)) for s in scores):
            raise TypeError("all scores must be int or float")

        args = []
        if exist is self.ZSET_IF_EXIST:
            args.append(b'XX')
        elif exist is self.ZSET_IF_NOT_EXIST:
            args.append(b'NX')<commit_msg>Support for `INCR` and `CH` arguments of the `ZADD` command.<commit_after>from aioredis.util import wait_convert, _NOTSET, _ScanIter


class SortedSetCommandsMixin:
    """Sorted Sets commands mixin.

    For commands details see: http://redis.io/commands/#sorted_set
    """

    ZSET_EXCLUDE_MIN = 'ZSET_EXCLUDE_MIN'
    ZSET_EXCLUDE_MAX = 'ZSET_EXCLUDE_MAX'
    ZSET_EXCLUDE_BOTH = 'ZSET_EXCLUDE_BOTH'

    ZSET_AGGREGATE_SUM = 'ZSET_AGGREGATE_SUM'
    ZSET_AGGREGATE_MIN = 'ZSET_AGGREGATE_MIN'
    ZSET_AGGREGATE_MAX = 'ZSET_AGGREGATE_MAX'

    ZSET_IF_NOT_EXIST = 'ZSET_IF_NOT_EXIST'  # NX
    ZSET_IF_EXIST = 'ZSET_IF_EXIST'  # XX

    def bzpopmax(self, key, *keys, timeout=0, encoding=_NOTSET):
        """Remove and get an element with the highest score in the sorted set,
        or block until one is available.

        :raises TypeError: if timeout is not int
        :raises ValueError: if timeout is less than 0
        """
        if not isinstance(timeout, int):
            raise TypeError("timeout argument must be int")
        if timeout < 0:
            raise ValueError("timeout must be greater equal 0")
        args = keys + (timeout,)
        return self.execute(b'BZPOPMAX', key, *args, encoding=encoding)

    def bzpopmin(self, key, *keys, timeout=0, encoding=_NOTSET):
        """Remove and get an element with the lowest score in the sorted set,
        or block until one is available.

        :raises TypeError: if timeout is not int
        :raises ValueError: if timeout is less than 0
        """
        if not isinstance(timeout, int):
            raise TypeError("timeout argument must be int")
        if timeout < 0:
            raise ValueError("timeout must be greater equal 0")
        args = keys + (timeout,)
        return self.execute(b'BZPOPMIN', key, *args, encoding=encoding)

    def zadd(self, key, score, member, *pairs, exist=None, changed=False,
             incr=False):
        """Add one or more members to a sorted set or update its score.

        :raises TypeError: score not int or float
        :raises TypeError: length of pairs is not even number
        """
        if not isinstance(score, (int, float)):
            raise TypeError("score argument must be int or float")
        if len(pairs) % 2 != 0:
            raise TypeError("length of pairs must be even number")

        scores = (item for i, item in enumerate(pairs) if i % 2 == 0)
        if any(not isinstance(s, (int, float)) for s in scores):
            raise TypeError("all scores must be int or float")

        args = []
        if exist is self.ZSET_IF_EXIST:
            args.append(b'XX')
        elif exist is self.ZSET_IF_NOT_EXIST:
            args.append(b'NX')

        if changed:
            args.append(b'CH')

        if incr:
            if pairs:
                raise ValueError('only one score-element pair '
                                 'can be specified in this mode')
            args.append(b'INCR')
{'fraction_non_alphanumeric': 0.08838293295087846, 'fraction_numerical': 0.004302617425600574, 'mean_word_length': 2.482521847690387, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2466281', 'n_tokens_mistral': 1746, 'n_tokens_neox': 1685, 'n_words': 571}