当前位置:网站首页>. 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");}边栏推荐
- 「小技巧」给Seurat对象瘦瘦身
- Flet教程之 03 FilledButton基础入门(教程含源码)(教程含源码)
- Dgraph: large scale dynamic graph dataset
- Apache服务器访问日志access.log设置
- Comprehensive evaluation of modular note taking software: craft, notation, flowus
- "Pre training weekly" issue 52: shielding visual pre training and goal-oriented dialogue
- Efficient! Build FTP working environment with virtual users
- Runc hang causes the kubernetes node notready
- Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
- Optional values and functions of the itemized contenttype parameter in the request header
猜你喜欢

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

Runc hang causes the kubernetes node notready

Xue Jing, director of insight technology solutions: Federal learning helps secure the flow of data elements

CTF竞赛题解之stm32逆向入门

Etcd 存储,Watch 以及过期机制

【AI系统前沿动态第40期】Hinton:我的深度学习生涯与研究心法;Google辟谣放弃TensorFlow;封神框架正式开源

n++也不靠谱

Database lock table? Don't panic, this article teaches you how to solve it

Is the outdoor LED screen waterproof?

光环效应——谁说头上有光的就算英雄
随机推荐
XML入门二
n++也不靠谱
数据库锁表?别慌,本文教你如何解决
Is the outdoor LED screen waterproof?
.NET 使用 redis
CVPR 2022 | TransFusion:用Transformer进行3D目标检测的激光雷达-相机融合
SQL language
诸神黄昏时代的对比学习
Don't turn down, three sentences to clarify the origin of cross domain resource request errors
[cloud native | kubernetes] in depth understanding of ingress (12)
Reptile exercises (I)
一个数据人对领域模型理解与深入
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
Talk about the design and implementation logic of payment process
XML入门三
6 分钟看完 BGP 协议。
Read the BGP agreement in 6 minutes.
mysql三级分销代理关系存储
使用Scrcpy投屏
【云原生 | Kubernetes篇】深入了解Ingress(十二)