using OASystem.RedisRepository.CommonHelper;
using OASystem.RedisRepository.Config;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OASystem.RedisRepository.RedisAsyncHelper
{///
/// Redis异步操作类 String部分类
///
internal partial class RedisHelper : IRedisHelper
{
private static IDatabase _client;
internal RedisHelper()
{
_client = RedisConnection.GenerateConnection.GetDatabase();
}
#region String 写操作
///
/// 将任何数据添加到redis中
///
///
///
///
///
///
public async Task StringSetAsync(string key, T value, TimeSpan? timeout = null)
{
return await _client.StringSetAsync(key, SerializeHelper.Serialize(value), timeout);
}
public async Task StringDecrementAsync(string key, long value = 1L)
{
return await _client.StringDecrementAsync(key, value);
}
public async Task StringIncrementAsync(string key, long value = 1L)
{
return await _client.StringIncrementAsync(key, value);
}
#endregion
#region String 读操作
///
/// 根据key获取指定类型数据
///
///
///
///
public async Task StringGetAsync(string key)
{
return SerializeHelper.Deserialize(await _client.StringGetAsync(key, CommandFlags.PreferSlave));
}
#endregion
}
}