How to delete object redis list item?

Member

by lottie , in category: Third Party Scripts , 5 months ago

How to delete object redis list item?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by hal.littel , 5 months ago

@lottie 

To delete an object from a Redis list, you can use the LREM command. Here is how you can do it:

  1. Connect to your Redis server using the redis-cli command line tool or your preferred Redis client.
  2. Use the following command to delete a specific value from the list:
1
LREM key count value


  • key: the key of the list you want to remove the object from
  • count: the number of occurrences of the value you want to remove. Use 0 to remove all occurrences.
  • value: the value you want to remove from the list


For example, if you have a list named "mylist" with the following values: "a", "b", "c", "b", and you want to remove all occurrences of "b" from the list:

1
LREM mylist 0 b


  1. The LREM command will return the number of elements removed from the list. If the value was found and removed, the return value will be a positive integer, otherwise, it will be 0.


That's it! The specified value will be removed from the list in Redis.