Unverified Commit 659d5149 authored by Nick Craver's avatar Nick Craver Committed by GitHub

Add F# compatibility enhancements for #831 (#1386)

Asked for in #831 and low overhead so why not! I didn't do `RedisChannel` since it already has a constructor available. Tests added to ensure these are used in a way we don't break them.
parent eef7b8d6
......@@ -14,6 +14,11 @@ internal RedisKey(byte[] keyPrefix, object keyValue)
KeyValue = keyValue;
}
/// <summary>
/// Creates a <see cref="RedisKey"/> from a string.
/// </summary>
public RedisKey(string key) : this(null, key) { }
internal RedisKey AsPrefix() => new RedisKey((byte[])this, null);
internal bool IsNull => KeyPrefix == null && KeyValue == null;
......
......@@ -37,6 +37,11 @@ internal RedisValue(object obj, long overlappedBits)
_memory = default;
}
/// <summary>
/// Creates a <see cref="RedisValue"/> from a string.
/// </summary>
public RedisValue(string value) : this(0, default, value) { }
#pragma warning disable RCS1085 // Use auto-implemented property.
internal object DirectObject => _objectOrSentinel;
internal long DirectOverlappedBits64 => _overlappedBits64;
......
using Xunit;
using Xunit.Abstractions;
namespace StackExchange.Redis.Tests
{
public class FSharpCompat : TestBase
{
public FSharpCompat(ITestOutputHelper output) : base (output) { }
[Fact]
public void RedisKeyConstructor()
{
Assert.Equal(default, new RedisKey());
Assert.Equal((RedisKey)"MyKey", new RedisKey("MyKey"));
Assert.Equal((RedisKey)"MyKey2", new RedisKey(null, "MyKey2"));
}
[Fact]
public void RedisValueConstructor()
{
Assert.Equal(default, new RedisValue());
Assert.Equal((RedisValue)"MyKey", new RedisValue("MyKey"));
Assert.Equal((RedisValue)"MyKey2", new RedisValue("MyKey2", 0));
}
}
}
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