Commit 5ba566b1 authored by Marc Gravell's avatar Marc Gravell

Provide foreground SAVE support

parent dd3c07ce
...@@ -11,6 +11,7 @@ _ReSharper.* ...@@ -11,6 +11,7 @@ _ReSharper.*
Mono/ Mono/
*.sln.ide *.sln.ide
*.rdb *.rdb
*.aof
*.orig *.orig
redis-cli.exe redis-cli.exe
Redis Configs/*.dat Redis Configs/*.dat
......
...@@ -11,12 +11,17 @@ namespace StackExchange.Redis.Tests.Issues ...@@ -11,12 +11,17 @@ namespace StackExchange.Redis.Tests.Issues
public class BgSaveResponse : TestBase public class BgSaveResponse : TestBase
{ {
[Test] [Test]
public void ShouldntThrowException() #pragma warning disable 0618
[TestCase(SaveType.ForegroundSave)]
#pragma warning restore 0618
[TestCase(SaveType.BackgroundSave)]
[TestCase(SaveType.BackgroundRewriteAppendOnlyFile)]
public void ShouldntThrowException(SaveType saveType)
{ {
using (var conn = Create(null, null, true)) using (var conn = Create(null, null, true))
{ {
var Server = GetServer(conn); var Server = GetServer(conn);
Server.Save(SaveType.BackgroundSave); Server.Save(saveType);
} }
} }
} }
......
...@@ -597,6 +597,9 @@ Message GetSaveMessage(SaveType type, CommandFlags flags = CommandFlags.None) ...@@ -597,6 +597,9 @@ Message GetSaveMessage(SaveType type, CommandFlags flags = CommandFlags.None)
{ {
case SaveType.BackgroundRewriteAppendOnlyFile: return Message.Create(-1, flags, RedisCommand.BGREWRITEAOF); case SaveType.BackgroundRewriteAppendOnlyFile: return Message.Create(-1, flags, RedisCommand.BGREWRITEAOF);
case SaveType.BackgroundSave: return Message.Create(-1, flags, RedisCommand.BGSAVE); case SaveType.BackgroundSave: return Message.Create(-1, flags, RedisCommand.BGSAVE);
#pragma warning disable 0618
case SaveType.ForegroundSave: return Message.Create(-1, flags, RedisCommand.SAVE);
#pragma warning restore 0618
default: throw new ArgumentOutOfRangeException("type"); default: throw new ArgumentOutOfRangeException("type");
} }
} }
...@@ -607,6 +610,9 @@ ResultProcessor<bool> GetSaveResultProcessor(SaveType type) ...@@ -607,6 +610,9 @@ ResultProcessor<bool> GetSaveResultProcessor(SaveType type)
{ {
case SaveType.BackgroundRewriteAppendOnlyFile: return ResultProcessor.DemandOK; case SaveType.BackgroundRewriteAppendOnlyFile: return ResultProcessor.DemandOK;
case SaveType.BackgroundSave: return ResultProcessor.BackgroundSaveStarted; case SaveType.BackgroundSave: return ResultProcessor.BackgroundSaveStarted;
#pragma warning disable 0618
case SaveType.ForegroundSave: return ResultProcessor.DemandOK;
#pragma warning restore 0618
default: throw new ArgumentOutOfRangeException("type"); default: throw new ArgumentOutOfRangeException("type");
} }
} }
......
namespace StackExchange.Redis using System;
namespace StackExchange.Redis
{ {
/// <summary> /// <summary>
/// The type of save operation to perform; note that foreground saving is not offered, as this is basically never a good thing to do through regular code. /// The type of save operation to perform
/// </summary> /// </summary>
public enum SaveType public enum SaveType
{ {
...@@ -15,5 +16,11 @@ public enum SaveType ...@@ -15,5 +16,11 @@ public enum SaveType
/// </summary> /// </summary>
/// <remarks>http://redis.io/commands/bgsave</remarks> /// <remarks>http://redis.io/commands/bgsave</remarks>
BackgroundSave, BackgroundSave,
/// <summary>
/// Save the DB in foreground. This is almost never a good thing to do, and could cause significant blocking. Only do this if you know you need to save
/// </summary>
/// <remarks>http://redis.io/commands/save</remarks>
[Obsolete("Saving on the foreground can cause significant blocking; use with extreme caution")]
ForegroundSave
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment