Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove element from list in Redis by value?

How to remove element from list in Redis by value?

For exmaple, I have:

127.0.0.1:6379> lrange POST:544 0 -1
1) "1"
2) "2"
3) "36"
127.0.0.1:6379> 

I know only value 36, not index. Can I remove element from list by value?

like image 551
Faud Avatar asked May 31 '15 21:05

Faud


2 Answers

http://redis.io/commands/lrem

Lrem is what you are looking for. use LREM POST:544 1 36.

like image 122
Karthikeyan Gopall Avatar answered Nov 09 '22 14:11

Karthikeyan Gopall


If the list contains strings then you may enclose it with double quotes then it works!

eg: sampleList ["one", "two", "three", "four"] If you want to remove "three" then use:

LREM sampleList 1 "three"
like image 20
prince_29 Avatar answered Nov 09 '22 12:11

prince_29