Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/NLog.Redis.Tests/RedisTargetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ namespace NLog.Redis.Tests
public class RedisTargetTests
{
protected const string RedisKey = "testkey";
protected const string RedisHost = "localhost";
protected const int RedisPort = 6379;
protected const string RedisHosts = "localhost:6379";
protected const string RedisPassword = "testingpassword";
protected string Password = null;

Expand All @@ -42,8 +41,7 @@ public void NLogRedisConfiguration(string dataType, bool usePassword = false)

// set target properties
redisTarget.Layout = "${uppercase:${level}} ${message}";
redisTarget.Host = RedisHost;
redisTarget.Port = RedisPort;
redisTarget.Hosts = RedisHosts;
redisTarget.Key = RedisKey;
redisTarget.Db = 0;
redisTarget.DataType = dataType;
Expand All @@ -68,7 +66,8 @@ public ConnectionMultiplexer GetRedisConnection(bool usePassword = false)
};
if (usePassword) connectionOptions.Password = RedisPassword;

connectionOptions.EndPoints.Add(RedisHost, RedisPort);
foreach(var host in RedisHosts.Split(','))
connectionOptions.EndPoints.Add(host);

return ConnectionMultiplexer.Connect(connectionOptions);
}
Expand Down
2 changes: 1 addition & 1 deletion src/NLog.Redis/NLog.Redis.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<projectUrl>https://github.com/richclement/NLog.Redis</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>1.0.2 - Update dependencies</releaseNotes>
<releaseNotes>1.0.3 - Support for master/slave configuration</releaseNotes>
<copyright>Copyright 2014</copyright>
<tags>NLog Redis</tags>
<dependencies>
Expand Down
4 changes: 2 additions & 2 deletions src/NLog.Redis/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.2.0")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyVersion("1.0.3.1")]
[assembly: AssemblyFileVersion("1.0.3.1")]
23 changes: 18 additions & 5 deletions src/NLog.Redis/RedisConnectionManager.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
using System;
using StackExchange.Redis;
using System.Collections.Generic;

namespace NLog.Targets
{
internal class RedisConnectionManager : IDisposable
{
private ConnectionMultiplexer _connectionMultiplexer;

private readonly string _host;
private readonly int _port;
private readonly List<string> _hosts;
private readonly int _db;
private readonly string _password;

public RedisConnectionManager(List<string> hosts, int db, string password)
{
_hosts = hosts;
_db = db;
_password = password;

InitializeConnection();
}

[Obsolete("Use constructor with hosts instead")]
public RedisConnectionManager(string host, int port, int db, string password)
{
_host = host;
_port = port;
_hosts = new List<string>();
_hosts.Add($"{host}:{port}");
_db = db;
_password = password;

Expand All @@ -32,7 +42,10 @@ private void InitializeConnection()
ConnectRetry = 3,
KeepAlive = 5
};
connectionOptions.EndPoints.Add(_host, _port);
foreach (var host in _hosts)
{
connectionOptions.EndPoints.Add(host);
}

if (!string.IsNullOrEmpty(_password))
{
Expand Down
17 changes: 14 additions & 3 deletions src/NLog.Redis/RedisTarget.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using NLog.Config;
using System.Linq;

namespace NLog.Targets
{
Expand All @@ -12,15 +13,20 @@ public class RedisTarget : TargetWithLayout
/// <summary>
/// Sets the host name or IP Address of the redis server
/// </summary>
[RequiredParameter]
[Obsolete("Use hosts instead")]
public string Host { get; set; }

/// <summary>
/// Sets the port number redis is running on
/// </summary>
[RequiredParameter]
[Obsolete("Use hosts instead")]
public int Port { get; set; }

/// <summary>
/// Sets the hosts names or IP Addresses and ports of the redis servers
/// </summary>
public string Hosts { get; set; }

/// <summary>
/// Sets the key to be used for either the list or the pub/sub channel in redis
/// </summary>
Expand Down Expand Up @@ -53,7 +59,12 @@ protected override void InitializeTarget()
{
base.InitializeTarget();

_redisConnectionManager = new RedisConnectionManager(Host, Port, Db, Password);
if (!string.IsNullOrWhiteSpace(Host))
_redisConnectionManager = new RedisConnectionManager(Host, Port, Db, Password);
else if (!string.IsNullOrWhiteSpace(Hosts))
_redisConnectionManager = new RedisConnectionManager(Hosts.Split(',').ToList(), Db, Password);
else
throw new ArgumentException("At least a host must be set");
}

protected override void CloseTarget()
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetPack.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.\.nuget\NuGet.exe pack -Symbols .\NLog.Redis\NLog.Redis.csproj
.\.nuget\NuGet.exe pack -Symbols .\NLog.Redis\NLog.Redis.csproj -Prop Configuration=Release