A
A
Alexander2017-12-22 19:55:07
PHP
Alexander, 2017-12-22 19:55:07

How to remove list from redis?

Good day, the following problem arose:
There is a chat, Redis is used to store messages, each message is written to 'list'.
Message example:

{
  "id": "fafe1b60c24107ccd8f4562213e44849",
  "userid": "1",
  "avatar": "img url",
  "time": "19:19",
  "messages": "any text",
  "username": "User1",
}

*id is always unique.
The question itself is how to delete a given message from redis knowing its id ?
Using lrem to delete the message does not work, because. lrem removes by exact match the entire array of data.
For example code:
$id = "fafe1b60c24107ccd8f4562213e44849";
$this->redis->lrem(self::CHAT_CHANNEL, 0, $id);

Doesn't remove anything.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
RidgeA, 2017-12-22
@RidgeA

https://redis.io/commands/lrem

P
Puma Thailand, 2018-01-03
@opium

And why not delete by key?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question