php - Remove nth element from redis's list in thread safe way -



php - Remove nth element from redis's list in thread safe way -

in cron job, wish remove nth element redis's list, in thread safe way during iteration.

is possible? may know how can so?

i'm looking thread safe way. there author process, perform write operation same list time-to-time.

while (true) { // elements "mylist" list. $list = $redis->lrange("mylist", 0, -1); // iterate through "mylist" list. ($n = 0; $n < count($list); ++$n) { if ($list[$n] == "dummy") { // wish remove nth element (with "dummy" value) "mylist" // in thread safe fashion. how? } } }

thread safe of import such next situation won't happen

cron job find out "dummy" element 5th element, , prepare remove it. writer process inserting additional element head of list, pushes "dummy" element 6th position. cron job removed 5th element list, no longer "dummy" element anymore!

in java, solve reader/writer problem using copy on write (through copyonwritearraylist). but, how in php & redis?

use lrem this:

lrem mylist 0 "dummy" ^ ^ ^ | | |- `value` delete | |------ remove elements equal `value`. |---------- list key name

you may utilize count (0 in sample above) moving head tail (or tail head).

php multithreading redis

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -