Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
StackExchange.Redis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
StackExchange.Redis
Commits
18a7427e
Commit
18a7427e
authored
Mar 25, 2016
by
DeepakVerma
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
incorporating review feedback.
parent
a4df51b8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
43 deletions
+49
-43
ConfigurationOptions.cs
...xchange.Redis/StackExchange/Redis/ConfigurationOptions.cs
+1
-42
ConnectionMultiplexer.cs
...change.Redis/StackExchange/Redis/ConnectionMultiplexer.cs
+48
-1
No files found.
StackExchange.Redis/StackExchange/Redis/ConfigurationOptions.cs
View file @
18a7427e
...
@@ -5,7 +5,6 @@
...
@@ -5,7 +5,6 @@
using
System.Linq
;
using
System.Linq
;
using
System.Net
;
using
System.Net
;
using
System.Net.Security
;
using
System.Net.Security
;
using
System.Reflection
;
using
System.Text
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
...
@@ -162,7 +161,7 @@ public static string TryNormalize(string value)
...
@@ -162,7 +161,7 @@ public static string TryNormalize(string value)
/// <summary>
/// <summary>
/// The client name to use for all connections
/// The client name to use for all connections
/// </summary>
/// </summary>
public
string
ClientName
{
get
{
return
clientName
??
(
clientName
=
(
AzureRoleInstanceId
!=
null
?
AzureRoleInstanceId
:
Environment
.
GetEnvironmentVariable
(
"ComputerName"
)))
;
}
set
{
clientName
=
value
;
}
}
public
string
ClientName
{
get
{
return
clientName
;
}
set
{
clientName
=
value
;
}
}
/// <summary>
/// <summary>
/// The number of times to repeat the initial connect cycle if no servers respond promptly
/// The number of times to repeat the initial connect cycle if no servers respond promptly
...
@@ -666,46 +665,6 @@ private bool IsAzureEndpoint()
...
@@ -666,46 +665,6 @@ private bool IsAzureEndpoint()
return
result
;
return
result
;
}
}
internal
static
string
AzureRoleInstanceId
=
TryGetAzureRoleInstanceIdNoThrow
();
/// <summary>
/// Tries to get the Roleinstance Id if Microsoft.WindowsAzure.ServiceRuntime is loaded.
/// In case of any failure, swallows the exception and returns null
/// </summary>
private
static
string
TryGetAzureRoleInstanceIdNoThrow
()
{
string
roleInstanceId
=
null
;
try
{
Assembly
asm
=
null
;
foreach
(
var
asmb
in
AppDomain
.
CurrentDomain
.
GetAssemblies
())
{
if
(
asmb
.
GetName
().
Name
.
Equals
(
"Microsoft.WindowsAzure.ServiceRuntime"
))
{
asm
=
asmb
;
break
;
}
}
if
(
asm
==
null
)
return
null
;
var
currentRoleInstanceProp
=
asm
.
GetType
(
"Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment"
).
GetProperty
(
"CurrentRoleInstance"
);
var
currentRoleInstanceId
=
currentRoleInstanceProp
.
GetValue
(
null
,
null
);
roleInstanceId
=
currentRoleInstanceId
.
GetType
().
GetProperty
(
"Id"
).
GetValue
(
currentRoleInstanceId
,
null
).
ToString
();
if
(
String
.
IsNullOrEmpty
(
roleInstanceId
))
{
roleInstanceId
=
null
;
}
}
catch
(
Exception
)
{
//silently ignores the exception
roleInstanceId
=
null
;
}
return
roleInstanceId
;
}
private
string
InferSslHostFromEndpoints
()
{
private
string
InferSslHostFromEndpoints
()
{
var
dnsEndpoints
=
endpoints
.
Select
(
endpoint
=>
endpoint
as
DnsEndPoint
);
var
dnsEndpoints
=
endpoints
.
Select
(
endpoint
=>
endpoint
as
DnsEndPoint
);
string
dnsHost
=
dnsEndpoints
.
FirstOrDefault
()?.
Host
;
string
dnsHost
=
dnsEndpoints
.
FirstOrDefault
()?.
Host
;
...
...
StackExchange.Redis/StackExchange/Redis/ConnectionMultiplexer.cs
View file @
18a7427e
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
using
System.Text
;
using
System.Text
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
System.Reflection
;
#if NET40
#if NET40
using
Microsoft.Runtime.CompilerServices
;
using
Microsoft.Runtime.CompilerServices
;
#else
#else
...
@@ -91,7 +92,53 @@ public ServerCounters GetCounters()
...
@@ -91,7 +92,53 @@ public ServerCounters GetCounters()
/// <summary>
/// <summary>
/// Gets the client-name that will be used on all new connections
/// Gets the client-name that will be used on all new connections
/// </summary>
/// </summary>
public
string
ClientName
=>
configuration
.
ClientName
;
public
string
ClientName
=>
configuration
.
ClientName
??
ConnectionMultiplexer
.
GetDefaultClientName
();
private
static
string
defaultClientName
;
private
static
string
GetDefaultClientName
()
{
if
(
defaultClientName
==
null
)
{
defaultClientName
=
TryGetAzureRoleInstanceIdNoThrow
()
??
Environment
.
GetEnvironmentVariable
(
"ComputerName"
);
}
return
defaultClientName
;
}
/// Tries to get the Roleinstance Id if Microsoft.WindowsAzure.ServiceRuntime is loaded.
/// In case of any failure, swallows the exception and returns null
internal
static
string
TryGetAzureRoleInstanceIdNoThrow
()
{
string
roleInstanceId
=
null
;
try
{
Assembly
asm
=
null
;
foreach
(
var
asmb
in
AppDomain
.
CurrentDomain
.
GetAssemblies
())
{
if
(
asmb
.
GetName
().
Name
.
Equals
(
"Microsoft.WindowsAzure.ServiceRuntime"
))
{
asm
=
asmb
;
break
;
}
}
if
(
asm
==
null
)
return
null
;
var
currentRoleInstanceProp
=
asm
.
GetType
(
"Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment"
).
GetProperty
(
"CurrentRoleInstance"
);
var
currentRoleInstanceId
=
currentRoleInstanceProp
.
GetValue
(
null
,
null
);
roleInstanceId
=
currentRoleInstanceId
.
GetType
().
GetProperty
(
"Id"
).
GetValue
(
currentRoleInstanceId
,
null
).
ToString
();
if
(
String
.
IsNullOrEmpty
(
roleInstanceId
))
{
roleInstanceId
=
null
;
}
}
catch
(
Exception
)
{
//silently ignores the exception
roleInstanceId
=
null
;
}
return
roleInstanceId
;
}
/// <summary>
/// <summary>
/// Gets the configuration of the connection
/// Gets the configuration of the connection
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment