RedisServerEvents calls FlushDb on reset

This code seems wrong. If RedisServerEvents is using the same redis DB as the rest of the app, calling the Reset method will clear out the entire DB. :confounded:

Should this code not be changed to:

var ids = redis.GetAllItemsFromSortedSet(RedisIndex.ActiveSubscriptionsSet);

using (var tran = redis.CreateTransaction())
{
	foreach (var id in ids)
	{
		tran.QueueCommand(r => r.Remove(RedisIndex.Subscription.Fmt(id)));
	}

	tran.QueueCommand(r => r.Remove(RedisIndex.ActiveSubscriptionsSet));    
	tran.QueueCommand(r => r.Remove(RedisIndex.ChannelSet));
	tran.QueueCommand(r => r.Remove(RedisIndex.UserIdSet));
	tran.QueueCommand(r => r.Remove(RedisIndex.UserNameSet));
	tran.QueueCommand(r => r.Remove(RedisIndex.SessionSet));

	tran.Commit();
}

Reset() isn’t used internally, but it’s an API that can be used to reset the Redis DB back to its initial state.

Unfortunately using redis.FlushDb() is cleanest approach, and your example wont work. You would need to delete every ChannelSet, UserSet, UserNameSet and SessionSet which is a different set per entry.

Anyway I’ve updated it with a more conservative impl in this commit:

local.Reset();
using (var redis = clientsManager.GetClient())
{
    var keysToDelete = new List<string> { RedisIndex.ActiveSubscriptionsSet };

    keysToDelete.AddRange(redis.SearchKeys(RedisIndex.Subscription.Replace("{0}", "*")));
    keysToDelete.AddRange(redis.SearchKeys(RedisIndex.ChannelSet.Replace("{0}", "*")));
    keysToDelete.AddRange(redis.SearchKeys(RedisIndex.UserIdSet.Replace("{0}", "*")));
    keysToDelete.AddRange(redis.SearchKeys(RedisIndex.UserNameSet.Replace("{0}", "*")));
    keysToDelete.AddRange(redis.SearchKeys(RedisIndex.SessionSet.Replace("{0}", "*")));
    redis.RemoveAll(keysToDelete);
}