# 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)
        if withscores:
            pieces.append(b('WITHSCORES'))
        options = {
            'withscores': withscores,
            'score_cast_func': score_cast_func
        }
        return await self.execute_command(*pieces, **options)

    async def zrevrank(self, name, value):
        """
        Returns a 0-based value indicating the descending rank of
        ``value`` in sorted set ``name``
        """
        return await self.execute_command('ZREVRANK', name, value)

    async def zscore(self, name, value):
        "Return the score of element ``value`` in sorted set ``name``"
        return await self.execute_command('ZSCORE', name, value)

    async def zunionstore(self, dest, keys, aggregate=None):
        """
        Performs Union on multiple sorted sets specified by ``keys`` into
        a new sorted set, ``dest``. Scores in the destination will be
        aggregated based on the ``aggregate``, or SUM if none is provided.
        """
        return await self._zaggregate('ZUNIONSTORE', dest, keys, aggregate)

    async def _zaggregate(self, command, dest, keys, aggregate=None):
        pieces = [command, dest, len(keys)]
        if isinstance(keys, dict):

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

        if withscores:
            pieces.append(b('WITHSCORES'))
        options = {
            'withscores': withscores,
            'score_cast_func': score_cast_func
        }
        return await self.execute_command(*pieces, **options)

    async def zrevrank(self, name, value):
        """
        Returns a 0-based value indicating the descending rank of
        ``value`` in sorted set ``name``
        """
        return await self.execute_command('ZREVRANK', name, value)

    async def zscore(self, name, value):
        "Return the score of element ``value`` in sorted set ``name``"
        return await self.execute_command('ZSCORE', name, value)

    async def zunionstore(self, dest, keys, aggregate=None):
        """
        Performs Union on multiple sorted sets specified by ``keys`` into
        a new sorted set, ``dest``. Scores in the destination will be
        aggregated based on the ``aggregate``, or SUM if none is provided.
        """
        return await self._zaggregate('ZUNIONSTORE', dest, keys, aggregate)

    async def _zaggregate(self, command, dest, keys, aggregate=None):
        pieces = [command, dest, len(keys)]
        if isinstance(keys, dict):

            keys, weights = iterkeys(keys), itervalues(keys)