1515from newrelic .api .datastore_trace import DatastoreTrace
1616from newrelic .api .time_trace import current_trace
1717from newrelic .api .transaction import current_transaction
18- from newrelic .common .object_wrapper import wrap_function_wrapper , function_wrapper
18+ from newrelic .common .object_wrapper import function_wrapper , wrap_function_wrapper
19+ from newrelic .common .package_version_utils import get_package_version_tuple
1920from newrelic .hooks .datastore_redis import (
2021 _redis_client_methods ,
2122 _redis_multipart_commands ,
2223 _redis_operation_re ,
2324)
24- from newrelic .common .package_version_utils import get_package_version_tuple
2525
2626
2727def _conn_attrs_to_dict (connection ):
@@ -39,14 +39,13 @@ def _conn_attrs_to_dict(connection):
3939
4040def _instance_info (kwargs ):
4141 host = kwargs .get ("host" ) or "localhost"
42- port_path_or_id = str (kwargs .get ("port " ) or kwargs .get ("path " , 6379 ))
42+ port_path_or_id = str (kwargs .get ("path " ) or kwargs .get ("port " , 6379 ))
4343 db = str (kwargs .get ("db" ) or 0 )
4444
4545 return (host , port_path_or_id , db )
4646
4747
4848def _wrap_AioRedis_method_wrapper (module , instance_class_name , operation ):
49-
5049 @function_wrapper
5150 async def _nr_wrapper_AioRedis_async_method_ (wrapped , instance , args , kwargs ):
5251 transaction = current_transaction ()
@@ -55,7 +54,7 @@ async def _nr_wrapper_AioRedis_async_method_(wrapped, instance, args, kwargs):
5554
5655 with DatastoreTrace (product = "Redis" , target = None , operation = operation ):
5756 return await wrapped (* args , ** kwargs )
58-
57+
5958 def _nr_wrapper_AioRedis_method_ (wrapped , instance , args , kwargs ):
6059 # Check for transaction and return early if found.
6160 # Method will return synchronously without executing,
@@ -64,6 +63,7 @@ def _nr_wrapper_AioRedis_method_(wrapped, instance, args, kwargs):
6463 if aioredis_version and aioredis_version < (2 ,):
6564 # AioRedis v1 uses a RedisBuffer instead of a real connection for queueing up pipeline commands
6665 from aioredis .commands .transaction import _RedisBuffer
66+
6767 if isinstance (instance ._pool_or_conn , _RedisBuffer ):
6868 # Method will return synchronously without executing,
6969 # it will be added to the command stack and run later.
@@ -80,7 +80,6 @@ def _nr_wrapper_AioRedis_method_(wrapped, instance, args, kwargs):
8080 # Method should be run when awaited, therefore we wrap in an async wrapper.
8181 return _nr_wrapper_AioRedis_async_method_ (wrapped )(* args , ** kwargs )
8282
83-
8483 name = "%s.%s" % (instance_class_name , operation )
8584 wrap_function_wrapper (module , name , _nr_wrapper_AioRedis_method_ )
8685
@@ -109,7 +108,9 @@ async def wrap_Connection_send_command(wrapped, instance, args, kwargs):
109108 # If it's not a multi part command, there's no need to trace it, so
110109 # we can return early.
111110
112- if operation .split ()[0 ] not in _redis_multipart_commands : # Set the datastore info on the DatastoreTrace containing this function call.
111+ if (
112+ operation .split ()[0 ] not in _redis_multipart_commands
113+ ): # Set the datastore info on the DatastoreTrace containing this function call.
113114 trace = current_trace ()
114115
115116 # Find DatastoreTrace no matter how many other traces are inbetween
@@ -161,7 +162,9 @@ def wrap_RedisConnection_execute(wrapped, instance, args, kwargs):
161162 # If it's not a multi part command, there's no need to trace it, so
162163 # we can return early.
163164
164- if operation .split ()[0 ] not in _redis_multipart_commands : # Set the datastore info on the DatastoreTrace containing this function call.
165+ if (
166+ operation .split ()[0 ] not in _redis_multipart_commands
167+ ): # Set the datastore info on the DatastoreTrace containing this function call.
165168 trace = current_trace ()
166169
167170 # Find DatastoreTrace no matter how many other traces are inbetween
0 commit comments