[fix]修正Search方法可能出现的数据转换错误
This commit is contained in:
parent
54933dc971
commit
04db122029
|
@ -721,17 +721,20 @@ public class FullRedis : Redis
|
|||
var rs = Execute(r => r.Execute<Object[]>("SCAN", p, "MATCH", GetKey(model.Pattern + ""), "COUNT", count), node);
|
||||
if (rs == null || rs.Length != 2) break;
|
||||
|
||||
model.Position = (rs[0] as IPacket)?.ToStr().ToInt() ?? 0;
|
||||
var pos = (rs[0] as IPacket)?.ToStr().ToInt();
|
||||
if (pos != null) model.Position = pos.Value;
|
||||
|
||||
if (rs[1] is Object[] ps)
|
||||
{
|
||||
foreach (IPacket item in ps)
|
||||
foreach (var item in ps)
|
||||
{
|
||||
if (item != null && count-- > 0) yield return item.ToStr();
|
||||
if (item == null && count-- > 0) yield return String.Empty;
|
||||
if (item is String str && count-- > 0) yield return str;
|
||||
if (item is IPacket pk && count-- > 0) yield return pk.ToStr();
|
||||
}
|
||||
}
|
||||
|
||||
if (model.Position == 0) break;
|
||||
if (pos == null || pos == 0) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -879,9 +879,9 @@ public class RedisClient : DisposeBase
|
|||
for (var i = 0; i < objs.Length; i++)
|
||||
{
|
||||
if (objs[i] is IPacket pk4)
|
||||
{
|
||||
arr.SetValue(Host.Encoder.Decode(pk4, elmType), i);
|
||||
}
|
||||
else if (elmType == typeof(Object))
|
||||
arr.SetValue(objs[i], i);
|
||||
else if (objs[i] != null && objs[i].GetType().As(elmType))
|
||||
arr.SetValue(objs[i], i);
|
||||
}
|
||||
|
|
|
@ -1,63 +1,58 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NewLife.Caching;
|
||||
using NewLife.Log;
|
||||
using Xunit;
|
||||
|
||||
namespace XUnitTest
|
||||
namespace XUnitTest;
|
||||
|
||||
[Collection("Basic")]
|
||||
public class SearchTest
|
||||
{
|
||||
[Collection("Basic")]
|
||||
public class SearchTest
|
||||
protected readonly FullRedis _redis;
|
||||
|
||||
public SearchTest()
|
||||
{
|
||||
protected readonly FullRedis _redis;
|
||||
var config = BasicTest.GetConfig();
|
||||
|
||||
public SearchTest()
|
||||
{
|
||||
var config = BasicTest.GetConfig();
|
||||
|
||||
_redis = new FullRedis();
|
||||
_redis.Init(config);
|
||||
_redis.Db = 2;
|
||||
_redis.Retry = 0;
|
||||
_redis.Log = XTrace.Log;
|
||||
_redis = new FullRedis();
|
||||
_redis.Init(config);
|
||||
_redis.Db = 2;
|
||||
_redis.Retry = 0;
|
||||
_redis.Log = XTrace.Log;
|
||||
|
||||
#if DEBUG
|
||||
_redis.ClientLog = XTrace.Log;
|
||||
_redis.ClientLog = XTrace.Log;
|
||||
#endif
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "搜索测试")]
|
||||
public void GetSearchTest()
|
||||
{
|
||||
var ic = _redis;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
PlayGameVo playGameVo = new PlayGameVo()
|
||||
{
|
||||
MemberId = (i + 1).ToString(),
|
||||
GameMode = 1,
|
||||
Num = 10000
|
||||
};
|
||||
//cache.Cache.Set(RedisConst.PlayGameKey + playGameVo.MemberId, playGameVo);
|
||||
//redis.Prefix=RedisConst.PlayGameKey;
|
||||
ic.Set("jinshi:member:battle-royale:play-game:" + playGameVo.MemberId, playGameVo);
|
||||
}
|
||||
IDictionary<string, string> all = new Dictionary<string, string>();
|
||||
List<string> list = ic.Search("jinshi:member:battle-royale:play-game:*", 1000).ToList();
|
||||
all = ic.GetAll<string>(list);
|
||||
Assert.True(list.Count==1000);
|
||||
Assert.False(list.Count < 1000);
|
||||
}
|
||||
}
|
||||
|
||||
public class PlayGameVo
|
||||
[Fact(DisplayName = "搜索测试")]
|
||||
public void GetSearchTest()
|
||||
{
|
||||
public string MemberId { get; set; }
|
||||
public int GameMode { get; set; }
|
||||
public int Num { get; set; }
|
||||
var ic = _redis;
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var playGameVo = new PlayGameVo()
|
||||
{
|
||||
MemberId = (i + 1).ToString(),
|
||||
GameMode = 1,
|
||||
Num = 10000
|
||||
};
|
||||
//cache.Cache.Set(RedisConst.PlayGameKey + playGameVo.MemberId, playGameVo);
|
||||
//redis.Prefix=RedisConst.PlayGameKey;
|
||||
ic.Set("jinshi:member:battle-royale:play-game:" + playGameVo.MemberId, playGameVo);
|
||||
}
|
||||
var list = ic.Search("jinshi:member:battle-royale:play-game:*", 1000).ToList();
|
||||
var all = ic.GetAll<String>(list);
|
||||
Assert.True(list.Count == 1000);
|
||||
Assert.False(list.Count < 1000);
|
||||
}
|
||||
}
|
||||
|
||||
public class PlayGameVo
|
||||
{
|
||||
public String MemberId { get; set; }
|
||||
public Int32 GameMode { get; set; }
|
||||
public Int32 Num { get; set; }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue