How to delete object redis list item?

Member

by lottie , in category: Third Party Scripts , a year ago

How to delete object redis list item?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by hal.littel , a year 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.

Related Threads:

How to delete from redis list faster then o(n)?
How to use knockout.js to add one item or delete an item by clicking?
How to remove selected item from a list in d3.js?
How to remove padding of list item in vuetify?
How to delete an item from the cart in shopify?
How to delete item from session in laravel?