@@ -152,3 +152,42 @@ def test_batch_search_with_real_cluster(redis_cluster_url):
152152
153153 finally :
154154 index .delete ()
155+
156+
157+ @pytest .mark .requires_cluster
158+ @pytest .mark .parametrize ("ttl" , [None , 30 ])
159+ def test_cluster_load_with_ttl (redis_cluster_url , ttl ):
160+ """
161+ Test that TTL is correctly set on keys when using load() with ttl parameter on cluster.
162+ """
163+ schema_dict = {
164+ "index" : {"name" : "test-ttl-cluster" , "prefix" : "ttl" , "storage_type" : "hash" },
165+ "fields" : [
166+ {"name" : "id" , "type" : "tag" },
167+ {"name" : "text" , "type" : "text" },
168+ ],
169+ }
170+
171+ schema = IndexSchema .from_dict (schema_dict )
172+ index = SearchIndex (schema , redis_url = redis_cluster_url )
173+
174+ index .create (overwrite = True )
175+
176+ try :
177+ # Load test data with TTL parameter
178+ data = [{"id" : "1" , "text" : "foo" }]
179+ keys = index .load (data , id_field = "id" , ttl = ttl )
180+
181+ # Check TTL on the loaded key
182+ key_ttl = index .client .ttl (keys [0 ])
183+
184+ if ttl is None :
185+ # No TTL set, should return -1
186+ assert key_ttl == - 1
187+ else :
188+ # TTL should be set and close to the expected value
189+ assert key_ttl > 0
190+ assert abs (key_ttl - ttl ) <= 5
191+
192+ finally :
193+ index .delete ()
0 commit comments