优化字符串数组和Object数组使用,减少GC分配
This commit is contained in:
parent
868f994cdd
commit
1b16e8369d
|
@ -470,7 +470,11 @@ public class FullRedis : Redis
|
||||||
{
|
{
|
||||||
if (keys == null || keys.Length == 0) return 0;
|
if (keys == null || keys.Length == 0) return 0;
|
||||||
|
|
||||||
keys = keys.Select(GetKey).ToArray();
|
//keys = keys.Select(GetKey).ToArray();
|
||||||
|
for (var i = 0; i < keys.Length; i++)
|
||||||
|
{
|
||||||
|
keys[i] = GetKey(keys[i]);
|
||||||
|
}
|
||||||
if (keys.Length == 1) return base.Remove(keys[0]);
|
if (keys.Length == 1) return base.Remove(keys[0]);
|
||||||
|
|
||||||
InitCluster();
|
InitCluster();
|
||||||
|
@ -481,7 +485,7 @@ public class FullRedis : Redis
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return Execute(keys.FirstOrDefault(), (rds, k) => rds.Execute<Int32>("DEL", keys), true);
|
return Execute(keys[0], (rds, k) => rds.Execute<Int32>("DEL", keys), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -574,25 +578,25 @@ public class FullRedis : Redis
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override IDictionary<String, T> GetDictionary<T>(String key) => new RedisHash<String, T>(this, key);
|
public override IDictionary<String, T> GetDictionary<T>(String key) => new RedisHash<String, T>(this, key);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取哈希表所有数据
|
/// 获取哈希表所有数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IDictionary<String, T> GetHashAll<T>(String key)
|
public IDictionary<String, T> GetHashAll<T>(String key)
|
||||||
{
|
{
|
||||||
var hashMap = new RedisHash<String, T>(this, key);
|
var hashMap = new RedisHash<String, T>(this, key);
|
||||||
var nCount = hashMap!.Count();
|
var nCount = hashMap!.Count();
|
||||||
var sModel = new SearchModel()
|
var sModel = new SearchModel()
|
||||||
{
|
{
|
||||||
Pattern = "*",
|
Pattern = "*",
|
||||||
Position = 0,
|
Position = 0,
|
||||||
Count = nCount
|
Count = nCount
|
||||||
};
|
};
|
||||||
return hashMap!.Search(sModel).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
return hashMap!.Search(sModel).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>获取队列,快速LIST结构,无需确认</summary>
|
/// <summary>获取队列,快速LIST结构,无需确认</summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
/// <param name="topic">消息队列主题</param>
|
/// <param name="topic">消息队列主题</param>
|
||||||
|
|
|
@ -999,16 +999,17 @@ public class RedisClient : DisposeBase
|
||||||
{
|
{
|
||||||
if (values == null || values.Count == 0) throw new ArgumentNullException(nameof(values));
|
if (values == null || values.Count == 0) throw new ArgumentNullException(nameof(values));
|
||||||
|
|
||||||
var ps = new List<Object>();
|
var k = 0;
|
||||||
|
var ps = new Object[values.Count * 2];
|
||||||
foreach (var item in values)
|
foreach (var item in values)
|
||||||
{
|
{
|
||||||
ps.Add(item.Key);
|
ps[k++] = item.Key;
|
||||||
|
|
||||||
if (item.Value == null) throw new NullReferenceException();
|
if (item.Value == null) throw new NullReferenceException();
|
||||||
ps.Add(item.Value);
|
ps[k++] = item.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
var rs = Execute<String>("MSET", ps.ToArray());
|
var rs = Execute<String>("MSET", ps);
|
||||||
if (rs != "OK")
|
if (rs != "OK")
|
||||||
{
|
{
|
||||||
using var span = Host.Tracer?.NewSpan($"redis:{Name}:ErrorSetAll", values);
|
using var span = Host.Tracer?.NewSpan($"redis:{Name}:ErrorSetAll", values);
|
||||||
|
|
Loading…
Reference in New Issue