当前位置: 首页 > news >正文

做网站公司人员台州seo服务

做网站公司人员,台州seo服务,嘉兴论坛网站建设,网站广告尺寸在前面说的JedisSentinelPool只能实现主从的切换&#xff0c;而无法实现读写的分离。 1.哨兵的客户端实现主从切换方案 <dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</arti…

在前面说的JedisSentinelPool只能实现主从的切换,而无法实现读写的分离

1.哨兵的客户端实现主从切换方案
<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!-- https://mvnrepository.com/artifact/redis.clients/jedis --><dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId><version>3.6.3</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>
# Redis哨兵服务器地址
redis.sentinel=aliyun:26885,aliyun:26886,aliyun:26887
redis.master=mymaster
# Redis服务器连接密码(默认为空)
redis.password=null
redis.timeout=30000
# 连接池最大连接数(使用负值表示没有限制)
redis.maxTotal=30
# 连接池中的最大空闲连接
redis.maxIdle=10
redis.numTestsPerEvictionRun=1024
redis.timeBetweenEvictionRunsMillis=30000
redis.minEvictableIdleTimeMillis=1800000
redis.softMinEvictableIdleTimeMillis=10000
# 连接池最大阻塞等待时间(使用负值表示没有限制)
redis.maxWaitMillis=1500
redis.testOnBorrow=true
redis.testWhileIdle=true
redis.blockWhenExhausted=false
redis.JmxEnabled=true
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisSentinelPool;import java.util.HashSet;
import java.util.Set;@Configuration
@PropertySource("classpath:application.properties")
public class RedisSentinelConfig {@Value("${redis.sentinel}")private String hosts;@Value("${redis.master}")private String master;@Value("${redis.timeout}")private int timeout;@Value("${redis.maxIdle}")private int maxIdle;@Value("${redis.maxWaitMillis}")private int maxWaitMillis;@Value("${redis.blockWhenExhausted}")private Boolean blockWhenExhausted;@Value("${redis.JmxEnabled}")private Boolean JmxEnabled;@Beanpublic JedisPoolConfig  jedisPoolConfigFactory() {JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();jedisPoolConfig.setMaxIdle(maxIdle);jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);// 连接耗尽时是否阻塞, false报异常,true阻塞直到超时, 默认truejedisPoolConfig.setBlockWhenExhausted(blockWhenExhausted);// 是否启用pool的jmx管理功能, 默认truejedisPoolConfig.setJmxEnabled(JmxEnabled);jedisPoolConfig.setTestOnBorrow(true);jedisPoolConfig.setTestOnReturn(true);return jedisPoolConfig;}@Beanpublic JedisSentinelPool JedisSentinelPoolFactory(JedisPoolConfig jedisPoolConfig){Set<String> nodeSet = new HashSet<>();//获取到节点信息String nodeString = hosts;//判断字符串是否为空if(nodeString == null || "".equals(nodeString)){throw new RuntimeException("RedisSentinelConfiguration initialize error nodeString is null");}String[] nodeArray = nodeString.split(",");//判断是否为空if(nodeArray == null || nodeArray.length == 0){throw new RuntimeException("RedisSentinelConfiguration initialize error nodeArray is null");}//循环注入至Set中for(String node : nodeArray){System.out.println("Read node : "+node);nodeSet.add(node);}//创建连接池对象JedisSentinelPool jedisSentinelPool = new JedisSentinelPool(master,nodeSet,jedisPoolConfig ,timeout);return jedisSentinelPool;}}
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisSentinelPool;/*** 操作字符串类型*/
@Component
public class RedisString {public final static String RS_STR_NS = "rs:";@Autowiredprivate JedisSentinelPool jedisSentinelPool;/*** 向Redis中存值,永久有效*/public String set(String key, String value) {Jedis jedis = null;try {jedis = jedisSentinelPool.getResource();return jedis.set(RS_STR_NS +key, value);} catch (Exception e) {throw new RuntimeException("向Redis中存值失败!");} finally {jedis.close();}}/*** 批量向Redis中存值,永久有效*/public String msetRaw(String... keysvalues) {Jedis jedis = null;try {jedis = jedisSentinelPool.getResource();return jedis.mset(keysvalues);} catch (Exception e) {throw new RuntimeException("批量向Redis中存值失败!");} finally {jedis.close();}}/*** 根据传入Key获取指定Value*/public String get(String key) {Jedis jedis = null;try {jedis = jedisSentinelPool.getResource();return jedis.get(RS_STR_NS +key);} catch (Exception e) {throw new RuntimeException("获取Redis值失败!");} finally {jedis.close();}}}
2、读写分离的实现

需要自己去封装代码实现。
待补充

http://www.yayakq.cn/news/547787/

相关文章:

  • 大朗仿做网站煤矿网站建设
  • 网站建设的理念新年贺卡图片 手工制作
  • 商家建设网站的好处婚纱摄影店排名前十名
  • 网站建设管理工作总结报告图书馆新生专栏网站建设
  • 哈尔滨产品推广网站网站邮件推送
  • 网站建设目标青岛即墨城乡建设局网站
  • 中山公司网站制作做网站的公司 洛阳
  • 杭州市拱墅区住房与建设局网站网站备案号查询系统
  • 老年大学网站开发一个工厂的网站建设
  • 免费服务器搭建网站详细教程短视频网站的动画是怎么做的
  • 个人如何申请网站可以做外贸私单的网站
  • 网站开发需要会什么软件太原网站优化常识
  • 网站排名软件多浏览器企业大型网站建设要多少钱
  • 网站建设服务器都有哪些软件开发工程师的职责
  • 利用电脑做网站已经买了域名怎么做网站
  • 三星网站建设内容丝足网站的建设
  • 公司网站是不是每天要更新如何建个人网站
  • 站长查询工具百度联盟个人怎么接广告
  • 做网站开发团队吉安高端网站建设公司
  • o2o网站建设信息wordpress更改ip地址后图片处理
  • 网站栏目结构优化武进建设局网站首页
  • 关键词整站排名优化网上服务平台登录
  • 网络服务提供者利用网络侵害他人杭州优化seo公司
  • 怎么用wordpress打开网站手机应用市场下载安装app
  • 电子商务网站与普通网站的区别大连如是科技
  • 云县网站建设自己做网站犯法吗
  • 简述网站一般建设的流程图重庆建设工程信息网查询官网
  • 企业网站规划方案wordpress相册短代码
  • 江阴做网站的公司有seo快速排名百度首页
  • 机械设计网站有哪些网络推广公司名字大全