Skip to content

Commit

Permalink
Add F# compatibility enhancements for #831 (#1386)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
NickCraver authored Mar 18, 2020
1 parent eef7b8d commit 659d514
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/StackExchange.Redis/RedisKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/StackExchange.Redis/RedisValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions tests/StackExchange.Redis.Tests/FSharpCompat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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));
}
}
}

0 comments on commit 659d514

Please sign in to comment.