当前位置:网站首页>. Net using redis
. Net using redis
2022-07-04 13:41:00 【Hua Weiyun】
Redis The publish and subscribe function of
redis To configure
Redis Configuration explanation ( Remember to restart after operation Redis service )
Allow remote access
1. Modify two configuration files :redis.windows.conf and redis.windows-service.conf
2. Comment out bind 127.0.0.1
3. Turn off protection mode protected-mode no
password
1. Modify two configuration files :redis.windows.conf and redis.windows-service.conf
2. Turn on requirepass yourPassword
ASP.NET Core Use redis
- install StackChange.Redis nuget package
- Database connection information such as connection string is placed in appsettings in
- Writing database access tool classes
- startup Registration service
Here is the manual parsing of configuration information , Can pass softjson Auto parse
public void ConfigureServices(IServiceCollection services) { var section = Configuration.GetSection("Redis:Default"); string _connectionString = section.GetSection("Connection").Value; string _instanceName = section.GetSection("InstanceName").Value; int _defaultDB = int.Parse(section.GetSection("DefaultDB").Value ?? "0"); services.AddSingleton(new RedisHelper(_connectionString, _instanceName, _defaultDB)); services.AddControllers(); }- controller Call in
ASP.NET CORE Use in redis cache
install nuget package
- StackExchange.Redis.Extensions.Core
- StackExchange.Redis.Extensions.AspNetCore
- StackExchange.Redis.Extensions.Newtonsoft
appsettings Profile add
"Redis": { "Password": "123456", "AllowAdmin": true, "Ssl": false, "ConnectTimeout": 6000, "ConnectRetry": 2, "Database": 0, "Hosts": [ { "Host": "127.0.0.1", "Port": "6379" } ] }startup Registration service
public void ConfigureServices(IServiceCollection services){ var redisConfiguration = Configuration.GetSection("Redis").Get<RedisConfiguration>(); services.AddControllersWithViews(); services.AddStackExchangeRedisExtensions<NewtonsoftSerializer>(redisConfiguration);}With services
private readonly RedisCacheClient _redisCacheClient; public TestController(IRedis redisCacheClient) { _redisCacheClient = redisCacheClient; }Use
public async Task<IActionResult> Index4() { var productdata = await _redisCacheClient.Db0.GetAsync<Product>("Product"); return View(); }.net in redis Publish subscription
Mainly use code : subscribe
using (ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("127.0.0.1:6379")){ ISubscriber sub = redis.GetSubscriber(); // The subscription is called messages The passage of sub.Subscribe("messages", (channel, message) => { // Output received messages Console.WriteLine($"[{DateTime.Now:HH:mm:ss}] {message}"); }); Console.WriteLine(" Subscribed messages"); Console.ReadKey();}Release
// Create connection using (ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("127.0.0.1:6379")){ ISubscriber sub = redis.GetSubscriber(); Console.WriteLine(" Please enter any character , Input exit sign out "); string input; do { input = Console.ReadLine(); sub.Publish("messages", input); } while (input != "exit");}边栏推荐
- Reptile exercises (I)
- Talk about the design and implementation logic of payment process
- 微服务入门
- SQL language
- Samsung's mass production of 3nm products has attracted the attention of Taiwan media: whether it can improve the input-output rate in the short term is the key to compete with TSMC
- Efficient! Build FTP working environment with virtual users
- n++也不靠谱
- SQL statement syntax error in test SQL statement deletion in eclipse linked database
- Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
- Xue Jing, director of insight technology solutions: Federal learning helps secure the flow of data elements
猜你喜欢

Talk about the design and implementation logic of payment process

6 分钟看完 BGP 协议。

求解:在oracle中如何用一条语句用delete删除两个表中jack的信息

"Pre training weekly" issue 52: shielding visual pre training and goal-oriented dialogue

Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example

聊聊支付流程的设计与实现逻辑

干货整理!ERP在制造业的发展趋势如何,看这一篇就够了

Oracle 被 Ventana Research 评为数字创新奖总冠军

After installing vscode, the program runs (an include error is detected, please update the includepath, which has been solved for this translation unit (waveform curve is disabled) and (the source fil

When MDK uses precompiler in header file, ifdef is invalid
随机推荐
光环效应——谁说头上有光的就算英雄
Apache服务器访问日志access.log设置
PostgreSQL 9.1 飞升之路
2022年中国移动阅读市场年度综合分析
Alibaba cloud award winning experience: build a highly available system with polardb-x
mysql三级分销代理关系存储
Simple understanding of binary search
Rsyslog configuration and use tutorial
"Tips" to slim down Seurat objects
Master the use of auto analyze in data warehouse
"Pre training weekly" issue 52: shielding visual pre training and goal-oriented dialogue
上汽大通MAXUS正式发布全新品牌“MIFA”,旗舰产品MIFA 9正式亮相!
6 分钟看完 BGP 协议。
数据库锁表?别慌,本文教你如何解决
CTF competition problem solution STM32 reverse introduction
PostgreSQL 9.1 soaring Road
CTF竞赛题解之stm32逆向入门
CVPR 2022 | TransFusion:用Transformer进行3D目标检测的激光雷达-相机融合
6 分钟看完 BGP 协议。
《预训练周刊》第52期:屏蔽视觉预训练、目标导向对话