Asp.Net core

來源:互聯網
上載者:User

標籤:var   UI   factor   json   nec   newton   code   string   hosting   

Hangfire 官方支援 MSSQL 與 Redis 兩種 ,當然也可以使用第三方來支援 MYSQL,PostgreSql,Mongo 等
安裝 Redis
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:chris-lea/redis-server
sudo apt-get update
sudo apt-get install redis-server
ps aux | grep redis
sudo service redis-server restart
sudo apt-get remove redis-server
redis-cli
#注釋bind
# bind 127.0.0.1
######守護進程啟動
daemonize yes
#保護模式[無Cipher 模式設定為no]
protected-mode no
#設定密碼
requirepass test
Mac 下安裝 Redis Desktop Manager(官方 Mac 版只支援源碼重編譯)
#install brew cask
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null ; brew install caskroom/cask/brew-cask 2> /dev/null
# install Redis Desktop Manager
brew cask install rdm

Asp.Net Core 整合Hangfire
Hangfire.Pro 是對 Hangfire 的一個擴充,使用自己搭建的 Nuget 源,Hangfire.Pro.Redis 是其中的一個擴充 ;我這裡是使用的 Hangfire.Redis.StackExchange 基本滿足需求。
增加 package<PackageReference Include="Hangfire.AspNetCore" Version="1.6.12" /><PackageReference Include="Hangfire.Redis.StackExchange.StrongName" Version="1.7.0" /><PackageReference Include="StackExchange.Redis.StrongName" Version="1.2.3" />配置 Hangfire 服務
 public class Startup    {        public IConfigurationRoot Configuration { get; }        public static ConnectionMultiplexer Redis;        public Startup(IHostingEnvironment env)        {            var builder = new ConfigurationBuilder()                            .SetBasePath(env.ContentRootPath)                            .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)                            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)                            .AddEnvironmentVariables();            Configuration = builder.Build();            Redis = ConnectionMultiplexer.Connect(Configuration.GetConnectionString("Redis"));        }        // This method gets called by the runtime. Use this method to add services to the container.        public void ConfigureServices(IServiceCollection services)        {            services.AddOptions();            //自訂配置            services.Configure<DbSetting>(Configuration.GetSection("ConnectionStrings"));            //返回大小寫問題            services.AddMvc()                    .AddJsonOptions(op => op.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver());            //注入Hangfire服務            services.AddHangfire(config => config.UseRedisStorage(Redis));          }        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)        {            loggerFactory.AddConsole(Configuration.GetSection("Logging"));            loggerFactory.AddDebug();            if (env.IsDevelopment())            {                app.UseDeveloperExceptionPage();                app.UseBrowserLink();            }            else            {                app.UseExceptionHandler("/Home/Error");            }            app.UseStaticFiles();                        app.UseHangfireServer();            app.UseHangfireDashboard();            app.UseMvc(routes =>            {                routes.MapRoute(                    name: "default",                    template: "{controller=Hq}/{action=Index}/{id?}");            });        }    }

https://github.com/marcoCasamento/Hangfire.Redis.StackExchange
http://docs.hangfire.io/en/latest/configuration/using-redis.html

Asp.Net core

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.