@@ -148,12 +148,7 @@ def response_hook(span, instance, response):
148148_DEFAULT_SERVICE = "valkey"
149149
150150
151- _VALKEY_ASYNCIO_VERSION = (4 , 2 , 0 )
152- if valkey .VERSION >= _VALKEY_ASYNCIO_VERSION :
153- import valkey .asyncio
154-
155- _VALKEY_CLUSTER_VERSION = (4 , 1 , 0 )
156- _VALKEY_ASYNCIO_CLUSTER_VERSION = (4 , 3 , 2 )
151+ import valkey .asyncio
157152
158153_FIELD_TYPES = ["NUMERIC" , "TEXT" , "GEO" , "TAG" , "VECTOR" ]
159154
@@ -338,10 +333,8 @@ def _add_search_attributes(span: Span, response, args):
338333 document [attribute_name_index + 1 ],
339334 )
340335
341- pipeline_class = (
342- "BasePipeline" if valkey .VERSION < (3 , 0 , 0 ) else "Pipeline"
343- )
344- valkey_class = "StrictValkey" if valkey .VERSION < (3 , 0 , 0 ) else "Valkey"
336+ pipeline_class = "Pipeline"
337+ valkey_class = "Valkey"
345338
346339 wrap_function_wrapper (
347340 "valkey" , f"{ valkey_class } .execute_command" , _traced_execute_command
@@ -356,17 +349,16 @@ def _add_search_attributes(span: Span, response, args):
356349 f"{ pipeline_class } .immediate_execute_command" ,
357350 _traced_execute_command ,
358351 )
359- if valkey .VERSION >= _VALKEY_CLUSTER_VERSION :
360- wrap_function_wrapper (
361- "valkey.cluster" ,
362- "ValkeyCluster.execute_command" ,
363- _traced_execute_command ,
364- )
365- wrap_function_wrapper (
366- "valkey.cluster" ,
367- "ClusterPipeline.execute" ,
368- _traced_execute_pipeline ,
369- )
352+ wrap_function_wrapper (
353+ "valkey.cluster" ,
354+ "ValkeyCluster.execute_command" ,
355+ _traced_execute_command ,
356+ )
357+ wrap_function_wrapper (
358+ "valkey.cluster" ,
359+ "ClusterPipeline.execute" ,
360+ _traced_execute_pipeline ,
361+ )
370362
371363 async def _async_traced_execute_command (
372364 func : Callable [..., Awaitable [R ]],
@@ -430,33 +422,31 @@ async def _async_traced_execute_pipeline(
430422
431423 return response
432424
433- if valkey .VERSION >= _VALKEY_ASYNCIO_VERSION :
434- wrap_function_wrapper (
435- "valkey.asyncio" ,
436- f"{ valkey_class } .execute_command" ,
437- _async_traced_execute_command ,
438- )
439- wrap_function_wrapper (
440- "valkey.asyncio.client" ,
441- f"{ pipeline_class } .execute" ,
442- _async_traced_execute_pipeline ,
443- )
444- wrap_function_wrapper (
445- "valkey.asyncio.client" ,
446- f"{ pipeline_class } .immediate_execute_command" ,
447- _async_traced_execute_command ,
448- )
449- if valkey .VERSION >= _VALKEY_ASYNCIO_CLUSTER_VERSION :
450- wrap_function_wrapper (
451- "valkey.asyncio.cluster" ,
452- "ValkeyCluster.execute_command" ,
453- _async_traced_execute_command ,
454- )
455- wrap_function_wrapper (
456- "valkey.asyncio.cluster" ,
457- "ClusterPipeline.execute" ,
458- _async_traced_execute_pipeline ,
459- )
425+ wrap_function_wrapper (
426+ "valkey.asyncio" ,
427+ f"{ valkey_class } .execute_command" ,
428+ _async_traced_execute_command ,
429+ )
430+ wrap_function_wrapper (
431+ "valkey.asyncio.client" ,
432+ f"{ pipeline_class } .execute" ,
433+ _async_traced_execute_pipeline ,
434+ )
435+ wrap_function_wrapper (
436+ "valkey.asyncio.client" ,
437+ f"{ pipeline_class } .immediate_execute_command" ,
438+ _async_traced_execute_command ,
439+ )
440+ wrap_function_wrapper (
441+ "valkey.asyncio.cluster" ,
442+ "ValkeyCluster.execute_command" ,
443+ _async_traced_execute_command ,
444+ )
445+ wrap_function_wrapper (
446+ "valkey.asyncio.cluster" ,
447+ "ClusterPipeline.execute" ,
448+ _async_traced_execute_pipeline ,
449+ )
460450
461451
462452class ValkeyInstrumentor (BaseInstrumentor ):
@@ -491,31 +481,15 @@ def _instrument(self, **kwargs: Any):
491481 )
492482
493483 def _uninstrument (self , ** kwargs : Any ):
494- if valkey .VERSION < (3 , 0 , 0 ):
495- unwrap (valkey .StrictValkey , "execute_command" )
496- unwrap (valkey .StrictValkey , "pipeline" )
497- unwrap (valkey .Valkey , "pipeline" )
498- unwrap (
499- valkey .client .BasePipeline , # pylint:disable=no-member
500- "execute" ,
501- )
502- unwrap (
503- valkey .client .BasePipeline , # pylint:disable=no-member
504- "immediate_execute_command" ,
505- )
506- else :
507- unwrap (valkey .Valkey , "execute_command" )
508- unwrap (valkey .Valkey , "pipeline" )
509- unwrap (valkey .client .Pipeline , "execute" )
510- unwrap (valkey .client .Pipeline , "immediate_execute_command" )
511- if valkey .VERSION >= _VALKEY_CLUSTER_VERSION :
512- unwrap (valkey .cluster .ValkeyCluster , "execute_command" )
513- unwrap (valkey .cluster .ClusterPipeline , "execute" )
514- if valkey .VERSION >= _VALKEY_ASYNCIO_VERSION :
515- unwrap (valkey .asyncio .Valkey , "execute_command" )
516- unwrap (valkey .asyncio .Valkey , "pipeline" )
517- unwrap (valkey .asyncio .client .Pipeline , "execute" )
518- unwrap (valkey .asyncio .client .Pipeline , "immediate_execute_command" )
519- if valkey .VERSION >= _VALKEY_ASYNCIO_CLUSTER_VERSION :
520- unwrap (valkey .asyncio .cluster .ValkeyCluster , "execute_command" )
521- unwrap (valkey .asyncio .cluster .ClusterPipeline , "execute" )
484+ unwrap (valkey .Valkey , "execute_command" )
485+ unwrap (valkey .Valkey , "pipeline" )
486+ unwrap (valkey .client .Pipeline , "execute" )
487+ unwrap (valkey .client .Pipeline , "immediate_execute_command" )
488+ unwrap (valkey .cluster .ValkeyCluster , "execute_command" )
489+ unwrap (valkey .cluster .ClusterPipeline , "execute" )
490+ unwrap (valkey .asyncio .Valkey , "execute_command" )
491+ unwrap (valkey .asyncio .Valkey , "pipeline" )
492+ unwrap (valkey .asyncio .client .Pipeline , "execute" )
493+ unwrap (valkey .asyncio .client .Pipeline , "immediate_execute_command" )
494+ unwrap (valkey .asyncio .cluster .ValkeyCluster , "execute_command" )
495+ unwrap (valkey .asyncio .cluster .ClusterPipeline , "execute" )
0 commit comments