S
S
Sergey Zolotarev2022-01-27 11:25:52
Yii
Sergey Zolotarev, 2022-01-27 11:25:52

How to execute a lrem Redis command removing the requested value from a specific list without an index and a for loop?

Good day!

I recently ran into a problem with executing the yii2-redis library's executeCommand command in my project.

Essence of the question:
VDvttyE.png

An error was detected when testing a certain solution from the server side in the client side of the project!

The problem is running the lrem Redis command to remove the value requested by the client from the list I have prepared. As far as I know, lrem removes the value along with the index from the list.

Problem code example:

$al = Yii::$app->redis->executeCommand('lrange', [$key, -100, 100]);
                        
for($i = 0; $i < $al; $i++){
  if($attributeId == $al[$i]){ 
    $delR = Yii::$app->redis->executeCommand('lrem', [$key, $i, $attributeId]);
                
    $hive[0]->name = $attributeId;

    if($delR && $hive[0]->save()){ $serviceResponse[] = 'New attribute table created!'; }
    else{
      \Yii::$app->response->statusCode = 502;
      $serviceResponse[] = 'Services gateway!';
    }
  }
}


Notes on code example:

  • $attributeId is a request with a value to remove it from the Redis list. Ready data attribute without filters;
  • $key is the key on which the Redis list itself operates;
  • $hive[0] - this is where the Yii data model object is located, responsible for storing only attributes. The object methods are executed after adding the first filter and before adding a new empty field to enter a new filter in Realtime.



How to fix this query execution error? Is it possible to access lrem in Redis in the same way as DELETE in SQL, without taking into account the numeric index and without using a for loop? Thank you in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question