@@ -57,7 +57,7 @@ def createIndex(self, client, num_docs = 100, definition=None):
57
57
TextField ('txt' ),
58
58
NumericField ('chapter' )), definition = definition )
59
59
except redis .ResponseError :
60
- client .drop_index ( )
60
+ client .dropindex ( delete_documents = True )
61
61
return self .createIndex (client , num_docs = num_docs , definition = definition )
62
62
63
63
chapters = {}
@@ -193,7 +193,7 @@ def getCleanClient(self, name):
193
193
"""
194
194
client = Client (name , port = self .server .port )
195
195
try :
196
- client .drop_index ( )
196
+ client .dropindex ( delete_documents = True )
197
197
except :
198
198
pass
199
199
@@ -391,6 +391,25 @@ def testSortby(self):
391
391
self .assertEqual ('doc2' , res2 .docs [1 ].id )
392
392
self .assertEqual ('doc3' , res2 .docs [0 ].id )
393
393
394
+ def testDropIndex (self ):
395
+ """
396
+ Ensure the index gets dropped by data remains by default
397
+ """
398
+ for x in range (20 ):
399
+ conn = self .redis ()
400
+ with conn as r :
401
+ if check_version (r , 20000 ):
402
+ for keep_docs in [[ True , {} ], [ False , {'name' : 'haveit' } ]]:
403
+ idx = "HaveIt"
404
+ index = Client (idx , port = conn .port )
405
+ index .redis .hset ("index:haveit" , mapping = {'name' : 'haveit' })
406
+ idef = IndexDefinition (prefix = ['index:' ])
407
+ index .create_index ((TextField ('name' ),),definition = idef )
408
+ waitForIndex (index .redis , idx )
409
+ index .dropindex (delete_documents = keep_docs [0 ])
410
+ i = index .redis .hgetall ("index:haveit" )
411
+ self .assertEqual (i , keep_docs [1 ])
412
+
394
413
def testExample (self ):
395
414
conn = self .redis ()
396
415
@@ -953,6 +972,5 @@ def testCreateClientDefiniontion(self):
953
972
info = client .info ()
954
973
self .assertEqual (495 , int (info ['num_docs' ]))
955
974
956
-
957
975
if __name__ == '__main__' :
958
976
unittest .main ()
0 commit comments