Abstract away redis even more with AlmostRedis.cs
This commit is contained in:
parent
f53258e348
commit
35f0a5c8f8
10 changed files with 153 additions and 78 deletions
44
Geekbot.net/Lib/AlmostRedis/AlmostRedis.cs
Normal file
44
Geekbot.net/Lib/AlmostRedis/AlmostRedis.cs
Normal file
|
@ -0,0 +1,44 @@
|
|||
using System.Collections.Generic;
|
||||
using Geekbot.net.Lib.Logger;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Geekbot.net.Lib.AlmostRedis
|
||||
{
|
||||
// if anyone ever sees this, please come up with a better fucking name, i'd appriciate it
|
||||
public class AlmostRedis : IAlmostRedis
|
||||
{
|
||||
private readonly GeekbotLogger _logger;
|
||||
private readonly RunParameters _runParameters;
|
||||
private IDatabase _database;
|
||||
private ConnectionMultiplexer _connection;
|
||||
private IAlmostRedis _almostRedisImplementation;
|
||||
|
||||
public AlmostRedis(GeekbotLogger logger, RunParameters runParameters)
|
||||
{
|
||||
_logger = logger;
|
||||
_runParameters = runParameters;
|
||||
}
|
||||
|
||||
public void Connect()
|
||||
{
|
||||
_connection = ConnectionMultiplexer.Connect($"{_runParameters.RedisHost}:{_runParameters.RedisPort}");
|
||||
_database = _connection.GetDatabase(int.Parse(_runParameters.RedisDatabase));
|
||||
_logger.Information(LogSource.Redis, $"Connected to Redis on {_connection.Configuration} at {_database.Database}");
|
||||
}
|
||||
|
||||
public IDatabase Db
|
||||
{
|
||||
get { return _database; }
|
||||
}
|
||||
|
||||
public ConnectionMultiplexer Connection
|
||||
{
|
||||
get { return _connection; }
|
||||
}
|
||||
|
||||
public IEnumerable<RedisKey> GetAllKeys()
|
||||
{
|
||||
return _connection.GetServer($"{_runParameters.RedisHost}:{_runParameters.RedisPort}", int.Parse(_runParameters.RedisDatabase)).Keys();
|
||||
}
|
||||
}
|
||||
}
|
13
Geekbot.net/Lib/AlmostRedis/IAlmostRedis.cs
Normal file
13
Geekbot.net/Lib/AlmostRedis/IAlmostRedis.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using System.Collections.Generic;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Geekbot.net.Lib.AlmostRedis
|
||||
{
|
||||
public interface IAlmostRedis
|
||||
{
|
||||
void Connect();
|
||||
IDatabase Db { get; }
|
||||
ConnectionMultiplexer Connection { get; }
|
||||
IEnumerable<RedisKey> GetAllKeys();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue