Remove item at specific index from redis list

Is it possible to delete an item at a specific index in a redis list? In fact, I do not find what I want. There is a trimmer that allows you to select a specific set of elements, LREM allows you to delete an element in the list by value, but I have no value.

I found a hack in which you use LSET to change the value of an element to a UID or string, for example. "DELETED" and you call LREM on that value. It's just a little dirty.

+4
source share
2 answers

Thus, the only way to accomplish what I wanted is to set the value in the index to a predefined row, and then delete by value.

. https://groups.google.com/forum/#!topic/redis-db/c-IpJ0YWa9I

@redis.lset("#{@namespace}/#{specified_queue}", index, "DELETED")
@redis.lrem("#{@namespace}/#{specified_queue}", 1, "DELETED")

LSET docs http://redis.io/commands/lset LREM docs http://redis.io/commands/lrem

+6

, redis-cli.

INDEX=<index (starts at 0)>
redis-cli -h <host> -p <port> LREM <list name> 1 "$(redis-cli -h <host> -p <port> LINDEX <list name> $INDEX)"

LINDEX , LREM .

+1

Source: https://habr.com/ru/post/1599234/


All Articles