# Path: aredis/exceptions.py
# class RedisClusterException(Exception):
#     pass
# 
# class ResponseError(RedisError):
#     pass
# 
# class DataError(RedisError):
#     pass
# 
# 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 iterkeys(x):
#     return iter(x.keys())
# 
# def itervalues(x):
#     return iter(x.values())
# 
# Path: aredis/commands/server.py
# def parse_info(response):
#     """Parses the result of Redis's INFO command into a Python dict"""
#     info = {}
#     response = nativestr(response)
# 
#     def get_value(value):
#         if ',' not in value or '=' not in value:
#             try:
#                 if '.' in value:
#                     return float(value)
#                 else:
#                     return int(value)
#             except ValueError:
#                 return value
#         else:
#             sub_dict = {}
#             for item in value.split(','):
#                 k, v = item.rsplit('=', 1)
#                 sub_dict[k] = get_value(v)
#             return sub_dict
# 
#     for line in response.splitlines():
#         if line and not line.startswith('#'):
#             if line.find(':') != -1:
#                 key, value = line.split(':', 1)
#                 info[key] = get_value(value)
#             else:
#                 # if the line isn't splittable, append it to the "__raw__" key
#                 info.setdefault('__raw__', []).append(line)
# 
#     return info
# 
# Path: tests/cluster/conftest.py
# def skip_if_server_version_lt(min_version):
#     """
#     """
#     versions = get_versions()
#     for version in versions.values():
#         if StrictVersion(version) < StrictVersion(min_version):
#             return pytest.mark.skipif(True, reason="")
#     return pytest.mark.skipif(False, reason="")
# 
# def skip_if_redis_py_version_lt(min_version):
#     """
#     """
#     import aredis
#     version = aredis.__version__
#     if StrictVersion(version) < StrictVersion(min_version):
#         return pytest.mark.skipif(True, reason="")
#     return pytest.mark.skipif(False, reason="")


import datetime
import re
import time
import pytest
from string import ascii_letters
from aredis.exceptions import RedisClusterException, ResponseError, DataError, RedisError
from aredis.utils import b, iteritems, iterkeys, itervalues
from aredis.commands.server import parse_info
from tests.cluster.conftest import skip_if_server_version_lt, skip_if_redis_py_version_lt

class TestBinarySave:
    @pytest.mark.asyncio
    async def test_binary_get_set(self, r):
        await r.flushdb()
        assert await r.set(' foo bar ', '123')
        assert await r.get(' foo bar ') == b('123')

        assert await r.set(' foo\r\nbar\r\n ', '456')
        assert await r.get(' foo\r\nbar\r\n ') == b('456')

        assert await r.set(' \r\n\t\x07\x13 ', '789')
        assert await r.get(' \r\n\t\x07\x13 ') == b('789')

        assert sorted(await r.keys('*')) == \
            [b(' \r\n\t\x07\x13 '), b(' foo\r\nbar\r\n '), b(' foo bar ')]

        assert await r.delete(' foo bar ')
        assert await r.delete(' foo\r\nbar\r\n ')
        assert await r.delete(' \r\n\t\x07\x13 ')

    @pytest.mark.asyncio
    async def test_binary_lists(self, r):
        await r.flushdb()
        mapping = {
            b('foo bar'): [b('1'), b('2'), b('3')],
            b('foo\r\nbar\r\n'): [b('4'), b('5'), b('6')],
            b('foo\tbar\x07'): [b('7'), b('8'), b('9')],
        }
        # fill in lists

# Path: aredis/exceptions.py
# class RedisClusterException(Exception):
#     pass
# 
# class ResponseError(RedisError):
#     pass
# 
# class DataError(RedisError):
#     pass
# 
# 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 iterkeys(x):
#     return iter(x.keys())
# 
# def itervalues(x):
#     return iter(x.values())
# 
# Path: aredis/commands/server.py
# def parse_info(response):
#     """Parses the result of Redis's INFO command into a Python dict"""
#     info = {}
#     response = nativestr(response)
# 
#     def get_value(value):
#         if ',' not in value or '=' not in value:
#             try:
#                 if '.' in value:
#                     return float(value)
#                 else:
#                     return int(value)
#             except ValueError:
#                 return value
#         else:
#             sub_dict = {}
#             for item in value.split(','):
#                 k, v = item.rsplit('=', 1)
#                 sub_dict[k] = get_value(v)
#             return sub_dict
# 
#     for line in response.splitlines():
#         if line and not line.startswith('#'):
#             if line.find(':') != -1:
#                 key, value = line.split(':', 1)
#                 info[key] = get_value(value)
#             else:
#                 # if the line isn't splittable, append it to the "__raw__" key
#                 info.setdefault('__raw__', []).append(line)
# 
#     return info
# 
# Path: tests/cluster/conftest.py
# def skip_if_server_version_lt(min_version):
#     """
#     """
#     versions = get_versions()
#     for version in versions.values():
#         if StrictVersion(version) < StrictVersion(min_version):
#             return pytest.mark.skipif(True, reason="")
#     return pytest.mark.skipif(False, reason="")
# 
# def skip_if_redis_py_version_lt(min_version):
#     """
#     """
#     import aredis
#     version = aredis.__version__
#     if StrictVersion(version) < StrictVersion(min_version):
#         return pytest.mark.skipif(True, reason="")
#     return pytest.mark.skipif(False, reason="")


# Path: tests/cluster/test_commands.py
import datetime
import re
import time
import pytest
from string import ascii_letters
from aredis.exceptions import RedisClusterException, ResponseError, DataError, RedisError
from aredis.utils import b, iteritems, iterkeys, itervalues
from aredis.commands.server import parse_info
from tests.cluster.conftest import skip_if_server_version_lt, skip_if_redis_py_version_lt


class TestBinarySave:
    @pytest.mark.asyncio
    async def test_binary_get_set(self, r):
        await r.flushdb()
        assert await r.set(' foo bar ', '123')
        assert await r.get(' foo bar ') == b('123')

        assert await r.set(' foo\r\nbar\r\n ', '456')
        assert await r.get(' foo\r\nbar\r\n ') == b('456')

        assert await r.set(' \r\n\t\x07\x13 ', '789')
        assert await r.get(' \r\n\t\x07\x13 ') == b('789')

        assert sorted(await r.keys('*')) == \
            [b(' \r\n\t\x07\x13 '), b(' foo\r\nbar\r\n '), b(' foo bar ')]

        assert await r.delete(' foo bar ')
        assert await r.delete(' foo\r\nbar\r\n ')
        assert await r.delete(' \r\n\t\x07\x13 ')

    @pytest.mark.asyncio
    async def test_binary_lists(self, r):
        await r.flushdb()
        mapping = {
            b('foo bar'): [b('1'), b('2'), b('3')],
            b('foo\r\nbar\r\n'): [b('4'), b('5'), b('6')],
            b('foo\tbar\x07'): [b('7'), b('8'), b('9')],
        }
        # fill in lists

        for key, value in iteritems(mapping):