@@ -53,13 +53,17 @@ def delete_all(self) -> None:
5353class HashMigrator :
5454 MINIMUM_ALLOWED_REDIS_SERVER = semver .Version (major = 7 , minor = 4 , patch = 0 )
5555 NEW_HASH_PREFIX = "migrated/"
56+ _version_checked : bool = False
5657
5758 def __init__ (self , hash_name : str , client : redis .Redis ):
5859 self .hash_name = hash_name
5960 self .zset_name = f"{ hash_name } .EXPIREAT"
6061 self .client = client
6162
6263 def check_redis_server_version (self ) -> None :
64+ if HashMigrator ._version_checked :
65+ return
66+
6367 # Require Redis 7.4+ for per-field TTL commands
6468 redis_version_str = self .client .info (section = "server" )["redis_version" ]
6569 server_version = semver .Version .parse (version = redis_version_str )
@@ -72,6 +76,8 @@ def check_redis_server_version(self) -> None:
7276 f"less then { self .MINIMUM_ALLOWED_REDIS_SERVER } -> "
7377 f"incompatible with used python SDK version `{ version ('corva-sdk' )} `" )
7478
79+ HashMigrator ._version_checked = True
80+
7581 def run (self ) -> bool :
7682 """Prepare parallel new-style cache while keeping legacy structures.
7783
@@ -91,16 +97,16 @@ def run(self) -> bool:
9197
9298 from corva import Logger
9399
94- # Legacy structure must exist; otherwise nothing to do
95- if not self .client .exists (self .zset_name ):
96- return False
97-
98100 new_hash_name = self .NEW_HASH_PREFIX + self .hash_name
99101
100102 # If new hash already exists, consider migration already done
101103 if self .client .exists (new_hash_name ):
102104 return False
103105
106+ # Legacy structure must exist; otherwise nothing to do
107+ if not self .client .exists (self .zset_name ):
108+ return False
109+
104110 # Current server time in ms
105111 sec , micro = self .client .time ()
106112 now_ms = int (sec ) * 1000 + int (micro ) // 1000
0 commit comments