Commit 0d355244 authored by Christian Corsano's avatar Christian Corsano

Fix RedisServer.Save(SaveType.BackgroundSave)

BGSAVE returns "Background saving started" upon success,
RedisServer.Save expected "OK".
parent 4eb5318a
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
namespace StackExchange.Redis.Tests.Issues
{
[TestFixture]
public class BgSaveResponse : TestBase
{
[Test]
public void ShouldntThrowException()
{
using (var conn = Create(null, null, true))
{
var Server = GetServer(conn);
Server.Save(SaveType.BackgroundSave);
}
}
}
}
......@@ -71,6 +71,7 @@
<Compile Include="Expiry.cs" />
<Compile Include="Config.cs" />
<Compile Include="FloatingPoint.cs" />
<Compile Include="Issues\BGSAVEResponse.cs" />
<Compile Include="Issues\Issue6.cs" />
<Compile Include="Issues\SO22786599.cs" />
<Compile Include="Keys.cs" />
......
......@@ -65,6 +65,7 @@ public static readonly RedisValue
public static readonly byte[] BytesOK = Encoding.UTF8.GetBytes("OK");
public static readonly byte[] BytesPONG = Encoding.UTF8.GetBytes("PONG");
public static readonly byte[] BytesBackgroundSavingStarted = Encoding.UTF8.GetBytes("Background saving started");
public static readonly byte[] ByteWildcard = { (byte)'*' };
internal static RedisValue Get(Bitwise operation)
{
......
......@@ -251,13 +251,13 @@ public void MakeMaster(ReplicationChangeOptions options, TextWriter log = null)
public void Save(SaveType type, CommandFlags flags = CommandFlags.None)
{
var msg = GetSaveMessage(type, flags);
ExecuteSync(msg, ResultProcessor.DemandOK);
ExecuteSync(msg, GetSaveResultProcessor(type));
}
public Task SaveAsync(SaveType type, CommandFlags flags = CommandFlags.None)
{
var msg = GetSaveMessage(type, flags);
return ExecuteAsync(msg, ResultProcessor.DemandOK);
return ExecuteAsync(msg, GetSaveResultProcessor(type));
}
public bool ScriptExists(string script, CommandFlags flags = CommandFlags.None)
......@@ -541,6 +541,17 @@ Message GetSaveMessage(SaveType type, CommandFlags flags = CommandFlags.None)
default: throw new ArgumentOutOfRangeException("type");
}
}
ResultProcessor<bool> GetSaveResultProcessor(SaveType type)
{
switch (type)
{
case SaveType.BackgroundRewriteAppendOnlyFile: return ResultProcessor.DemandOK;
case SaveType.BackgroundSave: return ResultProcessor.BackgroundSaveStarted;
default: throw new ArgumentOutOfRangeException("type");
}
}
struct KeysScanResult
{
public static readonly ResultProcessor<KeysScanResult> Processor = new KeysResultProcessor();
......
......@@ -13,12 +13,13 @@ abstract class ResultProcessor
public static readonly ResultProcessor<bool>
Boolean = new BooleanProcessor(),
DemandOK = new ExpectBasicStringProcessor(RedisLiterals.BytesOK),
DemandPONG = new ExpectBasicStringProcessor("PONG"),
DemandPONG = new ExpectBasicStringProcessor(RedisLiterals.BytesPONG),
DemandZeroOrOne = new DemandZeroOrOneProcessor(),
AutoConfigure = new AutoConfigureProcessor(),
TrackSubscriptions = new TrackSubscriptionsProcessor(),
Tracer = new TracerProcessor(false),
EstablishConnection = new TracerProcessor(true);
EstablishConnection = new TracerProcessor(true),
BackgroundSaveStarted = new ExpectBasicStringProcessor(RedisLiterals.BytesBackgroundSavingStarted);
public static readonly ResultProcessor<byte[]>
ByteArray = new ByteArrayProcessor(),
......
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