示例#1
0
def test_strict_redis_connection_instance_info(args, kwargs, expected):
    r = redis.StrictRedis(*args, **kwargs)
    r.connection_pool.connection_class = DisabledConnection
    connection = r.connection_pool.get_connection('SELECT')
    try:
        conn_kwargs = _conn_attrs_to_dict(connection)
        assert _instance_info(conn_kwargs) == expected
    finally:
        r.connection_pool.release(connection)
示例#2
0
def test_strict_redis_connection_from_url(args, kwargs, expected):
    r = aredis.StrictRedis.from_url(*args, **kwargs)
    if r.connection_pool.connection_class is aredis.Connection:
        r.connection_pool.connection_class = DisabledConnection
    elif r.connection_pool.connection_class is aredis.UnixDomainSocketConnection:
        r.connection_pool.connection_class = DisabledUnixConnection
    else:
        assert False, r.connection_pool.connection_class
    connection = r.connection_pool.get_connection("SELECT")
    try:
        conn_kwargs = _conn_attrs_to_dict(connection)
        assert _instance_info(conn_kwargs) == expected
    finally:
        r.connection_pool.release(connection)
async def _nr_Connection_send_command_wrapper_(wrapped, instance, args,
                                               kwargs):
    transaction = current_transaction()
    if not transaction:
        return await wrapped(*args, **kwargs)

    host, port_path_or_id, db = (None, None, None)

    try:
        dt = transaction.settings.datastore_tracer
        if dt.instance_reporting.enabled or dt.database_name_reporting.enabled:
            conn_kwargs = _conn_attrs_to_dict(instance)
            host, port_path_or_id, db = _instance_info(conn_kwargs)
    except Exception:
        pass

    transaction._nr_datastore_instance_info = (host, port_path_or_id, db)

    # Older Redis clients would when sending multi part commands pass
    # them in as separate arguments to send_command(). Need to therefore
    # detect those and grab the next argument from the set of arguments.

    operation = args[0].strip().lower()

    # If it's not a multi part command, there's no need to trace it, so
    # we can return early.

    if operation.split()[0] not in _redis_multipart_commands:
        return await wrapped(*args, **kwargs)

    # Convert multi args to single arg string

    if operation in _redis_multipart_commands and len(args) > 1:
        operation = "%s %s" % (operation, args[1].strip().lower())

    operation = _redis_operation_re.sub("_", operation)

    with DatastoreTrace(product="Redis",
                        target=None,
                        operation=operation,
                        host=host,
                        port_path_or_id=port_path_or_id,
                        database_name=db):
        return await wrapped(*args, **kwargs)