List is very common data structure, there are some very frequent method of list in programming languages. append, pop, remove, get value by index, lookup index by value, etc.
Redis implement most of these common command, but redis missing a very import command: lookup index by value.
I know LINDEXOF command is an O(N) algorithm, but redis LREM command is also an O(N) algorithm, it is not about algorithms complexity, it is really very useful command.
Some feature will be very easy to implement with LIST, and many time we use very small LIST.
Comment From: mattsta
Also see https://github.com/antirez/redis/issues/746
Comment From: antirez
Hello, the reason why Redis lacks LINDEXOF (better name is LSEARCH probably) is not because is O(N). There are certain good uses for O(N) commands that operate on lists, like for example applying them in small lists or when you have very high probabilities that your element will be towards the first elements. The reason is instead that in a mutable data structure with concurrent clients, returning an index is a poor API. What you do with the index later? If the list gets a push or pop the index is no longer valid.
So IMHO we should start re-checking what is missing for your use case by checking what your use case is. Please could you tell what you are trying to accomplish with LINDEXOF? Thanks.
Comment From: guileen
Hi @antirez , I am lack to response this issue.
My use case is something like a queue system, features like push the item into the queue if it is not in the queue. Finally I implement this system by list with LREM and RPUSH, but it change the raw position of that item.
But, there is still one feature I can't implement, I want to check if an item is in the queue, and if it is in the queue, show the queue index of that item.
Think about that each item is a user, and users want to know what the position they are in the queue. To do that, I have to use a SortedSet with the score of timestamp instead of List.
And, there is another use case, think about a crawler bot. I use BFS method, I give it a start url to parse all url in an that html, and push all parsed url to a queue, and pop the first url and reapeat this progress again. When I push all url to that queue, I have to check if it is in that queue first, and I don't want to change the raw index of that url, it will change the priority of that url.
Comment From: itamarhaber
I have to use a SortedSet with the score of timestamp instead of List
Exactly - use the right data structure for the problem.
When I push all url to that queue, I have to check if it is in that queue first
Indeed, so keep a regular Set just for membership tests before pushing into the queue.
Comment From: itamarhaber
FYIs: This was added in v6.0.6 as LPOS.