NewLife/X

[fix] 修正Redis缓存压缩次数过大时,keys数组索引越界的问题
大石头 authored at 2024-11-25 20:00:09
4564a6e
Tree
1 Parent(s) 67de80f
Summary: 1 changed files with 7 additions and 7 deletions.
Modified +7 -7
Modified +7 -7
diff --git a/NewLife.Core/Caching/Cache.cs b/NewLife.Core/Caching/Cache.cs
index fd4dac1..b7d4a59 100644
--- a/NewLife.Core/Caching/Cache.cs
+++ b/NewLife.Core/Caching/Cache.cs
@@ -477,7 +477,7 @@ public abstract class Cache : DisposeBase, ICache
                 {
                     for (var i = k; i < times; i += threads)
                     {
-                        var val = Get<String>(keys[i]);
+                        var val = Get<String>(keys[i % keys.Length]);
                     }
                 }
                 else
@@ -486,7 +486,7 @@ public abstract class Cache : DisposeBase, ICache
                     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)
                         {
@@ -543,7 +543,7 @@ public abstract class Cache : DisposeBase, ICache
                 {
                     for (var i = k; i < times; i += threads)
                     {
-                        Set(keys[i], val);
+                        Set(keys[i % keys.Length], val);
                     }
                 }
                 else
@@ -552,7 +552,7 @@ public abstract class Cache : DisposeBase, ICache
                     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)
@@ -618,7 +618,7 @@ public abstract class Cache : DisposeBase, ICache
                 {
                     for (var i = k; i < times; i += threads)
                     {
-                        Remove(keys[i]);
+                        Remove(keys[i % keys.Length]);
                     }
                 }
                 else
@@ -627,7 +627,7 @@ public abstract class Cache : DisposeBase, ICache
                     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)
                         {
@@ -689,7 +689,7 @@ public abstract class Cache : DisposeBase, ICache
                 var val = Rand.Next(100);
                 for (var i = k; i < times; i += threads)
                 {
-                    Increment(keys[i], val);
+                    Increment(keys[i % keys.Length], val);
                 }
 
                 // 提交变更