# Path: aredis/exceptions.py
# class RedisError(Exception):
#     pass
# 
# Path: aredis/utils.py
# def b(x):
#     return x.encode('latin-1') if not isinstance(x, bytes) else x
# 
# def iteritems(x):
#     return iter(x.items())
# 
# def first_key(res):
#     """
#     Returns the first result for the given command.
# 
#     If more then 1 result is returned then a `RedisClusterException` is raised.
#     """
#     if not isinstance(res, dict):
#         raise ValueError('Value should be of dict type')
# 
#     if len(res.keys()) != 1:
#         raise RedisClusterException("More then 1 result from command")
# 
#     return list(res.values())[0]
# 
# def iterkeys(x):
#     return iter(x.keys())
# 
# def itervalues(x):
#     return iter(x.values())
# 
# def dict_merge(*dicts):
#     merged = {}
#     for d in dicts:
#         merged.update(d)
#     return merged
# 
# def string_keys_to_dict(key_string, callback):
#     return dict.fromkeys(key_string.split(), callback)
# 
# def int_or_none(response):
#     if response is None:
#         return None
#     return int(response)


import re
from aredis.exceptions import RedisError
from aredis.utils import (b, iteritems,
                          first_key,
                          iterkeys,
                          itervalues,
                          dict_merge,
                          string_keys_to_dict,
                          int_or_none)
            'ZREMRANGEBYSCORE', int
        ),
        string_keys_to_dict('ZSCORE ZINCRBY', float_or_none),
        string_keys_to_dict(
            'ZRANGE ZRANGEBYSCORE ZREVRANGE ZREVRANGEBYSCORE',
            zset_score_pairs
        ),
        string_keys_to_dict('ZRANK ZREVRANK', int_or_none),
        {
            'ZSCAN': parse_zscan,
        }
    )

    async def zadd(self, name, *args, **kwargs):
        """
        Set any number of score, element-name pairs to the key ``name``. Pairs
        can be specified in two ways:

        As *args, in the form of: score1, name1, score2, name2, ...
        or as **kwargs, in the form of: name1=score1, name2=score2, ...

        The following example would add four values to the 'my-key' key:
        redis.zadd('my-key', 1.1, 'name1', 2.2, 'name2', name3=3.3, name4=4.4)
        """
        pieces = []
        if args:
            if len(args) % 2 != 0:
                raise RedisError("ZADD requires an equal number of "
                                 "values and scores")
            pieces.extend(args)

# Path: aredis/exceptions.py
# class RedisError(Exception):
#     pass
# 
# Path: aredis/utils.py
# def b(x):
#     return x.encode('latin-1') if not isinstance(x, bytes) else x
# 
# def iteritems(x):
#     return iter(x.items())
# 
# def first_key(res):
#     """
#     Returns the first result for the given command.
# 
#     If more then 1 result is returned then a `RedisClusterException` is raised.
#     """
#     if not isinstance(res, dict):
#         raise ValueError('Value should be of dict type')
# 
#     if len(res.keys()) != 1:
#         raise RedisClusterException("More then 1 result from command")
# 
#     return list(res.values())[0]
# 
# def iterkeys(x):
#     return iter(x.keys())
# 
# def itervalues(x):
#     return iter(x.values())
# 
# def dict_merge(*dicts):
#     merged = {}
#     for d in dicts:
#         merged.update(d)
#     return merged
# 
# def string_keys_to_dict(key_string, callback):
#     return dict.fromkeys(key_string.split(), callback)
# 
# def int_or_none(response):
#     if response is None:
#         return None
#     return int(response)


# Path: aredis/commands/sorted_set.py
import re
from aredis.exceptions import RedisError
from aredis.utils import (b, iteritems,
                          first_key,
                          iterkeys,
                          itervalues,
                          dict_merge,
                          string_keys_to_dict,
                          int_or_none)

            'ZREMRANGEBYSCORE', int
        ),
        string_keys_to_dict('ZSCORE ZINCRBY', float_or_none),
        string_keys_to_dict(
            'ZRANGE ZRANGEBYSCORE ZREVRANGE ZREVRANGEBYSCORE',
            zset_score_pairs
        ),
        string_keys_to_dict('ZRANK ZREVRANK', int_or_none),
        {
            'ZSCAN': parse_zscan,
        }
    )

    async def zadd(self, name, *args, **kwargs):
        """
        Set any number of score, element-name pairs to the key ``name``. Pairs
        can be specified in two ways:

        As *args, in the form of: score1, name1, score2, name2, ...
        or as **kwargs, in the form of: name1=score1, name2=score2, ...

        The following example would add four values to the 'my-key' key:
        redis.zadd('my-key', 1.1, 'name1', 2.2, 'name2', name3=3.3, name4=4.4)
        """
        pieces = []
        if args:
            if len(args) % 2 != 0:
                raise RedisError("ZADD requires an equal number of "
                                 "values and scores")
            pieces.extend(args)

        for pair in iteritems(kwargs):