Skip to content

Commit

Permalink
Fix Zero length check
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek committed Jul 23, 2024
1 parent a64ca14 commit 1f014f7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/StackExchange.Redis/PhysicalConnection.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Pipelines.Sockets.Unofficial;
using Microsoft.Extensions.Logging;
using Pipelines.Sockets.Unofficial;
using Pipelines.Sockets.Unofficial.Arenas;
using System;
using System.Buffers;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
Expand All @@ -17,9 +19,7 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using static StackExchange.Redis.Message;
using System.Buffers.Binary;

namespace StackExchange.Redis
{
Expand Down Expand Up @@ -91,7 +91,7 @@ public PhysicalConnection(PhysicalBridge bridge)
connectionType = bridge.ConnectionType;
_bridge = new WeakReference(bridge);
ChannelPrefix = bridge.Multiplexer.RawConfig.ChannelPrefix;
if (ChannelPrefix?.Length == 0) ChannelPrefix = null; // null tests are easier than null+empty
if (ChannelPrefix == null || ChannelPrefix.Length == 0) ChannelPrefix = null; // null tests are easier than null+empty
var endpoint = bridge.ServerEndPoint.EndPoint;
_physicalName = connectionType + "#" + Interlocked.Increment(ref totalCount) + "@" + Format.ToString(endpoint);

Expand Down
6 changes: 3 additions & 3 deletions src/StackExchange.Redis/RedisKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace StackExchange.Redis
{
internal RedisKey(byte[]? keyPrefix, object? keyValue)
{
KeyPrefix = keyPrefix?.Length == 0 ? null : keyPrefix;
KeyPrefix = keyPrefix == null || keyPrefix.Length == 0 ? null : keyPrefix;
KeyValue = keyValue;
}

Expand Down Expand Up @@ -253,7 +253,7 @@ public static implicit operator RedisKey(byte[]? key)
/// Obtain the <see cref="RedisKey"/> as a <see cref="T:byte[]"/>.
/// </summary>
/// <param name="key">The key to get a byte array for.</param>
public static implicit operator byte[]? (RedisKey key)
public static implicit operator byte[]?(RedisKey key)
{
if (key.IsNull) return null;
if (key.TryGetSimpleBuffer(out var arr)) return arr;
Expand All @@ -270,7 +270,7 @@ public static implicit operator RedisKey(byte[]? key)
/// Obtain the key as a <see cref="string"/>.
/// </summary>
/// <param name="key">The key to get a string for.</param>
public static implicit operator string? (RedisKey key)
public static implicit operator string?(RedisKey key)
{
if (key.KeyPrefix is null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/StackExchange.Redis/RedisResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ internal override bool AsBoolean()
: Array.ConvertAll(_value, x => x.AsByteArray()!);

private bool IsSingleton => _value?.Length == 1;
private bool IsEmpty => _value?.Length == 0;
private bool IsEmpty => _value == null || _value.Length == 0;
internal override double AsDouble()
{
if (IsSingleton) return _value![0].AsDouble();
Expand Down

0 comments on commit 1f014f7

Please sign in to comment.