Redis
1.Connect to redis.
static void RedisDemo() { using (var redis = ConnectionMultiplexer.Connect("localhost")) { IDatabase db = redis.GetDatabase(2); for(int i=0;i<100000;i++) { string redisKey = Guid.NewGuid().ToString(); db.StringSet(redisKey, redisKey); } } }
2.StackExchange.Redis.RedisCommandException: 'This operation is not available unless admin mode is enabled: FLUSHDB'
ConnectionMultiplexer redis= ConnectionMultiplexer.Connect("localhost,allowAdmin=true")
3.Flush redis DB.
//dbIndex is between 0 and 15 static void FlushRedisDbs(int dbIndex) { using(ConnectionMultiplexer redis= ConnectionMultiplexer.Connect("localhost,allowAdmin=true")) { var server = redis.GetServer("localhost:6379"); server.FlushDatabase(dbIndex); } }