Created
October 23, 2013 14:22
-
-
Save glikoz/7119769 to your computer and use it in GitHub Desktop.
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
[DependencyRegisterar(Lifetime = LifetimeManagers.PerRequest)] | |
public class RedisRepository : IRedisClientsManager, IBasicPersistenceProvider | |
{ | |
#region Members | |
private const string CONFIGURATION_PREFIX = "cfg:"; | |
private const string PERFORMANCE_PREFIX = "prf:"; | |
private const string HASHSET_PREFIX = "set:"; | |
private IRedisClientsManager _Manager; | |
#endregion | |
#region Properties | |
/// <summary> | |
/// Gets the current Redis Repository | |
/// </summary> | |
public static RedisRepository Current | |
{ | |
get | |
{ | |
return Core.Resolve<RedisRepository>(); | |
} | |
} | |
/// <summary> | |
/// Gets the Redis clients manager | |
/// </summary> | |
public IRedisClientsManager Manager | |
{ | |
get | |
{ | |
return _Manager; | |
} | |
} | |
#endregion | |
#region Initialization | |
/// <summary> | |
/// Initialize a new instance of this class | |
/// </summary> | |
/// <param name="manager"></param> | |
public RedisRepository(IRedisClientsManager manager) | |
{ | |
_Manager = manager; | |
} | |
#endregion | |
#region Public Methods | |
public IDisposable GetLock(LockEnum lockEnum, TimeSpan timeout) | |
{ | |
return _Manager.GetClient().AcquireLock(lockEnum.ToString(), timeout); | |
} | |
public long GetAid(string code) | |
{ | |
using (var context = CreateOperationContext()) | |
{ | |
return context.Client.IncrementValue("aid:" + code); | |
} | |
} | |
public IEnumerable<T> GetValuesFromHashes<T>(IEnumerable<string> hashIds, string key) | |
{ | |
//TODO: Performance optimization | |
List<T> result = new List<T>(); | |
using (var context = CreateOperationContext()) | |
{ | |
foreach (var hash in hashIds) | |
{ | |
result.Add(GetHashItem<T>(hash, key)); | |
} | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment