Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 2a2355e

Browse files
authored
Merge pull request #239 from joelharkes/master
Fixed Interface usage IRemoveByPattern | Add documentation | Tiny perf on removeByPattern
2 parents 0b1fcf7 + 49bad8a commit 2a2355e

File tree

5 files changed

+33
-12
lines changed

5 files changed

+33
-12
lines changed

src/ServiceStack.Redis/RedisClient.ICacheClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
namespace ServiceStack.Redis
2121
{
2222
public partial class RedisClient
23-
: ICacheClient, IRemoveByPattern
23+
: ICacheClient
2424
{
2525
public T Exec<T>(Func<RedisClient, T> action)
2626
{

src/ServiceStack.Redis/RedisClient.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using ServiceStack.Redis.Generic;
2020
using ServiceStack.Redis.Pipeline;
2121
using ServiceStack.Text;
22+
using ServiceStack.Caching;
2223

2324
namespace ServiceStack.Redis
2425
{
@@ -30,7 +31,7 @@ namespace ServiceStack.Redis
3031
/// RedisClient.Sets => ICollection[string]
3132
/// </summary>
3233
public partial class RedisClient
33-
: RedisNativeClient, IRedisClient
34+
: RedisNativeClient, IRedisClient, IRemoveByPattern // IRemoveByPattern is implemented in this file.
3435
{
3536
public RedisClient()
3637
{
@@ -990,9 +991,9 @@ public string LoadLuaScript(string body)
990991

991992
public void RemoveByPattern(string pattern)
992993
{
993-
List<string> keys = Keys(pattern).ToStringList();
994-
if (keys.Count > 0)
995-
Del(keys.ToArray());
994+
var keys = Keys(pattern).ToStringArray();
995+
if (keys.Length > 0)
996+
Del(keys);
996997
}
997998

998999
public void RemoveByRegex(string pattern)
@@ -1118,6 +1119,7 @@ private static RedisServerRole ToServerRole(string roleName)
11181119
return RedisServerRole.Unknown;
11191120
}
11201121
}
1122+
11211123
}
11221124

11231125
}

src/ServiceStack.Redis/RedisClientManagerCacheClient.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,24 @@ public void RemoveByPattern(string pattern)
181181
{
182182
using (var client = GetClient())
183183
{
184-
var redisClient = client as RedisClient;
184+
var redisClient = client as IRemoveByPattern;
185185
if (redisClient != null)
186186
{
187-
List<string> keys = redisClient.Keys(pattern).ToStringList();
188-
if (keys.Count > 0)
189-
redisClient.Del(keys.ToArray());
187+
redisClient.RemoveByPattern(pattern);
190188
}
191189
}
192190
}
193191

194192
public void RemoveByRegex(string pattern)
195193
{
196-
RemoveByPattern(pattern.Replace(".*", "*").Replace(".+", "?"));
194+
using (var client = GetClient())
195+
{
196+
var redisClient = client as IRemoveByPattern;
197+
if (redisClient != null)
198+
{
199+
redisClient.RemoveByRegex(pattern);
200+
}
201+
}
197202
}
198203

199204
public TimeSpan? GetTimeToLive(string key)

src/ServiceStack.Redis/RedisManagerPool.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,30 @@
1111

1212
namespace ServiceStack.Redis
1313
{
14+
///<summary>
15+
/// Configuration class for the RedisManagerPool
16+
///</summary>
1417
public class RedisPoolConfig
1518
{
19+
/// <summary>
20+
/// Default pool size used by every new instance of <see cref="RedisPoolConfig"/>. (default: 40)
21+
/// </summary>
1622
public static int DefaultMaxPoolSize = 40;
1723

1824
public RedisPoolConfig()
1925
{
26+
// maybe a bit overkill? could be deprecated if you add max int on RedisManagerPool
2027
MaxPoolSize = RedisConfig.DefaultMaxPoolSize ?? DefaultMaxPoolSize;
2128
}
2229

30+
/// <summary>
31+
/// Maximum ammount of <see cref="ICacheClient"/>s created by the <see cref="RedisManagerPool"/>.
32+
/// </summary>
2333
public int MaxPoolSize { get; set; }
2434
}
2535

2636
/// <summary>
27-
/// Provides thread-safe pooling of redis client connections.
37+
/// Provides thread-safe pooling of redis client connections. All connections are treaded as read and write hosts.
2838
/// </summary>
2939
public partial class RedisManagerPool
3040
: IRedisClientsManager, IRedisFailover, IHandleClientDispose, IHasRedisResolver

src/ServiceStack.Redis/RedisNativeClient.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ namespace ServiceStack.Redis
2828
/// This class contains all the common operations for the RedisClient.
2929
/// The client contains a 1:1 mapping of c# methods to redis operations of the same name.
3030
///
31-
/// Not threadsafe use a pooled manager
31+
/// Not threadsafe, use a pooled manager!
32+
/// All redis calls on a single instances write to the same Socket.
33+
/// If used in multiple threads (or async Tasks) at the same time you will find
34+
/// that commands are not executed properly by redis and Servicestack wont be able to (json) serialize
35+
/// the data that comes back.
3236
/// </summary>
3337
public partial class RedisNativeClient
3438
: IRedisNativeClient

0 commit comments

Comments
 (0)