Skip to content
This repository was archived by the owner on Jun 29, 2020. It is now read-only.
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
10 changes: 10 additions & 0 deletions HealthChecks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNet.HealthChec
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleHealthChecker.AspNet", "samples\SampleHealthChecker.AspNet\SampleHealthChecker.AspNet.csproj", "{33FB5967-62C7-4230-B515-780EF63F748E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.HealthChecks.Redis", "src\Microsoft.Extensions.HealthChecks.Redis\Microsoft.Extensions.HealthChecks.Redis.csproj", "{B88C2B6F-991F-4217-84A0-28F0BEDBD993}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -63,6 +65,10 @@ Global
{33FB5967-62C7-4230-B515-780EF63F748E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33FB5967-62C7-4230-B515-780EF63F748E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{33FB5967-62C7-4230-B515-780EF63F748E}.Release|Any CPU.Build.0 = Release|Any CPU
{B88C2B6F-991F-4217-84A0-28F0BEDBD993}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B88C2B6F-991F-4217-84A0-28F0BEDBD993}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B88C2B6F-991F-4217-84A0-28F0BEDBD993}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B88C2B6F-991F-4217-84A0-28F0BEDBD993}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -76,5 +82,9 @@ Global
{13BE838A-200B-4A68-8F58-3EA3BE3A1A8A} = {F9BA869A-7D5F-420F-9505-2D881F7934A7}
{2AE82E1C-6CE1-4755-A332-FA359B7CCE72} = {F9BA869A-7D5F-420F-9505-2D881F7934A7}
{33FB5967-62C7-4230-B515-780EF63F748E} = {E05DCF88-F916-4B61-A5DC-A8344C9E2429}
{B88C2B6F-991F-4217-84A0-28F0BEDBD993} = {F9BA869A-7D5F-420F-9505-2D881F7934A7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {647884AE-0D3B-4A25-8303-1CEA1C2DD945}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using ServiceStack.Redis;
using System.Linq;
namespace Microsoft.Extensions.HealthChecks
{
public static class HealthCheckBuilderRedisExtensions
{
public static HealthCheckBuilder AddRedisCheck(this HealthCheckBuilder builder, string name, string host, int port, string password = null)
{
Guard.ArgumentNotNull(nameof(builder), builder);
return AddRedisCheck(builder, name, builder.DefaultCacheDuration, host, port, password);
}


public static HealthCheckBuilder AddRedisCheck(this HealthCheckBuilder builder, string name, TimeSpan cacheDuration, string host, int port, string password = null)
{
builder.AddCheck($"RedisCheck({name})", () =>
{
try
{
using (var client = new RedisClient(host, port, password))
{
var response = client.Info;

if (response != null && response.Any())
{
return HealthCheckResult.Healthy($"RedisCheck({name}): Healthy");
}
return HealthCheckResult.Unhealthy($"RedisCheck({name}): Unhealthy");

}
}
catch (Exception ex)
{
return HealthCheckResult.Unhealthy($"RedisCheck({name}): Exception during check: {ex.GetType().FullName}");
}
}, cacheDuration);

return builder;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\common\Guard.cs" Link="Internal\Guard.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="ServiceStack.Redis.Core" Version="5.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.Extensions.HealthChecks\Microsoft.Extensions.HealthChecks.csproj" />
</ItemGroup>

</Project>