2

I have a list container the current players for a game, and I keep track of the current turn with another integer. When a player leaves, I remove them from the players list. However, there are cases where I need to also adjust the turn value (when a player leaves).

I've found that if the index of a particular player is LESS than the turn value, then I need to decrement the turn variable. For example

1) A B C(t=2) D E => B leaves
2) A C(t=1) D E

Since B's index was before turn, turn is decremented. Conversely

1) A B C(t=2) D E => D leaves
2) A B C(t=2) E

Here, we do not have to change the turn value, since the player that left is AFTER turn.

So my question is, how can I determine the index of a particular string in a list? (non-blocking). If this is not possible, is there maybe another solution?

Jordan Scales
  • 2,687
  • 4
  • 28
  • 37
  • Possible duplicate? http://stackoverflow.com/questions/8899111/get-the-index-of-an-item-by-value-in-a-redis-list – jwatts1980 Jul 21 '12 at 22:42

1 Answers1

0

There is no way to do it with non-blocking algorithm. You have to traverse a list with first item to the turn'th item.

Because, you cannot reach any item with its value in such a list, there is only way I can see for now.

totten
  • 2,769
  • 3
  • 27
  • 41