Hangfire.Redis.StackExchange 1.8.7

.NET Standard 2.0 .NET Framework 4.6.2
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Hangfire.Redis.StackExchange --version 1.8.7
NuGet\Install-Package Hangfire.Redis.StackExchange -Version 1.8.7
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Hangfire.Redis.StackExchange" Version="1.8.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Hangfire.Redis.StackExchange --version 1.8.7
#r "nuget: Hangfire.Redis.StackExchange, 1.8.7"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Hangfire.Redis.StackExchange as a Cake Addin
#addin nuget:?package=Hangfire.Redis.StackExchange&version=1.8.7

// Install Hangfire.Redis.StackExchange as a Cake Tool
#tool nuget:?package=Hangfire.Redis.StackExchange&version=1.8.7


HangFire Redis storage based on HangFire.Redis but using lovely StackExchange.Redis client.

Build status Nuget Badge

Package Name NuGet.org
Hangfire.Redis.StackExchange Nuget Badge
Hangfire.Redis.StackExchange.StrongName Nuget Badge
  • Support for Hangfire Batches (feature of Hangfire Pro)
  • Efficient use of Redis resources thanks to ConnectionMultiplexer
  • Support for Redis Prefix, allow multiple Hangfire Instances against a single Redis DB
  • Allow customization of Succeeded and Failed lists size

Despite the name, Hangfire.Redis.StackExchange.StrongName is not signed because Hangfire.Core is not yet signed.

Tutorial: Hangfire on Redis on ASP.NET Core MVC

Getting Started

To use Hangfire against Redis in an ASP.NET Core MVC projects, first you will need to install at least these two packages: Hangfire.AspNetCore and Hangfire.Redis.StackExchange.

In Startup.cs, these are the bare minimum codes that you will need to write for enabling Hangfire on Redis:

public class Startup
    public static ConnectionMultiplexer Redis;

    public Startup(IHostingEnvironment env)
        // Other codes / configurations are omitted for brevity.
        Redis = ConnectionMultiplexer.Connect(Configuration.GetConnectionString("Redis"));

    public void ConfigureServices(IServiceCollection services)
        services.AddHangfire(configuration =>

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)

Attention: If you are using Microsoft.Extensions.Caching.Redis package, you will need to use Hangfire.Redis.StackExchange.StrongName instead, because the former package requires StackExchange.Redis.StrongName instead of StackExchange.Redis!



This method accepts two parameters:

  • The first parameter accepts either your Redis connection string or a ConnectionMultiplexer object. By recommendation of the official StackExchange.Redis documentation, it is actually recommended to create one ConnectionMultiplexer for multiple reuse.

  • The second parameter accepts RedisStorageOptions object. As of version 1.7.0, these are the properties you can set into the said object:

namespace Hangfire.Redis
    public class RedisStorageOptions
        public const string DefaultPrefix = "{hangfire}:";

        public RedisStorageOptions();

        public TimeSpan InvisibilityTimeout { get; set; }
        public TimeSpan FetchTimeout { get; set; }
        public string Prefix { get; set; }
        public int Db { get; set; }
        public int SucceededListSize { get; set; }
        public int DeletedListSize { get; set; }

It is highly recommended to set the Prefix property, to avoid overlap with other projects that targets the same Redis store!


This method accepts BackgroundJobServerOptions as the first parameter:

namespace Hangfire
    public class BackgroundJobServerOptions
        public BackgroundJobServerOptions();

        public string ServerName { get; set; }
        public int WorkerCount { get; set; }
        public string[] Queues { get; set; }
        public TimeSpan ShutdownTimeout { get; set; }
        public TimeSpan SchedulePollingInterval { get; set; }
        public TimeSpan HeartbeatInterval { get; set; }
        public TimeSpan ServerTimeout { get; set; }
        public TimeSpan ServerCheckInterval { get; set; }
        public IJobFilterProvider FilterProvider { get; set; }
        public JobActivator Activator { get; set; }

Of these options, several interval options may be manually set (to longer intervals) to reduce CPU load:

  • SchedulePollingInterval is by default set to 15 seconds.

  • HeartbeatInterval is by default set to 30 seconds.

  • ServerTimeout and ServerCheckInterval is by default set to 5 minutes.


Written below is a short snippet on how to implement Hangfire dashboard in ASP.NET Core MVC applications, with limited access to cookie-authenticated users of Administrator role. Read more in official documentation.

public class AdministratorHangfireDashboardAuthorizationFilter : IDashboardAuthorizationFilter
    public bool Authorize(DashboardContext context)
        var user = context.GetHttpContext().User;
        return user.Identity.IsAuthenticated && user.IsInRole("Administrator");
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)

    // This middleware must be placed AFTER the authentication middlewares!
    app.UseHangfireDashboard(options: new DashboardOptions
        Authorization = new[] { new AdministratorHangfireDashboardAuthorizationFilter() }

Jobs via ASP.NET Core Dependency Injection Services

For cleaner and more managable application code, it is possible to define your jobs in a class that is registered via dependency injection.

public class MyHangfireJobs
    public async Task SendGetRequest()
        var client = new HttpClient();
        await client.GetAsync("https://www.accelist.com");
public void ConfigureServices(IServiceCollection services)

Using this technique, the registered jobs service will be able to obtain other services as dependency via constructor parameters, such as Entity Framework Core DbContext; which enables the development of powerful jobs with relative ease.

Then later you can execute the jobs using generic expression:

BackgroundJob.Enqueue<MyHangfireJobs>(jobs => jobs.SendGetRequest());

BackgroundJob.Schedule<MyHangfireJobs>(jobs => jobs.SendGetRequest(), DateTimeOffset.UtcNow.AddDays(1));

RecurringJob.AddOrUpdate<MyHangfireJobs>("RecurringSendGetRequest", jobs => jobs.SendGetRequest(), Cron.Hourly());
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (24)

Showing the top 5 NuGet packages that depend on Hangfire.Redis.StackExchange:

Package Downloads



EaCloud Hangfire 后台任务组件,封装基于 Hangfire 后台任务的服务端实现。






Support for Redis for Hangfire.Tags. This separate library is required in order to search for tags, and proper cleanup.

GitHub repositories (7)

Showing the top 5 popular GitHub repositories that depend on Hangfire.Redis.StackExchange:

Repository Stars
:shield: The independent, comprehensive directory of filter and host lists for advertisements, trackers, malware, and annoyances.
集合.net core、ocelot、consul、netty、rpc、eventbus、configserver、tracing、sqlsugar、vue-admin、基础管理平台等构建的微服务一条龙应用
一个基于 .NET Core构建的简单、跨平台、模块化的商城系统
基于 Asp.Net Core 5.0、Uni-App开发,支持可视化布局的小程序商城系统,前后端分离,支持分布式部署,跨平台运行,拥有分销、代理、团购、拼团、秒杀、直播、优惠券、自定义表单等众多营销功能,拥有完整SKU、下单、售后、物流流程。支持一套代码编译发布微信小程序版、H5版、Android版、iOS版、支付宝小程序版、字节跳动小程序版、QQ小程序版等共10个平台。
Self-hosted VirusTotal / MetaDefender wannabe with API, demo UI and Scanners running in Docker.
Version Downloads Last updated
1.9.1-beta 1,661 10/7/2022
1.9.0-beta 831 7/18/2022
1.8.7 10,776 3/8/2023
1.8.6 210,076 9/30/2022
1.8.5 694,100 10/17/2021
1.8.4 1,307,132 5/28/2020
1.8.3 145,977 5/6/2020
1.8.2 29,440 4/20/2020
1.8.1 172,606 1/9/2020
1.8.0 724,703 11/5/2018
1.7.2 160,886 1/4/2018
1.7.0 35,571 5/9/2017 30,515 2/16/2017 18,037 12/9/2016 1,185 11/30/2016 1,085 11/30/2016 1,747 11/18/2016 1,154 11/17/2016 1,086 11/17/2016 1,075 11/17/2016 1,139 11/17/2016 1,187 11/11/2016 1,536 11/8/2016 1,310 11/1/2016
1.6.6 1,027 11/17/2016 1,715 10/20/2016 2,577 10/5/2016 3,746 4/19/2016
1.5.3 1,367 3/16/2016
1.5.3-rc 1,192 1/4/2016
1.4.8 3,750 1/6/2016
1.4.7 2,215 9/1/2015
1.4.6 2,183 8/11/2015
1.4.5 1,309 8/5/2015
1.4.2 1,325 5/27/2015 2,369 4/22/2015 1,271 4/22/2015
1.1.4 2,240 4/6/2015
1.1.2-beta 871 4/4/2015
1.1.0-beta 840 3/13/2015
1.0.6-alpha 1,001 2/27/2015
1.0.5-alpha 1,403 2/27/2015
1.0.4-alpha 964 2/27/2015
1.0.3-alpha 1,357 2/26/2015
1.0.2-beta 864 4/4/2015
1.0.2-alpha 1,313 2/25/2015
1.0.1-alpha 1,092 2/23/2015
1.0.0-alpha 1,279 2/23/2015

           - Updated Nuget packages
           - Removed .NET 4.6.1 support (no longer supported by Microsoft)
           - Adds netstandard 2.1 as a target framework
           - Miscellaneous cleanup, namespace adjustment
           - Suppress Password in Connection's ToString (thanks to matheusriboli)
           - Updated Nuget Packages dependencies
           - Speed up Recurring jobs Fetching (thanks to developingjim)
           - Fix #90, #91 concurrent access on dictinoary (thanks to luukholleman)
           - Fix #94 occasional error in monitoringApi (thanks to tsu1980)
           - Removed dependency to NewtonSoft.JSON (thanks to neyromant)
           - Updated Hangfire to 1.7.11 (thanks to abarducci)
           - Updated StackExchange.Redis to 2.1.30 (thanks to abarducci)
           - Updated Hangfire to 1.7.8
           - Fixed #82 (thanks to @bcuff)
           - Updated StackExchange.Redis to 2.0 (thanks to @andrebires)
           - Added support for Lifo Queues (thanks to AndreSteenbergen)
           - Added option to not use transaction (thanks to AndreSteenbergen)
           - Enabled sliding expiration for distributed locks (thanks to pieceofsummer)
           - Add epired jobs watch to cleanup succeeded/deleted lists (thanks to pieceofsummer)
           - Make succeeded and deleted lists size configurable (thanks to pieceofsummer)
           - Fix job state order (thanks to pieceofsummer)
           - Exclude Fetched property from job parameters (thanks to pieceofsummer)
           - Add expired jobs watcher to cleanup succeeded/deleted lists thanks to pieceofsummer
           - Redis Cluster support (#42 thanks to gzpbx)
           - Update to VS2017 (#48 thanks to ryanelian)
           - Added support for Redis DB in the ConnectionString (#26 thanks to zivillian)
           - Added constructor to RedisStorage that accepts a ConnectionMultiplexer instance (#23 thanks to sjwoodard)
           - Lowered dependencies for net45 framework and aligned to Hangfire.Core (#21 thanks to zlangner)
           - Fixed dependency casing of Hangfire.Core (#33 thanks to Poly3k)
           - Fix Dispose of RedisSupscription (#32 thanks to WebApelsin)
           - Fixed random failure of test NestLockDisposePreservesRoot
           - Configurable timeout for FetchNextJob (thanks to WebApelsin)
           - .Net Core Support (thanks to Stefan Polyanszky)
           - Aligned dependency to Hangfire.Core