三、Signalr WebApi客服-客户链接+Redis(集群扩展)
2021-01-20 22:13
阅读:565
标签:div eric webapi empty src alt 参数 api 安装
一、扩展Redis集群
1、安装CSRedisCore 3.3.0
2、访问
代码如下:
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 namespace DemoCore.Controllers { [Route("api/[controller]/[action]")] //Api控制器 [ApiController] public class HomeController : Controller { private ILogger _logger; public HomeController(ILoggerlogger) { _logger = logger; } // GET: api/ [HttpGet] public IEnumerablestring> Get() { var csredis = new CSRedis.CSRedisClient(null, "127.0.0.1:6379,defaultDatabase=11,poolsize=10,ssl=false,writeBuffer=10240,prefix=btkey_", "120.79.21.96:6379,defaultDatabase=14,poolsize=13,ssl=false,writeBuffer=10240,prefix=key_"); //实现思路:根据key.GetHashCode() % 节点总数量,确定连向的节点 //也可以自定义规则(第一个参数设置) //初始化 RedisHelper RedisHelper.Initialization(csredis); RedisHelper.Set("name1", "祝雷1");//设置值。默认永不过期 RedisHelper.Set("name2", "祝雷2");//设置值。默认永不过期 RedisHelper.Set("name1", "祝雷11");//设置值。默认永不过期 RedisHelper.Set("name2", "祝雷22");//设置值。默认永不过期 RedisHelper.Set("name", "祝雷");//设置值。默认永不过期 string str=RedisHelper.Get("name");//取值 _logger.LogInformation("测试一下,不要紧张!"); return new string[] { "value1", "value2" }; } } }
三、Signalr WebApi客服-客户链接+Redis(集群扩展)
标签:div eric webapi empty src alt 参数 api 安装
原文地址:https://www.cnblogs.com/fger/p/12119396.html
上一篇:C#6新特性,让你的代码更干净
下一篇:windows10删除用户头像
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:三、Signalr WebApi客服-客户链接+Redis(集群扩展)
文章链接:http://soscw.com/essay/44728.html
文章标题:三、Signalr WebApi客服-客户链接+Redis(集群扩展)
文章链接:http://soscw.com/essay/44728.html
评论
亲,登录后才可以留言!