# 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)


def zset_score_pairs(response, **options):
    """
    If ``withscores`` is specified in the options, return the response as
    a list of (value, score) pairs
    """
    if not response or not options['withscores']:
        return response
    score_cast_func = options.get('score_cast_func', float)
    it = iter(response)
    return list(zip(it, map(score_cast_func, it)))


def parse_zscan(response, **options):
    score_cast_func = options.get('score_cast_func', float)
    cursor, r = response
    it = iter(r)
    return int(cursor), list(zip(it, map(score_cast_func, it)))


class SortedSetCommandMixin:

    RESPONSE_CALLBACKS = dict_merge(
        string_keys_to_dict(
            'ZADD ZCARD ZLEXCOUNT '
            'ZREM ZREMRANGEBYLEX '
            'ZREMRANGEBYRANK '
            'ZREMRANGEBYSCORE', int
        ),

# 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)



def zset_score_pairs(response, **options):
    """
    If ``withscores`` is specified in the options, return the response as
    a list of (value, score) pairs
    """
    if not response or not options['withscores']:
        return response
    score_cast_func = options.get('score_cast_func', float)
    it = iter(response)
    return list(zip(it, map(score_cast_func, it)))


def parse_zscan(response, **options):
    score_cast_func = options.get('score_cast_func', float)
    cursor, r = response
    it = iter(r)
    return int(cursor), list(zip(it, map(score_cast_func, it)))


class SortedSetCommandMixin:

    RESPONSE_CALLBACKS = dict_merge(
        string_keys_to_dict(
            'ZADD ZCARD ZLEXCOUNT '
            'ZREM ZREMRANGEBYLEX '
            'ZREMRANGEBYRANK '
            'ZREMRANGEBYSCORE', int
        ),

        string_keys_to_dict('ZSCORE ZINCRBY', float_or_none),