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

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Nov 6, 2020
1 parent 0c39476 commit b67c772
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 81 deletions.
2 changes: 1 addition & 1 deletion src/ServiceStack.Redis/BasicRedisClientManager.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ValueTask IAsyncDisposable.DisposeAsync()
async Task<T> ICacheClientAsync.GetAsync<T>(string key, CancellationToken token)
{
await using var client = await GetReadOnlyCacheClientAsync(token).ConfigureAwait(false);
return await client.GetAsync<T>(key).ConfigureAwait(false);
return await client.GetAsync<T>(key, token).ConfigureAwait(false);
}

async Task<bool> ICacheClientAsync.SetAsync<T>(string key, T value, CancellationToken token)
Expand Down
117 changes: 37 additions & 80 deletions src/ServiceStack.Redis/BasicRedisClientManager.ICacheClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,152 +30,109 @@ namespace ServiceStack.Redis
public partial class BasicRedisClientManager
: ICacheClient
{
public ICacheClient GetCacheClient()
{
return new RedisClientManagerCacheClient(this);
}
public ICacheClient GetCacheClient() =>
new RedisClientManagerCacheClient(this);

public ICacheClient GetReadOnlyCacheClient()
{
return ConfigureRedisClient(this.GetReadOnlyClientImpl());
}
public ICacheClient GetReadOnlyCacheClient() =>
ConfigureRedisClient(this.GetReadOnlyClientImpl());

private ICacheClient ConfigureRedisClient(IRedisClient client)
{
return client;
}

#region Implementation of ICacheClient
private ICacheClient ConfigureRedisClient(IRedisClient client) => client;

public bool Remove(string key)
{
using (var client = GetReadOnlyCacheClient())
{
return client.Remove(key);
}
using var client = GetReadOnlyCacheClient();
return client.Remove(key);
}

public void RemoveAll(IEnumerable<string> keys)
{
using (var client = GetCacheClient())
{
client.RemoveAll(keys);
}
using var client = GetCacheClient();
client.RemoveAll(keys);
}

public T Get<T>(string key)
{
using (var client = GetReadOnlyCacheClient())
{
return client.Get<T>(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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
using var client = GetCacheClient();
return client.Replace(key, value, expiresIn);
}

public void FlushAll()
{
using (var client = GetCacheClient())
{
client.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);
}
using var client = GetReadOnlyCacheClient();
return client.GetAll<T>(keys);
}

#endregion
}


Expand Down

0 comments on commit b67c772

Please sign in to comment.