当前位置:网站首页>. 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");}边栏推荐
- Annual comprehensive analysis of China's mobile reading market in 2022
- AI painting minimalist tutorial
- 提高MySQL深分页查询效率的三种方案
- iptables基础及Samba配置举例
- Runc hang causes the kubernetes node notready
- N++ is not reliable
- Talk about the design and implementation logic of payment process
- Reinforcement learning - learning notes 1 | basic concepts
- [leetcode] 96 and 95 (how to calculate all legal BST)
- DGraph: 大规模动态图数据集
猜你喜欢

CANN算子:利用迭代器高效实现Tensor数据切割分块处理

AI painting minimalist tutorial

ISO 27001 Information Security Management System Certification

实战:fabric 用户证书吊销操作流程

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

面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读

室外LED屏幕防水吗?

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

实时云交互如何助力教育行业发展

Is the outdoor LED screen waterproof?
随机推荐
8个扩展子包!RecBole推出2.0!
【AI系统前沿动态第40期】Hinton:我的深度学习生涯与研究心法;Google辟谣放弃TensorFlow;封神框架正式开源
Node の MongoDB 安装
7 月数据库排行榜:MongoDB 和 Oracle 分数下降最多
Practice: fabric user certificate revocation operation process
面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
Reinforcement learning - learning notes 1 | basic concepts
jsonp
C#/VB. Net to add text / image watermarks to PDF documents
It is six orders of magnitude faster than the quantum chemical method. An adiabatic artificial neural network method based on adiabatic state can accelerate the simulation of dual nitrogen benzene der
三星量产3纳米产品引台媒关注:能否短期提高投入产出率是与台积电竞争关键
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
Web知识补充
XML入门二
洞见科技解决方案总监薛婧:联邦学习助力数据要素安全流通
Definition of cognition
请问大佬们有遇到这个情况吗,cdc 1.4 连接MySQL 5.7 无法使用 timestamp
XML入门一
runc hang 导致 Kubernetes 节点 NotReady
WPF双滑块控件以及强制捕获鼠标事件焦点