Skip to content

Commit

Permalink
Merge branch 'KeyPrefix'
Browse files Browse the repository at this point in the history
# Conflicts:
#	BeetleX.Redis.XUnitTest/DBTester.cs
  • Loading branch information
beetlex-io committed May 23, 2021
2 parents bf4bd7f + a08b0d4 commit b164116
Show file tree
Hide file tree
Showing 137 changed files with 205 additions and 210 deletions.
2 changes: 1 addition & 1 deletion BeetleX.Redis.XUnitTest/DBMessagePackTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class DBMessagePackTester
public DBMessagePackTester(ITestOutputHelper output)
{
this.Console = output;
DB.Host.AddWriteHost("192.168.2.19");
DB.Host.AddWriteHost("localhost");
}

private RedisDB DB = new RedisDB(0, new MessagePackFormater());
Expand Down
7 changes: 6 additions & 1 deletion BeetleX.Redis.XUnitTest/DBTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ 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

}

Expand Down Expand Up @@ -183,7 +188,7 @@ public async void Keys()
await DB.Flushall();
var mset = await DB.MSet(("one", 1), ("tow", 2), ("three", 2), ("four", 4));
Write(mset);
var keys = await DB.Keys("*o*");
var keys = await DB.Keys("*");
Write(keys);
keys = await DB.Keys("t??");
Write(keys);
Expand Down
23 changes: 0 additions & 23 deletions BeetleX.Redis.XUnitTest/GEOTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,6 @@ public GEOTester(ITestOutputHelper output)

public DataHelper Data => DataHelper.Defalut;


private Employee GetEmployee(int id)
{
return Data.Employees[id];
}

private Order GetOrder(int id)
{
return Data.Orders[id];
}

private OrderBase GetOrderBase(int id)
{
return Data.OrderBases[id];
}

private Customer GetCustomer(int id)
{
return Data.Customers[id];
}



private void Write(object result)
{
if (result is System.Collections.IEnumerable && !(result is string))
Expand Down
1 change: 1 addition & 0 deletions BeetleX.Redis.XUnitTest/HashTableTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public HashTableTester(ITestOutputHelper output)
{
this.Console = output;
DB.Host.AddWriteHost("localhost");
DB.KeyPrefix = "KV";
}

private RedisDB DB = new RedisDB(0);
Expand Down
5 changes: 3 additions & 2 deletions BeetleX.Redis.XUnitTest/SequenceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class SequenceTest
public SequenceTest(ITestOutputHelper output)
{
this.Console = output;
DB.Host.AddWriteHost("192.168.2.19");
DB.Host.AddWriteHost("localhost");
}

private RedisDB DB = new RedisDB(0);
Expand All @@ -38,7 +38,8 @@ public async void ZAdd()
{
await DB.Del("seq2");
var sequeue = DB.CreateSequence("seq2");
var count = await sequeue.ZAdd((1, Guid.NewGuid().ToString("N")), (2, Guid.NewGuid().ToString("N")));
var count = await sequeue.ZAdd((123.1231, "123"), (123.1231, "234"));
var value = await sequeue.ZRange(0, -1,true);
Assert.Equal<long>(count, 2);
Write(count);
}
Expand Down
27 changes: 2 additions & 25 deletions BeetleX.Redis.XUnitTest/SetsTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,12 @@ public SetsTester(ITestOutputHelper output)
this.Console = output;
DefaultRedis.Instance.Host.AddWriteHost("localhost");
DefaultRedis.Instance.DataFormater = new JsonFormater();
DB = DefaultRedis.Instance;
DB = DefaultRedis.Instance.Cloneable();
DB.KeyPrefix = "HENRY";
}

private RedisDB DB;

public DataHelper Data => DataHelper.Defalut;


private Employee GetEmployee(int id)
{
return Data.Employees[id];
}

private Order GetOrder(int id)
{
return Data.Orders[id];
}

private OrderBase GetOrderBase(int id)
{
return Data.OrderBases[id];
}

private Customer GetCustomer(int id)
{
return Data.Customers[id];
}


private void Write(object result)
{
if (result is System.Collections.IEnumerable && !(result is string))
Expand Down
5 changes: 3 additions & 2 deletions BeetleX.Redis.XUnitTest/StreamTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public StreamTester(ITestOutputHelper output)
{
this.Console = output;
DB.DataFormater = new JsonFormater();
DB.KeyPrefix = "henry";
DB.Host.AddWriteHost("127.0.0.1");
}

Expand Down Expand Up @@ -61,7 +62,7 @@ public async void XRANGE()
{
RedisStream<Employee> stream = DB.GetStream<Employee>("employees_stream");
var items = await stream.Range();
items = await stream.Read(0);
items = await stream.Read(0, 1, "0");
Write(items);
}
[Fact]
Expand All @@ -74,7 +75,7 @@ public async void XREVRANGE()
[Fact]
public async void XREADProperties()
{
RedisStream<Dictionary<string,string>> stream = DB.GetStream<Dictionary<string, string>>("employees_stream");
RedisStream<Dictionary<string, string>> stream = DB.GetStream<Dictionary<string, string>>("employees_stream");
var items = await stream.RangeAll();
Write(items);
items = await stream.RevRangeAll();
Expand Down
6 changes: 6 additions & 0 deletions BeetleX.Redis.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeetleX.Redis.Samples", "Be
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeetleX.Redis.XUnitTest", "BeetleX.Redis.XUnitTest\BeetleX.Redis.XUnitTest.csproj", "{B805DA42-087A-4884-9EB1-062771C62026}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StackExchange.Redis", "C:\Users\henry\Downloads\StackExchange.Redis-main\StackExchange.Redis-main\src\StackExchange.Redis\StackExchange.Redis.csproj", "{9D6EF164-37F3-4674-8B04-3D411A4C9568}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -33,6 +35,10 @@ Global
{B805DA42-087A-4884-9EB1-062771C62026}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B805DA42-087A-4884-9EB1-062771C62026}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B805DA42-087A-4884-9EB1-062771C62026}.Release|Any CPU.Build.0 = Release|Any CPU
{9D6EF164-37F3-4674-8B04-3D411A4C9568}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D6EF164-37F3-4674-8B04-3D411A4C9568}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D6EF164-37F3-4674-8B04-3D411A4C9568}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D6EF164-37F3-4674-8B04-3D411A4C9568}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 2 additions & 0 deletions PerformanceTest/GET_JSON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public async override Task Execute()
var i = OrderHelper.GetOrderID();
var data = await RedisDB.StringGetAsync(i.ToString());
var item = System.Text.Json.JsonSerializer.Deserialize<Northwind.Data.Order>(data);
if (item.OrderID != i)
throw new Exception("aaaa");
}
}

Expand Down
7 changes: 5 additions & 2 deletions PerformanceTest/PerformanceTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@

<ItemGroup>
<PackageReference Include="BeetleX.CodeBenchmark" Version="1.1.1" />
<PackageReference Include="BeetleX.Redis" Version="1.2.1" />
<PackageReference Include="BeetleX.Redis" Version="1.2.4" />
<PackageReference Include="FreeRedis" Version="0.3.5" />
<PackageReference Include="NewLife.Redis" Version="3.9.2021.407" />
<PackageReference Include="Northwind.Data" Version="1.2.3" />
<PackageReference Include="StackExchange.Redis" Version="2.2.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="C:\Users\henry\Downloads\StackExchange.Redis-main\StackExchange.Redis-main\src\StackExchange.Redis\StackExchange.Redis.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
17 changes: 16 additions & 1 deletion src/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ static Command()

private static byte[] LineBytes;

internal string KeyPrefix { get; set; }

public static List<byte[]> mMsgHeaderLenData = new List<byte[]>();

public static byte[] GetMsgHeaderLengthData(int length)
Expand Down Expand Up @@ -92,8 +94,21 @@ public virtual void OnExecute()
mParameters.Add(new CommandParameter { ValueBuffer = cmdBuffer });
}

public void Execute(RedisClient client, PipeStream stream)
protected virtual void OnWriteKey(string key)
{
if (string.IsNullOrEmpty(KeyPrefix))
{
AddText(key);
}
else
{
AddText(KeyPrefix + ":" + key);
}
}

public void Execute(RedisDB db, RedisClient client, PipeStream stream)
{
KeyPrefix = db?.KeyPrefix;
using (var track = CodeTrackFactory.Track("Write", CodeTrackLevel.Function, Activity?.Id, "Redis", "Protocol"))
{
OnExecute();
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/BLPOP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override void OnExecute()
{
base.OnExecute();
for (int i = 0; i < Key.Length; i++)
AddText(Key[i]);
OnWriteKey(Key[i]);
AddText(TimeOut);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/BRPOP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override void OnExecute()
{
base.OnExecute();
for (int i = 0; i < Key.Length; i++)
AddText(Key[i]);
OnWriteKey(Key[i]);
AddText(Timeout);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/BRPOPLPUSH.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public BRPOPLPUSH(string source, string dest, int timeout, IDataFormater dataFor
public override void OnExecute()
{
base.OnExecute();
AddText(Source);
AddText(Dest);
OnWriteKey(Source);
OnWriteKey(Dest);
AddText(TimeOut);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/DECR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public DECR(string key)
public override void OnExecute()
{
base.OnExecute();
AddText(Key);
OnWriteKey(Key);
}
}
}
2 changes: 1 addition & 1 deletion src/Commands/DECRBY.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public DECRBY(string key, int decrement)
public override void OnExecute()
{
base.OnExecute();
AddText(Key);
OnWriteKey(Key);
AddText(Decrement);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/DEL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override void OnExecute()
{
base.OnExecute();
for (int i = 0; i < Keys.Length; i++)
AddText(Keys[i]);
OnWriteKey(Keys[i]);
}
}
}
2 changes: 1 addition & 1 deletion src/Commands/DUMP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public DUMP(string key)
public override void OnExecute()
{
base.OnExecute();
AddText(Key);
OnWriteKey(Key);
}
}
}
2 changes: 1 addition & 1 deletion src/Commands/EXISTS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override void OnExecute()
{
base.OnExecute();
for (int i = 0; i < Keys.Length; i++)
AddText(Keys[i]);
OnWriteKey(Keys[i]);
}
}
}
2 changes: 1 addition & 1 deletion src/Commands/EXPIRE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public EXPIRE(string key, int seconds)
public override void OnExecute()
{
base.OnExecute();
AddText(Key);
OnWriteKey(Key);
AddText(Seconds);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/EXPIREAT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public EXPIREAT(string key, long timestamp)
public override void OnExecute()
{
base.OnExecute();
AddText(Key);
OnWriteKey(Key);
AddText(Timestamp);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/GEOADD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public GEOADD(string key, (double, double, string)[] data)
public override void OnExecute()
{
base.OnExecute();
AddText(Key);
OnWriteKey(Key);
foreach (var item in Data)
{
AddText(item.Item1);
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/GEODIST.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public GEODIST(string key, string member1, string member2, GEODISTUnit unit = GE
public override void OnExecute()
{
base.OnExecute();
AddText(Key);
OnWriteKey(Key);
AddText(Member1);
AddText(Member2);
AddText(Unit.ToString());
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/GEOPOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public GEOPOS(string key, params string[] members)
public override void OnExecute()
{
base.OnExecute();
AddText(Key);
OnWriteKey(Key);
foreach (var item in Members)
AddText(item);

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/GEORADIUS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public GEORADIUSBYMEMBER(string key, string member, int radius)
public override void OnExecute()
{
base.OnExecute();
AddText(Key);
OnWriteKey(Key);
AddText(Member);
AddText(Radius);
AddText(Unit.ToString());
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/GET.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public GET(string key, IDataFormater formater)
public override void OnExecute()
{
base.OnExecute();
AddText(Key);
OnWriteKey(Key);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/GETBIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public GETBIT(string key, int offset)
public override void OnExecute()
{
base.OnExecute();
AddText(Key);
OnWriteKey(Key);
AddText(Offset);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/GETRANGE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public GETRANGE(string key, int start, int end)
public override void OnExecute()
{
base.OnExecute();
AddText(Key);
OnWriteKey(Key);
AddText(Start);
AddText(End);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/GETSET.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public GETSET(string key, object value, IDataFormater dataFormater)
public override void OnExecute()
{
base.OnExecute();
AddText(Key);
OnWriteKey(Key);
AddData(Value);
}
}
Expand Down
Loading

0 comments on commit b164116

Please sign in to comment.