12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
- from newrelic .api .datastore_trace import DatastoreTrace , DatastoreTraceWrapper
15
+ from newrelic .api .datastore_trace import DatastoreTrace
16
16
from newrelic .api .time_trace import current_trace
17
17
from newrelic .api .transaction import current_transaction
18
- from newrelic .common .object_wrapper import wrap_function_wrapper , function_wrapper , FunctionWrapper
18
+ from newrelic .common .object_wrapper import wrap_function_wrapper , function_wrapper
19
19
from newrelic .hooks .datastore_redis import (
20
20
_redis_client_methods ,
21
21
_redis_multipart_commands ,
22
22
_redis_operation_re ,
23
23
)
24
24
25
- from newrelic .common .async_wrapper import async_wrapper
26
25
27
- import aioredis
28
-
29
- try :
30
- AIOREDIS_VERSION = lambda : tuple (int (x ) for x in getattr (aioredis , "__version__" ).split ("." ))
31
- except Exception :
32
- AIOREDIS_VERSION = lambda : (0 , 0 , 0 )
26
+ def get_aioredis_version ():
27
+ try :
28
+ import aioredis as aioredis_legacy
29
+ except ModuleNotFoundError :
30
+ return None
31
+ try :
32
+ return tuple (int (x ) for x in getattr (aioredis_legacy , "__version__" ).split ("." ))
33
+ except Exception :
34
+ return 0 , 0 , 0
33
35
34
36
35
37
def _conn_attrs_to_dict (connection ):
@@ -68,7 +70,8 @@ def _nr_wrapper_AioRedis_method_(wrapped, instance, args, kwargs):
68
70
# Check for transaction and return early if found.
69
71
# Method will return synchronously without executing,
70
72
# it will be added to the command stack and run later.
71
- if AIOREDIS_VERSION () < (2 ,):
73
+ aioredis_version = get_aioredis_version ()
74
+ if aioredis_version and aioredis_version < (2 ,):
72
75
# AioRedis v1 uses a RedisBuffer instead of a real connection for queueing up pipeline commands
73
76
from aioredis .commands .transaction import _RedisBuffer
74
77
if isinstance (instance ._pool_or_conn , _RedisBuffer ):
@@ -77,7 +80,10 @@ def _nr_wrapper_AioRedis_method_(wrapped, instance, args, kwargs):
77
80
return wrapped (* args , ** kwargs )
78
81
else :
79
82
# AioRedis v2 uses a Pipeline object for a client and internally queues up pipeline commands
80
- from aioredis .client import Pipeline
83
+ if aioredis_version :
84
+ from aioredis .client import Pipeline
85
+ else :
86
+ from redis .asyncio .client import Pipeline
81
87
if isinstance (instance , Pipeline ):
82
88
return wrapped (* args , ** kwargs )
83
89
0 commit comments