Skip to content

Commit

Permalink
fix the problem
Browse files Browse the repository at this point in the history
  • Loading branch information
beetlex-io committed May 24, 2021
1 parent b164116 commit 0fd5f71
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 29 deletions.
7 changes: 7 additions & 0 deletions BeetleX.Redis.XUnitTest/BeetleX.Redis.XUnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<Compile Remove="DBTester_BACKUP_37104.cs" />
<Compile Remove="DBTester_BASE_37104.cs" />
<Compile Remove="DBTester_LOCAL_37104.cs" />
<Compile Remove="DBTester_REMOTE_37104.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Northwind.Data" Version="1.2.3" />
Expand Down
13 changes: 4 additions & 9 deletions BeetleX.Redis.XUnitTest/DBTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ public class DBTester
public DBTester(ITestOutputHelper output)
{
this.Console = output;
//DB.Host.AddWriteHost("192.168.2.19", 6378, true);
<<<<<<< HEAD
DB.Host.AddWriteHost("192.168.2.19", 6379);
=======
DB.Host.AddWriteHost("127.0.0.1");
DB.KeyPrefix = "bbq";
>>>>>>> KeyPrefix

DB.KeyPrefix = "BeetleX";
DB.AutoPing = false;
}

private RedisDB DB = new RedisDB(0);
Expand Down Expand Up @@ -100,15 +95,15 @@ public async void Set()

var emptyValue = await DB.Get<string>("test");
Write(emptyValue);
Assert.Equal<string>(emptyValue, "");
Assert.Equal<string>(emptyValue, null);


var nullResult = await DB.Set("test", null);
Write(nullResult);

var nullValue = await DB.Get<string>("test");
Write(nullValue);
Assert.Equal<string>(nullValue, "");
Assert.Equal<string>(nullValue, null);

}

Expand Down
12 changes: 6 additions & 6 deletions BeetleX.Redis.XUnitTest/HashTableTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public HashTableTester(ITestOutputHelper output)
{
this.Console = output;
DB.Host.AddWriteHost("localhost");
DB.KeyPrefix = "KV";
DB.KeyPrefix = "BeetleX";
}

private RedisDB DB = new RedisDB(0);
Expand Down Expand Up @@ -73,15 +73,15 @@ public async void HGet()

var emptyValue = await table.Get<string>("fieldEmpty");
Write(emptyValue);
Assert.Equal<string>(emptyValue, "");
Assert.Equal<string>(emptyValue, null);


var nullResult = await table.Set("fieldNull", null);
Write(nullResult);

var nullValue = await table.Get<string>("fieldNull");
Write(nullValue);
Assert.Equal<string>(nullValue, "");
Assert.Equal<string>(nullValue, null);


}
Expand Down Expand Up @@ -134,9 +134,9 @@ public async void HLen()
public async void HMGet()
{
await DB.Flushall();
var table = DB.CreateHashTable("myhash");
Write(await table.MSet(("field1", "hello"), ("field2", "world")));
var values = await table.Get<string, string, string>("field1", "field2", "nofield");
var table = DB.CreateHashTable("myhash");
Write(await table.MSet(("field1", "hello"), ("field2", "world")));
var values = await table.Get<string, string, string>("field1", "field2", "nofield");
Write(values.Item1);
Write(values.Item2);
Write(values.Item3);
Expand Down
9 changes: 5 additions & 4 deletions BeetleX.Redis.XUnitTest/SequenceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public SequenceTest(ITestOutputHelper output)
{
this.Console = output;
DB.Host.AddWriteHost("localhost");
DB.KeyPrefix = "BeetleX";
}

private RedisDB DB = new RedisDB(0);
Expand Down Expand Up @@ -50,7 +51,7 @@ public async void ZSCORE()
var sequeue = DB.CreateSequence("seq2");
var count = await sequeue.ZAdd((4.14, "bca"));
var value = await sequeue.ZScore("bca");
Assert.Equal<double>(value, 4.14);
Assert.Equal<double>(value.Value, 4.14);

var unknownMemberValue = await sequeue.ZScore("unknownseq");
Assert.Equal<double?>(unknownMemberValue, null);
Expand All @@ -64,10 +65,10 @@ public async void ZINCRBY()
var sequeue = DB.CreateSequence("seq2");
var count = await sequeue.ZAdd((4.14, member));
var value = await sequeue.ZScore(member);
Assert.Equal<double>(value, 4.14);
Assert.Equal<double>(value.Value, 4.14);
await sequeue.ZIncrby(5, member);
value = await sequeue.ZScore(member);
Assert.Equal<double>(value, 9.14);
Assert.Equal<double>(value.Value, 9.14);
}
[Fact]
public async void ZCARD()
Expand Down Expand Up @@ -161,7 +162,7 @@ public async void ZRANK()
var sequeue = DB.CreateSequence("seq2");
await sequeue.ZAdd((100, "A1"), (200, "A2"), (300, "A3"), (400, "A4"));
var value = await sequeue.ZRank("A4");
Assert.Equal<long>(value, 3);
Assert.Equal<long>(value.Value, 3);


var unknownMemberValue = await sequeue.ZRank("unknownseq");
Expand Down
2 changes: 1 addition & 1 deletion BeetleX.Redis.XUnitTest/SetsTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public SetsTester(ITestOutputHelper output)
DefaultRedis.Instance.Host.AddWriteHost("localhost");
DefaultRedis.Instance.DataFormater = new JsonFormater();
DB = DefaultRedis.Instance.Cloneable();
DB.KeyPrefix = "HENRY";
DB.KeyPrefix = "BeetleX";
}

private RedisDB DB;
Expand Down
6 changes: 3 additions & 3 deletions src/BeetleX.Redis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
<Version>1.2.4</Version>
<Version>1.3.1</Version>
<Company>beetlex.io</Company>
<Authors>henryfan</Authors>
<Copyright>Copyright © beetlex.io 2019-2021</Copyright>
Expand All @@ -17,11 +17,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BeetleX" Version="1.6.5.41" />
<PackageReference Include="BeetleX" Version="1.6.5.62" />
<PackageReference Include="BeetleX.Tracks" Version="0.7.5" />
<PackageReference Include="MessagePack" Version="2.1.115" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="protobuf-net" Version="2.4.6" />
<PackageReference Include="protobuf-net" Version="3.0.101" />
<PackageReference Include="System.Text.Json" Version="5.0.2" />
</ItemGroup>

Expand Down
4 changes: 4 additions & 0 deletions src/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ static Command()

public static byte[] GetMsgHeaderLengthData(int length)
{
if (length <= 0)
return null;
if (length > MAX_LENGTH_TABLE)
return null;
return mMsgHeaderLenData[length - 1];
Expand All @@ -38,6 +40,8 @@ public static byte[] GetMsgHeaderLengthData(int length)

public static byte[] GetBodyHeaderLenData(int length)
{
if (length <= 0)
return null;
if (length > MAX_LENGTH_TABLE)
return null;
return mBodyHeaderLenData[length - 1];
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/HSET.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public override void OnExecute()
base.OnExecute();
OnWriteKey(Key);
AddText(Field);
if (Value == null)
Value = string.Empty;
AddData(Value);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Commands/SET.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public override void OnExecute()
{
base.OnExecute();
OnWriteKey(Key);
if (Data == null)
Data = string.Empty;
AddData(Data);
if (TimeOut > 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ZUNIONSTORE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public override void OnExecute()
AddText(Items.Length);
foreach (var item in Items)
{
AddText(item.key);
OnWriteKey(item.key);
}
AddText("WEIGHTS");
foreach (var item in Items)
Expand Down
5 changes: 3 additions & 2 deletions src/RedisDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public RedisStream<T> GetStream<T>(string name)
public RedisDB Cloneable(IDataFormater dataFormater = null)
{
var result = new RedisDB(this.DB, dataFormater, this);
result.KeyPrefix = this.KeyPrefix;
return result;
}

Expand Down Expand Up @@ -163,7 +164,7 @@ public async Task<Result> Execute(Command cmd, params Type[] types)
return new Result() { ResultType = ResultType.NetError, Messge = "exceeding maximum number of connections" };
try
{
var result = host.Connect(this,client);
var result = host.Connect(this, client);
if (result.IsError)
{
return result;
Expand Down Expand Up @@ -661,7 +662,7 @@ public async Task PFMerge(string key, params string[] items)
throw new RedisException(result.Messge);
}




public async ValueTask<InfoResult> Info(InfoSection? section = null)
Expand Down
10 changes: 7 additions & 3 deletions src/Sequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ public async ValueTask<long> ZAdd(params (double, string)[] items)
return (long)result.Value;
}

public async ValueTask<double> ZScore(string member)
public async ValueTask<double?> ZScore(string member)
{
ZSCORE cmd = new ZSCORE(Key, member);
var result = await DB.Execute(cmd, typeof(string));
if (result.IsError)
throw new RedisException(result.Messge);
if (result.Value == null)
return null;
return System.Convert.ToDouble(result.Value);
}

Expand Down Expand Up @@ -114,12 +116,14 @@ public async ValueTask<long> ZCount(double min, double max)
return GetItems(result, withscores);
}

public async ValueTask<long> ZRank(string member)
public async ValueTask<long?> ZRank(string member)
{
ZRANK cmd = new ZRANK(Key, member);
var result = await DB.Execute(cmd, typeof(string));
if (result.IsError)
throw new RedisException(result.Messge);
if (result.Value == null)
return null;
return System.Convert.ToInt64(result.Value);
}

Expand Down Expand Up @@ -211,7 +215,7 @@ public ValueTask<long> ZUnionsStore(params string[] keys)
return ZUnionsStore(items);
}

public ValueTask<long> ZUnionsStore(params (string key, double weight)[] items)
public ValueTask<long> ZUnionsStore(params (string key, double weight)[] items)
{
return ZUnionsStore(items, ZUNIONSTORE.AggregateType.SUM);
}
Expand Down

0 comments on commit 0fd5f71

Please sign in to comment.