This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 876
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
149 changed files
with
24,970 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 10.00 | ||
# Visual Studio 2008 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{38F69F8F-9303-4BAF-B081-D28339163E07}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceStack.Redis", "src\ServiceStack.Redis\ServiceStack.Redis.csproj", "{AF99F19B-4C04-4F58-81EF-B092F1FCC540}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceStack.Redis.Tests", "tests\ServiceStack.Redis.Tests\ServiceStack.Redis.Tests.csproj", "{951D28EE-5D22-4C62-AC0F-1661A8CEEC5A}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
MonoTouch|Any CPU = MonoTouch|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
STATIC_ONLY NO_EXPRESSIONS|Any CPU = STATIC_ONLY NO_EXPRESSIONS|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{AF99F19B-4C04-4F58-81EF-B092F1FCC540}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{AF99F19B-4C04-4F58-81EF-B092F1FCC540}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{AF99F19B-4C04-4F58-81EF-B092F1FCC540}.MonoTouch|Any CPU.ActiveCfg = MonoTouch|Any CPU | ||
{AF99F19B-4C04-4F58-81EF-B092F1FCC540}.MonoTouch|Any CPU.Build.0 = MonoTouch|Any CPU | ||
{AF99F19B-4C04-4F58-81EF-B092F1FCC540}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{AF99F19B-4C04-4F58-81EF-B092F1FCC540}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{AF99F19B-4C04-4F58-81EF-B092F1FCC540}.STATIC_ONLY NO_EXPRESSIONS|Any CPU.ActiveCfg = STATIC_ONLY NO_EXPRESSIONS|Any CPU | ||
{AF99F19B-4C04-4F58-81EF-B092F1FCC540}.STATIC_ONLY NO_EXPRESSIONS|Any CPU.Build.0 = STATIC_ONLY NO_EXPRESSIONS|Any CPU | ||
{951D28EE-5D22-4C62-AC0F-1661A8CEEC5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{951D28EE-5D22-4C62-AC0F-1661A8CEEC5A}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{951D28EE-5D22-4C62-AC0F-1661A8CEEC5A}.MonoTouch|Any CPU.ActiveCfg = MonoTouch|Any CPU | ||
{951D28EE-5D22-4C62-AC0F-1661A8CEEC5A}.MonoTouch|Any CPU.Build.0 = MonoTouch|Any CPU | ||
{951D28EE-5D22-4C62-AC0F-1661A8CEEC5A}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{951D28EE-5D22-4C62-AC0F-1661A8CEEC5A}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{951D28EE-5D22-4C62-AC0F-1661A8CEEC5A}.STATIC_ONLY NO_EXPRESSIONS|Any CPU.ActiveCfg = STATIC_ONLY NO_EXPRESSIONS|Any CPU | ||
{951D28EE-5D22-4C62-AC0F-1661A8CEEC5A}.STATIC_ONLY NO_EXPRESSIONS|Any CPU.Build.0 = STATIC_ONLY NO_EXPRESSIONS|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
SET DEPLOY_PATH=C:\src\ServiceStack\release\latest\ServiceStack.Redis | ||
|
||
REM SET BUILD=Debug | ||
SET BUILD=Release | ||
|
||
SET PROJ_LIBS= | ||
SET PROJ_LIBS=%PROJ_LIBS% ..\lib\ServiceStack.Interfaces.dll | ||
SET PROJ_LIBS=%PROJ_LIBS% ..\lib\ServiceStack.Client.dll | ||
SET PROJ_LIBS=%PROJ_LIBS% ..\lib\ServiceStack.Common.dll | ||
SET PROJ_LIBS=%PROJ_LIBS% ..\lib\ServiceStack.Text.dll | ||
SET PROJ_LIBS=%PROJ_LIBS% ..\lib\ServiceStack.Messaging.dll | ||
SET PROJ_LIBS=%PROJ_LIBS% ..\src\ServiceStack.Redis\bin\%BUILD%\ServiceStack.Redis.dll | ||
|
||
ILMerge.exe /ndebug /t:library /out:ServiceStack.Redis.dll %PROJ_LIBS% | ||
|
||
COPY *.dll %DEPLOY_PATH% |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
191 changes: 191 additions & 0 deletions
191
src/ServiceStack.Redis/BasicRedisClientManager.ICacheClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
// | ||
// https://github.com/mythz/ServiceStack.Redis | ||
// ServiceStack.Redis: ECMA CLI Binding to the Redis key-value storage system | ||
// | ||
// Authors: | ||
// Demis Bellot (demis.bellot@gmail.com) | ||
// | ||
// Copyright 2010 Liquidbit Ltd. | ||
// | ||
// Licensed under the same terms of Redis and ServiceStack: new BSD license. | ||
// | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using ServiceStack.CacheAccess; | ||
|
||
namespace ServiceStack.Redis | ||
{ | ||
/// <summary> | ||
/// BasicRedisClientManager for ICacheClient | ||
/// | ||
/// For more interoperabilty I'm also implementing the ICacheClient on | ||
/// this cache client manager which has the affect of calling | ||
/// GetCacheClient() for all write operations and GetReadOnlyCacheClient() | ||
/// for the read ones. | ||
/// | ||
/// This works well for master-slave replication scenarios where you have | ||
/// 1 master that replicates to multiple read slaves. | ||
/// </summary> | ||
public partial class BasicRedisClientManager | ||
: ICacheClient | ||
{ | ||
public const int DefaultCacheDb = 9; | ||
|
||
public ICacheClient GetCacheClient() | ||
{ | ||
return ConfigureRedisClient(this.GetClient()); | ||
} | ||
|
||
public ICacheClient GetReadOnlyCacheClient() | ||
{ | ||
return ConfigureRedisClient(this.GetReadOnlyClient()); | ||
} | ||
|
||
private ICacheClient ConfigureRedisClient(IRedisClient client) | ||
{ | ||
//Provide automatic partitioning of 'Redis Caches' from normal persisted data | ||
//which is on DB '0' by default. | ||
var notUserSpecified = this.Db == RedisNativeClient.DefaultDb; | ||
if (notUserSpecified) | ||
{ | ||
client.Db = DefaultCacheDb; | ||
} | ||
return client; | ||
} | ||
|
||
#region Implementation of ICacheClient | ||
|
||
public bool Remove(string key) | ||
{ | ||
using (var client = GetReadOnlyCacheClient()) | ||
{ | ||
return client.Remove(key); | ||
} | ||
} | ||
|
||
public void RemoveAll(IEnumerable<string> keys) | ||
{ | ||
using (var client = GetCacheClient()) | ||
{ | ||
client.RemoveAll(keys); | ||
} | ||
} | ||
|
||
public T Get<T>(string key) | ||
{ | ||
using (var client = GetReadOnlyCacheClient()) | ||
{ | ||
return client.Get<T>(key); | ||
} | ||
} | ||
|
||
public long Increment(string key, uint amount) | ||
{ | ||
using (var client = GetCacheClient()) | ||
{ | ||
return client.Increment(key, amount); | ||
} | ||
} | ||
|
||
public long Decrement(string key, uint amount) | ||
{ | ||
using (var client = GetCacheClient()) | ||
{ | ||
return client.Decrement(key, amount); | ||
} | ||
} | ||
|
||
public bool Add<T>(string key, T value) | ||
{ | ||
using (var client = GetCacheClient()) | ||
{ | ||
return client.Add(key, value); | ||
} | ||
} | ||
|
||
public bool Set<T>(string key, T value) | ||
{ | ||
using (var client = GetCacheClient()) | ||
{ | ||
return client.Set(key, value); | ||
} | ||
} | ||
|
||
public bool Replace<T>(string key, T value) | ||
{ | ||
using (var client = GetCacheClient()) | ||
{ | ||
return client.Replace(key, value); | ||
} | ||
} | ||
|
||
public bool Add<T>(string key, T value, DateTime expiresAt) | ||
{ | ||
using (var client = GetCacheClient()) | ||
{ | ||
return client.Add(key, value, expiresAt); | ||
} | ||
} | ||
|
||
public bool Set<T>(string key, T value, DateTime expiresAt) | ||
{ | ||
using (var client = GetCacheClient()) | ||
{ | ||
return client.Set(key, value, expiresAt); | ||
} | ||
} | ||
|
||
public bool Replace<T>(string key, T value, DateTime expiresAt) | ||
{ | ||
using (var client = GetCacheClient()) | ||
{ | ||
return client.Replace(key, value, expiresAt); | ||
} | ||
} | ||
|
||
public bool Add<T>(string key, T value, TimeSpan expiresIn) | ||
{ | ||
using (var client = GetCacheClient()) | ||
{ | ||
return client.Add(key, value, expiresIn); | ||
} | ||
} | ||
|
||
public bool Set<T>(string key, T value, TimeSpan expiresIn) | ||
{ | ||
using (var client = GetCacheClient()) | ||
{ | ||
return client.Set(key, value, expiresIn); | ||
} | ||
} | ||
|
||
public bool Replace<T>(string key, T value, TimeSpan expiresIn) | ||
{ | ||
using (var client = GetCacheClient()) | ||
{ | ||
return client.Replace(key, value, expiresIn); | ||
} | ||
} | ||
|
||
public void FlushAll() | ||
{ | ||
using (var client = GetCacheClient()) | ||
{ | ||
client.FlushAll(); | ||
} | ||
} | ||
|
||
public IDictionary<string, T> GetAll<T>(IEnumerable<string> keys) | ||
{ | ||
using (var client = GetReadOnlyCacheClient()) | ||
{ | ||
return client.GetAll<T>(keys); | ||
} | ||
} | ||
|
||
#endregion | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// | ||
// https://github.com/mythz/ServiceStack.Redis | ||
// ServiceStack.Redis: ECMA CLI Binding to the Redis key-value storage system | ||
// | ||
// Authors: | ||
// Demis Bellot (demis.bellot@gmail.com) | ||
// | ||
// Copyright 2010 Liquidbit Ltd. | ||
// | ||
// Licensed under the same terms of Redis and ServiceStack: new BSD license. | ||
// | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using ServiceStack.Common.Web; | ||
|
||
namespace ServiceStack.Redis | ||
{ | ||
/// <summary> | ||
/// Provides thread-safe retrievel of redis clients since each client is a new one. | ||
/// Allows the configuration of different ReadWrite and ReadOnly hosts | ||
/// </summary> | ||
public partial class BasicRedisClientManager | ||
: IRedisClientsManager | ||
{ | ||
private List<EndPoint> ReadWriteHosts { get; set; } | ||
private List<EndPoint> ReadOnlyHosts { get; set; } | ||
|
||
private int readWriteHostsIndex; | ||
private int readOnlyHostsIndex; | ||
|
||
public IRedisClientFactory RedisClientFactory { get; set; } | ||
|
||
public int Db { get; private set; } | ||
|
||
public BasicRedisClientManager() : this(RedisNativeClient.DefaultHost) { } | ||
|
||
public BasicRedisClientManager(params string[] readWriteHosts) | ||
: this(readWriteHosts, readWriteHosts) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Hosts can be an IP Address or Hostname in the format: host[:port] | ||
/// e.g. 127.0.0.1:6379 | ||
/// default is: localhost:6379 | ||
/// </summary> | ||
/// <param name="readWriteHosts">The write hosts.</param> | ||
/// <param name="readOnlyHosts">The read hosts.</param> | ||
public BasicRedisClientManager( | ||
IEnumerable<string> readWriteHosts, | ||
IEnumerable<string> readOnlyHosts) | ||
: this(readWriteHosts, readOnlyHosts, RedisNativeClient.DefaultDb) | ||
{ | ||
} | ||
|
||
public BasicRedisClientManager( | ||
IEnumerable<string> readWriteHosts, | ||
IEnumerable<string> readOnlyHosts, | ||
int initalDb) | ||
{ | ||
this.Db = initalDb; | ||
|
||
ReadWriteHosts = readWriteHosts.ToIpEndPoints(); | ||
ReadOnlyHosts = readOnlyHosts.ToIpEndPoints(); | ||
|
||
this.RedisClientFactory = Redis.RedisClientFactory.Instance; | ||
|
||
this.OnStart(); | ||
} | ||
|
||
protected virtual void OnStart() | ||
{ | ||
this.Start(); | ||
} | ||
|
||
/// <summary> | ||
/// Returns a Read/Write client (The default) using the hosts defined in ReadWriteHosts | ||
/// </summary> | ||
/// <returns></returns> | ||
public IRedisClient GetClient() | ||
{ | ||
var nextHost = ReadWriteHosts[readWriteHostsIndex++ % ReadWriteHosts.Count]; | ||
var client = RedisClientFactory.CreateRedisClient( | ||
nextHost.Host, nextHost.Port); | ||
|
||
//Set database to userSpecified if different | ||
if (Db != RedisNativeClient.DefaultDb) | ||
{ | ||
client.Db = Db; | ||
} | ||
|
||
return client; | ||
} | ||
|
||
/// <summary> | ||
/// Returns a ReadOnly client using the hosts defined in ReadOnlyHosts. | ||
/// </summary> | ||
/// <returns></returns> | ||
public virtual IRedisClient GetReadOnlyClient() | ||
{ | ||
var nextHost = ReadOnlyHosts[readOnlyHostsIndex++ % ReadOnlyHosts.Count]; | ||
var client = RedisClientFactory.CreateRedisClient( | ||
nextHost.Host, nextHost.Port); | ||
|
||
//Set database to userSpecified if different | ||
if (Db != RedisNativeClient.DefaultDb) | ||
{ | ||
client.Db = Db; | ||
} | ||
|
||
return client; | ||
} | ||
|
||
public void SetAll<T>(IDictionary<string, T> values) | ||
{ | ||
foreach (var entry in values) | ||
{ | ||
Set(entry.Key, entry.Value); | ||
} | ||
} | ||
|
||
public void Start() | ||
{ | ||
readWriteHostsIndex = 0; | ||
readOnlyHostsIndex = 0; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
} | ||
} |
Oops, something went wrong.