@@ -518,18 +518,36 @@ def delete_multi(self, keys, time=None, key_prefix='', noreply=False):
518
518
rc = 0
519
519
return rc
520
520
521
- def delete (self , key , time = None , noreply = False ):
521
+ def delete (self , key , noreply = False ):
522
522
'''Deletes a key from the memcache.
523
523
524
524
@return: Nonzero on success.
525
- @param time: number of seconds any subsequent set / update commands
526
- should fail. Defaults to None for no delay.
527
525
@param noreply: optional parameter instructs the server to not send the
528
526
reply.
529
527
@rtype: int
530
528
'''
531
- return self ._deletetouch ([b'DELETED' , b'NOT_FOUND' ], "delete" , key ,
532
- time , noreply )
529
+ key = self ._encode_key (key )
530
+ if self .do_check_key :
531
+ self .check_key (key )
532
+ server , key = self ._get_server (key )
533
+ if not server :
534
+ return 0
535
+ self ._statlog ('delete' )
536
+ fullcmd = self ._encode_cmd ('delete' , key , None , noreply )
537
+
538
+ try :
539
+ server .send_cmd (fullcmd )
540
+ if noreply :
541
+ return 1
542
+ line = server .readline ()
543
+ if line and line .strip () in [b'DELETED' , b'NOT_FOUND' ]:
544
+ return 1
545
+ self .debuglog ('delete expected DELETED or NOT_FOUND, got: %r' % (line ,))
546
+ except socket .error as msg :
547
+ if isinstance (msg , tuple ):
548
+ msg = msg [1 ]
549
+ server .mark_dead (msg )
550
+ return 0
533
551
534
552
def touch (self , key , time = 0 , noreply = False ):
535
553
'''Updates the expiration time of a key in memcache.
@@ -544,31 +562,23 @@ def touch(self, key, time=0, noreply=False):
544
562
reply.
545
563
@rtype: int
546
564
'''
547
- return self ._deletetouch ([b'TOUCHED' ], "touch" , key , time , noreply )
548
-
549
- def _deletetouch (self , expected , cmd , key , time = 0 , noreply = False ):
550
565
key = self ._encode_key (key )
551
566
if self .do_check_key :
552
567
self .check_key (key )
553
568
server , key = self ._get_server (key )
554
569
if not server :
555
570
return 0
556
- self ._statlog (cmd )
557
- if time is not None :
558
- headers = str (time )
559
- else :
560
- headers = None
561
- fullcmd = self ._encode_cmd (cmd , key , headers , noreply )
571
+ self ._statlog ('touch' )
572
+ fullcmd = self ._encode_cmd ('touch' , key , str (time ), noreply )
562
573
563
574
try :
564
575
server .send_cmd (fullcmd )
565
576
if noreply :
566
577
return 1
567
578
line = server .readline ()
568
- if line and line .strip () in expected :
579
+ if line and line .strip () in [ b'TOUCHED' ] :
569
580
return 1
570
- self .debuglog ('%s expected %s, got: %r'
571
- % (cmd , b' or ' .join (expected ), line ))
581
+ self .debuglog ('touch expected TOUCHED, got: %r' % (line ,))
572
582
except socket .error as msg :
573
583
if isinstance (msg , tuple ):
574
584
msg = msg [1 ]
0 commit comments