2017-09-12 20:27:51 +00:00
|
|
|
|
using StackExchange.Redis;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Services.Impl
|
|
|
|
|
{
|
|
|
|
|
public class RedisCache : IDataCache
|
|
|
|
|
{
|
2017-09-22 22:42:15 +00:00
|
|
|
|
private ulong _botid;
|
|
|
|
|
|
2017-09-13 01:12:40 +00:00
|
|
|
|
public ConnectionMultiplexer Redis { get; }
|
2017-09-12 20:27:51 +00:00
|
|
|
|
private readonly IDatabase _db;
|
|
|
|
|
|
2017-09-22 22:42:15 +00:00
|
|
|
|
public RedisCache(ulong botId)
|
2017-09-12 20:27:51 +00:00
|
|
|
|
{
|
2017-09-22 22:42:15 +00:00
|
|
|
|
_botid = botId;
|
2017-09-14 17:37:41 +00:00
|
|
|
|
Redis = ConnectionMultiplexer.Connect("127.0.0.1");
|
2017-09-13 01:12:40 +00:00
|
|
|
|
Redis.PreserveAsyncOrder = false;
|
|
|
|
|
_db = Redis.GetDatabase();
|
2017-09-12 20:27:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<(bool Success, byte[] Data)> TryGetImageDataAsync(string key)
|
|
|
|
|
{
|
|
|
|
|
byte[] x = await _db.StringGetAsync("image_" + key);
|
|
|
|
|
return (x != null, x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task SetImageDataAsync(string key, byte[] data)
|
|
|
|
|
{
|
|
|
|
|
return _db.StringSetAsync("image_" + key, data);
|
|
|
|
|
}
|
2017-09-15 00:42:51 +00:00
|
|
|
|
|
|
|
|
|
public async Task<(bool Success, string Data)> TryGetAnimeDataAsync(string key)
|
|
|
|
|
{
|
|
|
|
|
string x = await _db.StringGetAsync("anime_" + key);
|
|
|
|
|
return (x != null, x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task SetAnimeDataAsync(string key, string data)
|
|
|
|
|
{
|
|
|
|
|
return _db.StringSetAsync("anime_" + key, data);
|
|
|
|
|
}
|
2017-09-12 20:27:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|