forked from ServiceStack/ServiceStack.Redis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedisEndpoint.cs
More file actions
125 lines (114 loc) · 4.95 KB
/
RedisEndpoint.cs
File metadata and controls
125 lines (114 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using ServiceStack.IO;
using ServiceStack.Text;
namespace ServiceStack.Redis
{
public class RedisEndpoint : IEndpoint
{
public RedisEndpoint()
{
Host = RedisConfig.DefaultHost;
Port = RedisConfig.DefaultPort;
Db = RedisConfig.DefaultDb;
ConnectTimeout = RedisConfig.DefaultConnectTimeout;
SendTimeout = RedisConfig.DefaultSendTimeout;
ReceiveTimeout = RedisConfig.DefaultReceiveTimeout;
RetryTimeout = RedisConfig.DefaultRetryTimeout;
IdleTimeOutSecs = RedisConfig.DefaultIdleTimeOutSecs;
}
public RedisEndpoint(string host, int port, string password = null, long db = RedisConfig.DefaultDb)
: this()
{
this.Host = host;
this.Port = port;
this.Password = password;
this.Db = db;
}
public string Host { get; set; }
public int Port { get; set; }
public bool Ssl { get; set; }
public int ConnectTimeout { get; set; }
public int SendTimeout { get; set; }
public int ReceiveTimeout { get; set; }
public int RetryTimeout { get; set; }
public int IdleTimeOutSecs { get; set; }
public long Db { get; set; }
public string Client { get; set; }
public string Password { get; set; }
public bool RequiresAuth { get { return !string.IsNullOrEmpty(Password); } }
public string NamespacePrefix { get; set; }
public override string ToString()
{
var sb = StringBuilderCache.Allocate();
sb.AppendFormat("{0}:{1}", Host, Port);
var args = new List<string>();
if (Client != null)
args.Add("Client=" + Client);
if (Password != null)
args.Add("Password=" + Password);
if (Db != RedisConfig.DefaultDb)
args.Add("Db=" + Db);
if (Ssl)
args.Add("Ssl=true");
if (ConnectTimeout != RedisConfig.DefaultConnectTimeout)
args.Add("ConnectTimeout=" + ConnectTimeout);
if (SendTimeout != RedisConfig.DefaultSendTimeout)
args.Add("SendTimeout=" + SendTimeout);
if (ReceiveTimeout != RedisConfig.DefaultReceiveTimeout)
args.Add("ReceiveTimeout=" + ReceiveTimeout);
if (RetryTimeout != RedisConfig.DefaultRetryTimeout)
args.Add("RetryTimeout=" + RetryTimeout);
if (IdleTimeOutSecs != RedisConfig.DefaultIdleTimeOutSecs)
args.Add("IdleTimeOutSecs=" + IdleTimeOutSecs);
if (NamespacePrefix != null)
args.Add("NamespacePrefix=" + NamespacePrefix.UrlEncode());
if (args.Count > 0)
sb.Append("?").Append(string.Join("&", args));
return StringBuilderCache.ReturnAndFree(sb);
}
protected bool Equals(RedisEndpoint other)
{
return string.Equals(Host, other.Host)
&& Port == other.Port
&& Ssl.Equals(other.Ssl)
&& ConnectTimeout == other.ConnectTimeout
&& SendTimeout == other.SendTimeout
&& ReceiveTimeout == other.ReceiveTimeout
&& RetryTimeout == other.RetryTimeout
&& IdleTimeOutSecs == other.IdleTimeOutSecs
&& Db == other.Db
&& string.Equals(Client, other.Client)
&& string.Equals(Password, other.Password)
&& string.Equals(NamespacePrefix, other.NamespacePrefix);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((RedisEndpoint)obj);
}
public override int GetHashCode()
{
unchecked
{
var hashCode = (Host != null ? Host.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ Port;
hashCode = (hashCode * 397) ^ Ssl.GetHashCode();
hashCode = (hashCode * 397) ^ ConnectTimeout;
hashCode = (hashCode * 397) ^ SendTimeout;
hashCode = (hashCode * 397) ^ ReceiveTimeout;
hashCode = (hashCode * 397) ^ RetryTimeout;
hashCode = (hashCode * 397) ^ IdleTimeOutSecs;
hashCode = (hashCode * 397) ^ Db.GetHashCode();
hashCode = (hashCode * 397) ^ (Client != null ? Client.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (Password != null ? Password.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (NamespacePrefix != null ? NamespacePrefix.GetHashCode() : 0);
return hashCode;
}
}
}
}