# 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: aredis/exceptions.py
# class RedisError(Exception):
#     pass
# 
# class ResponseError(RedisError):
#     pass
# 
# class DataError(RedisError):
#     pass
# 
# Path: tests/client/conftest.py
# def skip_if_server_version_lt(min_version):
#     loop = asyncio.get_event_loop()
#     version = StrictVersion(loop.run_until_complete(get_version()))
#     check = version < StrictVersion(min_version)
#     return pytest.mark.skipif(check, reason="")
# 
# def skip_python_vsersion_lt(min_version):
#     min_version = tuple(map(int, min_version.split('.')))
#     check = sys.version_info[:2] < min_version
#     return pytest.mark.skipif(check, reason="")


import binascii
import datetime
import pytest
import aredis
import time
from string import ascii_letters
from aredis.utils import (b, iteritems,
                          iterkeys, itervalues)
from aredis.commands.server import parse_info
from aredis.exceptions import (RedisError,
                               ResponseError,
                               DataError)
from .conftest import (skip_if_server_version_lt,
                       skip_python_vsersion_lt)
    async def test_delete(self, r):
        await r.flushdb()
        assert await r.delete('a') == 0
        await r.set('a', 'foo')
        assert await r.delete('a') == 1

    @pytest.mark.asyncio(forbid_global_loop=True)
    async def test_delete_with_multiple_keys(self, r):
        await r.set('a', 'foo')
        await r.set('b', 'bar')
        assert await r.delete('a', 'b') == 2
        assert await r.get('a') is None
        assert await r.get('b') is None

    @skip_if_server_version_lt('2.6.0')
    @pytest.mark.asyncio(forbid_global_loop=True)
    async def test_dump_and_restore(self, r):
        await r.flushdb()
        await r.set('a', 'foo')
        dumped = await r.dump('a')
        await r.delete('a')
        await r.restore('a', 0, dumped)
        assert await r.get('a') == b('foo')

    @skip_if_server_version_lt('3.0.0')
    @pytest.mark.asyncio(forbid_global_loop=True)
    async def test_dump_and_restore_and_replace(self, r):
        await r.flushdb()
        await r.set('a', 'bar')
        dumped = await r.dump('a')

# 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: aredis/exceptions.py
# class RedisError(Exception):
#     pass
# 
# class ResponseError(RedisError):
#     pass
# 
# class DataError(RedisError):
#     pass
# 
# Path: tests/client/conftest.py
# def skip_if_server_version_lt(min_version):
#     loop = asyncio.get_event_loop()
#     version = StrictVersion(loop.run_until_complete(get_version()))
#     check = version < StrictVersion(min_version)
#     return pytest.mark.skipif(check, reason="")
# 
# def skip_python_vsersion_lt(min_version):
#     min_version = tuple(map(int, min_version.split('.')))
#     check = sys.version_info[:2] < min_version
#     return pytest.mark.skipif(check, reason="")


# Path: tests/client/test_commands.py
import binascii
import datetime
import pytest
import aredis
import time
from string import ascii_letters
from aredis.utils import (b, iteritems,
                          iterkeys, itervalues)
from aredis.commands.server import parse_info
from aredis.exceptions import (RedisError,
                               ResponseError,
                               DataError)
from .conftest import (skip_if_server_version_lt,
                       skip_python_vsersion_lt)

    async def test_delete(self, r):
        await r.flushdb()
        assert await r.delete('a') == 0
        await r.set('a', 'foo')
        assert await r.delete('a') == 1

    @pytest.mark.asyncio(forbid_global_loop=True)
    async def test_delete_with_multiple_keys(self, r):
        await r.set('a', 'foo')
        await r.set('b', 'bar')
        assert await r.delete('a', 'b') == 2
        assert await r.get('a') is None
        assert await r.get('b') is None

    @skip_if_server_version_lt('2.6.0')
    @pytest.mark.asyncio(forbid_global_loop=True)
    async def test_dump_and_restore(self, r):
        await r.flushdb()
        await r.set('a', 'foo')
        dumped = await r.dump('a')
        await r.delete('a')
        await r.restore('a', 0, dumped)
        assert await r.get('a') == b('foo')

    @skip_if_server_version_lt('3.0.0')
    @pytest.mark.asyncio(forbid_global_loop=True)
    async def test_dump_and_restore_and_replace(self, r):
        await r.flushdb()
        await r.set('a', 'bar')
        dumped = await r.dump('a')

        with pytest.raises(ResponseError):