Skip to content

Commit

Permalink
redis: fix connections
Browse files Browse the repository at this point in the history
  • Loading branch information
jalalmostafa committed Feb 28, 2024
1 parent 82f08cb commit 884ec29
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion BenchmarkTool/ClientRead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ClientRead()
_minutes = Config.GetDurationMinutes();

var dbFactory = new DatabaseFactory();
_targetDb = dbFactory.Create();
_targetDb = dbFactory.Create(1, 0, 0);
_targetDb.Init();
}
catch (Exception ex)
Expand Down
2 changes: 1 addition & 1 deletion BenchmarkTool/ClientWrite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ClientWrite(int index, int clientsNumber, int sensorNumber, int batchSize
_date = date;
_daySpan = Config.GetDaySpan();
var dbFactory = new DatabaseFactory();
_targetDb = dbFactory.Create();
_targetDb = dbFactory.Create(ClientsNumber, SensorsNumber, BatchSize);
_targetDb.Init();
}
catch (Exception ex)
Expand Down
4 changes: 2 additions & 2 deletions BenchmarkTool/Database/DatabaseFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public DatabaseFactory()
_database = Config.GetTargetDatabase();
}

public IDatabase Create()
public IDatabase Create(int clientsNumber, int sensorsNumber, int batchSize)
{
switch (_database)
{
Expand All @@ -27,7 +27,7 @@ public IDatabase Create()
case Constants.MySQLClass:
return new MySQLDB();
case Constants.RedisTimeSeriesClass:
return new RedisTimeSeriesDB();
return new RedisTimeSeriesDB(clientsNumber, sensorsNumber, batchSize);
default:
throw new NotImplementedException();
}
Expand Down
25 changes: 19 additions & 6 deletions BenchmarkTool/Database/RedisTimeSeriesDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@ public class RedisTimeSeriesDB : IDatabase
{
private static bool _initialized = false;

private SERedis.ConnectionMultiplexer _connection;
private static ConnectionMultiplexer _connection;
private SERedis.IDatabase _redisDB;
private TimeSeriesCommands _redists;

private int _aggInterval;
private int _clientsNumber;
private int _sensorsNumber;
private int _batchSize;

public RedisTimeSeriesDB(int clientsNumber, int sensorsNumber, int batchSize)
{
_clientsNumber = clientsNumber;
_sensorsNumber = sensorsNumber;
_batchSize = batchSize;
}

public void Cleanup()
{
Expand All @@ -46,12 +56,15 @@ public void Init()
{
try
{
var options = new ConfigurationOptions()
if (_connection == null)
{
SocketManager = new SocketManager("test", 1),
EndPoints = { { Config.GetRedisHost(), Config.GetRedisPort() } },
};
_connection = ConnectionMultiplexer.Connect(options);
var options = new ConfigurationOptions()
{
SocketManager = new SocketManager("test", _clientsNumber),
EndPoints = { { Config.GetRedisHost(), Config.GetRedisPort() } },
};
_connection = ConnectionMultiplexer.Connect(options);
}
_redisDB = _connection.GetDatabase();
_redists = _redisDB.TS();
if (!_initialized)
Expand Down

0 comments on commit 884ec29

Please sign in to comment.