remove element from list by it index

5,128 views
Skip to first unread message

tantra

unread,
Feb 18, 2010, 4:35:51 AM2/18/10
to Redis DB
Hello

Is it possible to remove element from list by it index? I read manual
and does't find such command. Is it possible to add this feature?

Demis Bellot

unread,
Feb 18, 2010, 4:47:56 AM2/18/10
to redi...@googlegroups.com
Not really there are some comments about this at the end of this page:

I'm doing a really lam0 hack using whats available by replacing the element at index (LSET) with a UUID/GUID then LREM the UUID/GUID by value.

- Demis


--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To post to this group, send email to redi...@googlegroups.com.
To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.


Salvatore Sanfilippo

unread,
Feb 18, 2010, 9:56:50 AM2/18/10
to redi...@googlegroups.com
On Thu, Feb 18, 2010 at 10:47 AM, Demis Bellot <demis....@gmail.com> wrote:
> Not really there are some comments about this at the end of this page:
> http://code.google.com/p/redis/wiki/LremCommand
> I'm doing a really lam0 hack using whats available by replacing the element
> at index (LSET) with a UUID/GUID then LREM the UUID/GUID by value.
> - Demis

Actually it's not a bad trick at all... in the general form this could
be something like to LSETting to an "invalid" element, like
"__deleted__", and then calling LREM against it.

The reason there there isn't a remove by index operation is that it
does not play well with Redis atomic operations. There is no way
without an explicit lock to use it in a safe way.

Cheers,
Salvatore

--
Salvatore 'antirez' Sanfilippo
http://invece.org

"Once you have something that grows faster than education grows,
you’re always going to get a pop culture.", Alan Kay

Reply all
Reply to author
Forward
0 new messages