Skip to content

Commit 12e49f6

Browse files
authored
Fixes StackExchange#229, bringing HasValue in parity with IsNullOrEmpty (StackExchange#840)
It appears we just never use this property anywhere and never noticed, but users did long ago. See StackExchange#229 for details. Also adds some testing around this. While this may be considered a breaking change, I'm really going to err on the side of this is a plain on bug fix on a rarely used property. This doesn't impact any existing tests.
1 parent e7b4ab8 commit 12e49f6

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

StackExchange.Redis.Tests/Values.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Linq;
2+
using System.Text;
3+
using Xunit;
4+
using Xunit.Abstractions;
5+
6+
namespace StackExchange.Redis.Tests
7+
{
8+
public class Values : TestBase
9+
{
10+
public Values(ITestOutputHelper output) : base (output) { }
11+
12+
[Fact]
13+
public void NullValueChecks()
14+
{
15+
RedisValue four = 4;
16+
Assert.False(four.IsNull);
17+
Assert.True(four.IsInteger);
18+
Assert.True(four.HasValue);
19+
Assert.False(four.IsNullOrEmpty);
20+
21+
RedisValue n = default(RedisValue);
22+
Assert.True(n.IsNull);
23+
Assert.False(n.IsInteger);
24+
Assert.False(n.HasValue);
25+
Assert.True(n.IsNullOrEmpty);
26+
27+
RedisValue emptyArr = new byte[0];
28+
Assert.False(emptyArr.IsNull);
29+
Assert.False(emptyArr.IsInteger);
30+
Assert.False(emptyArr.HasValue);
31+
Assert.True(emptyArr.IsNullOrEmpty);
32+
}
33+
}
34+
}

StackExchange.Redis/StackExchange/Redis/RedisValue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ private RedisValue(long valueInt64, byte[] valueBlob)
4747
public bool IsNullOrEmpty => valueBlob == null || (valueBlob.Length == 0 && !(valueBlob == IntegerSentinel));
4848

4949
/// <summary>
50-
/// Indicates whether the value is greater than zero-length
50+
/// Indicates whether the value is greater than zero-length or has an integer value
5151
/// </summary>
52-
public bool HasValue => valueBlob?.Length > 0;
52+
public bool HasValue => !IsNullOrEmpty;
5353

5454
/// <summary>
5555
/// Indicates whether two RedisValue values are equivalent

0 commit comments

Comments
 (0)