Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed null and empty fullbulkstring encoding in redis encoder #482

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 9 additions & 63 deletions src/DotNetty.Codecs.Redis/Messages/FullBulkStringRedisMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ namespace DotNetty.Codecs.Redis.Messages

public sealed class FullBulkStringRedisMessage : DefaultByteBufferHolder, IFullBulkStringRedisMessage
{
public static readonly IFullBulkStringRedisMessage Null = new NullFullBulkStringRedisMessage();
public static readonly IFullBulkStringRedisMessage Empty = new EmptyFullBulkStringRedisMessage();
public static readonly FullBulkStringRedisMessage Null = new FullBulkStringRedisMessage(true);
public static readonly FullBulkStringRedisMessage Empty = new FullBulkStringRedisMessage(false);

public FullBulkStringRedisMessage(IByteBuffer content)
: base(content)
{
}


public bool IsNull => false;
public FullBulkStringRedisMessage(bool isNull)
: base(Unpooled.Empty)
{
this.IsNull = isNull;
}
public bool IsNull { get; private set; }

public override string ToString() =>
new StringBuilder(StringUtil.SimpleClassName(this))
Expand All @@ -28,66 +34,6 @@ public override string ToString() =>
.Append(']')
.ToString();

sealed class NullFullBulkStringRedisMessage : IFullBulkStringRedisMessage
{
public bool IsNull => true;

public IByteBuffer Content => Unpooled.Empty;

public IByteBufferHolder Copy() => this;

public IByteBufferHolder Duplicate() => this;

public IByteBufferHolder RetainedDuplicate() => this;

public int ReferenceCount => 1;

public IReferenceCounted Retain() => this;

public IReferenceCounted Retain(int increment) => this;


public IByteBufferHolder Replace(IByteBuffer content) => this;

public IReferenceCounted Touch() => this;

public IReferenceCounted Touch(object hint) => this;

public bool Release() => false;

public bool Release(int decrement) => false;
}

sealed class EmptyFullBulkStringRedisMessage : IFullBulkStringRedisMessage
{
public bool IsNull => false;

public IByteBuffer Content => Unpooled.Empty;

public IByteBufferHolder Copy() => this;

public IByteBufferHolder Duplicate() => this;

public IByteBufferHolder RetainedDuplicate() => this;

public int ReferenceCount => 1;

public IReferenceCounted Retain() => this;

public IReferenceCounted Retain(int increment) => this;


public IByteBufferHolder Replace(IByteBuffer content) => this;

public IReferenceCounted Touch() => this;

public IReferenceCounted Touch(object hint) => this;

public bool Release() => false;

public bool Release(int decrement) => false;
}

public override IByteBufferHolder Replace(IByteBuffer content) => new FullBulkStringRedisMessage(content);
}
}
14 changes: 14 additions & 0 deletions test/DotNetty.Codecs.Redis.Tests/RedisEncoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ public void EncodeFullBulkString()
written.Release();
}

[Fact]
public void EncodeNullFullBulkString()
{


var msg = FullBulkStringRedisMessage.Null;
Assert.True(this.channel.WriteOutbound(msg));

IByteBuffer written = ReadAll(this.channel);
Assert.Equal(BytesOf("$-1\r\n"), BytesOf(written));

}


[Fact]
public void EncodeSimpleArray()
{
Expand Down