Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add reconnectAttempts #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
28 changes: 17 additions & 11 deletions Disque.Net/DisqueClient.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using CSRedis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CSRedis;

namespace Disque.Net
{
Expand All @@ -16,27 +16,30 @@ public class DisqueClient : ISyncDisqueClient, IDisposable
private IRedisClient _c;
private readonly IJobInfoBuilder _jobInfoBuilder;
private readonly IQstatBuilder _queueStatBuilder;
private readonly int _reconnectAttempts;

public DisqueClient() : this(new Uri(string.Format("{0}{1}:{2}", DISQUE_PROTOCOL, DISQUE_HOST, DISQUE_PORT)))
public DisqueClient(int reconnectAttempts = 0) : this(reconnectAttempts, new Uri(string.Format("{0}{1}:{2}", DISQUE_PROTOCOL, DISQUE_HOST, DISQUE_PORT)))
{

}

public DisqueClient(string host, int port) : this(new Uri(string.Format("{0}{1}:{2}", DISQUE_PROTOCOL, host, port)))
public DisqueClient(string host, int port, int reconnectAttempts = 0) : this(reconnectAttempts, new Uri(string.Format("{0}{1}:{2}", DISQUE_PROTOCOL, host, port)))
{

}

public DisqueClient(params Uri[] uris) : this(uris.ToList())
{
}

public DisqueClient(int reconnectAttempts = 0, params Uri[] uris) : this(uris.ToList(), reconnectAttempts)
{
}

public DisqueClient(List<Uri> uris)
public DisqueClient(List<Uri> uris, int reconnectAttempts = 0)
{
_uris.AddRange(uris);
_jobInfoBuilder = new JobInfoBuilder();
_queueStatBuilder = new QstatBuilder();
_reconnectAttempts = reconnectAttempts;
Connect();
}

Expand All @@ -53,15 +56,18 @@ private void Connect()
try
{
Uri uri = _uris[index];
_c = new RedisClient(uri.Host, uri.Port);
_c = new RedisClient(uri.Host, uri.Port)
{
ReconnectAttempts = _reconnectAttempts
};
}
catch (Exception e)
{
_uris.RemoveAt(index);
}
}
}

public string Info()
{
return (string)_c.Call(Commands.INFO.ToString());
Expand Down Expand Up @@ -181,7 +187,7 @@ public List<Job> Qpeek(string queueName, long count)
object call = _c.Call(Commands.QPEEK.ToString(), queueName, count.ToString());

object[] objects = call as object[];

ParseGetJobResponse(objects, result);

return result;
Expand Down Expand Up @@ -291,4 +297,4 @@ private static string Conv(object b)
return str ?? Encoding.UTF8.GetString((byte[])b);
}
}
}
}