note 90864 added to function.memcache-increment

From: Date: Wed, 13 May 2009 13:34:21 +0000
Subject: note 90864 added to function.memcache-increment
Groups: php.notes 
Request: Send a blank email to php-notes+get-154552@lists.php.net to get a copy of this message
Instead of checking the value before incrementing, you can simply ADD it instead before incrementing each time. If it's already there, your ADD is ignored, and if it's not there, it's set. If you add($memcacheKey, 0) and then increment($memcacheKey, 1) in that order, you avoid all possible race conditions. If two threads are running this code concurrently, you will always end up with your value being 2 no matter which order the threads execute in. ---- Server IP: 64.71.164.2 Probable Submitter: 209.251.128.198 ---- Manual Page -- http://www.php.net/manual/en/function.memcache-increment.php Edit -- https://master.php.net/note/edit/90864 Del: integrated -- https://master.php.net/note/delete/90864/integrated Del: useless -- https://master.php.net/note/delete/90864/useless Del: bad code -- https://master.php.net/note/delete/90864/bad+code Del: spam -- https://master.php.net/note/delete/90864/spam Del: non-english -- https://master.php.net/note/delete/90864/non-english Del: in docs -- https://master.php.net/note/delete/90864/in+docs Del: other reasons-- https://master.php.net/note/delete/90864 Reject -- https://master.php.net/note/reject/90864 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#154552) next »