Skip to content

Commit

Permalink
[fix] 修正Redis缓存压缩次数过大时,keys数组索引越界的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Nov 25, 2024
1 parent 67de80f commit 4564a6e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions NewLife.Core/Caching/Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ protected virtual Int64 BenchGet(String[] keys, Int64 times, Int32 threads, Bool
{
for (var i = k; i < times; i += threads)
{
var val = Get<String>(keys[i]);
var val = Get<String>(keys[i % keys.Length]);
}
}
else
Expand All @@ -486,7 +486,7 @@ protected virtual Int64 BenchGet(String[] keys, Int64 times, Int32 threads, Bool
var keys2 = new String[batch];
for (var i = k; i < times; i += threads)
{
keys2[n++] = keys[i];
keys2[n++] = keys[i % keys.Length];

if (n >= batch)
{
Expand Down Expand Up @@ -543,7 +543,7 @@ protected virtual Int64 BenchSet(String[] keys, Int64 times, Int32 threads, Bool
{
for (var i = k; i < times; i += threads)
{
Set(keys[i], val);
Set(keys[i % keys.Length], val);
}
}
else
Expand All @@ -552,7 +552,7 @@ protected virtual Int64 BenchSet(String[] keys, Int64 times, Int32 threads, Bool
var dic = new Dictionary<String, String>();
for (var i = k; i < times; i += threads)
{
dic[keys[i]] = val;
dic[keys[i % keys.Length]] = val;
n++;

if (n >= batch)
Expand Down Expand Up @@ -618,7 +618,7 @@ protected virtual Int64 BenchRemove(String[] keys, Int64 times, Int32 threads, B
{
for (var i = k; i < times; i += threads)
{
Remove(keys[i]);
Remove(keys[i % keys.Length]);
}
}
else
Expand All @@ -627,7 +627,7 @@ protected virtual Int64 BenchRemove(String[] keys, Int64 times, Int32 threads, B
var keys2 = new String[batch];
for (var i = k; i < times; i += threads)
{
keys2[n++] = keys[i];
keys2[n++] = keys[i % keys.Length];

if (n >= batch)
{
Expand Down Expand Up @@ -689,7 +689,7 @@ protected virtual Int64 BenchInc(String[] keys, Int64 times, Int32 threads, Bool
var val = Rand.Next(100);
for (var i = k; i < times; i += threads)
{
Increment(keys[i], val);
Increment(keys[i % keys.Length], val);
}

// 提交变更
Expand Down

0 comments on commit 4564a6e

Please sign in to comment.