RemoveAllFromList() does not always empty the list

I’ve discovered a bug in RedisClient.RemoveAllFromList("listid") that it does not empty a list in the special case that the list has one item in it. It turns out that if there is only one item in the list, then that item remains.

Apparently, this is a known issue and talked about in places like this: https://stackoverflow.com/questions/9828160/delete-all-entries-in-a-redis-list

From the perspective of a consumer of RedisClient, when calling RedisClient.RemoveAllFromList("listid") you would expect the list to be emptied, so perhaps dealing with the special case is the responsibility of RedisClient rather then the consumer’s issue.

Suggested fixes include:

  1. call LTRIM listid 1 0 where the startindex is greater than the end index. 1 and 0 work great here to empty the whole list
  2. call LTRIM listid -1 0 (as is hte case now), and then delete either the last item, or delete the key of the list
  3. Just delete the key of the list DEL listid

I’m not expert in redis, so I cannot judge the best solution here. (hence why no PR). I’d need a redis expert to decide what the best resolution would be.

The client retains the same behavior in Redis, you’d need to delete the key for lists that have more than 1 element:

client.Remove("list"); //alias for: client.Del("list");