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

普宁建设局网站企业网站开发有哪些

普宁建设局网站,企业网站开发有哪些,seo做论坛和企业网站差别,有专门教做儿童美食的网站吗本地Java连接Redis常见问题#xff1a; bind配置请注释掉保护模式设置为noLinux系统的防火墙设置redis服务器的IP地址和密码是否正确忘记写访问redis的服务端口号和auth密码 集成Jedis jedis是什么 Jedis Client是Redis官网推荐的一个面向java客户端#xff0c;库文件实现…本地Java连接Redis常见问题 bind配置请注释掉保护模式设置为noLinux系统的防火墙设置redis服务器的IP地址和密码是否正确忘记写访问redis的服务端口号和auth密码 集成Jedis jedis是什么 Jedis Client是Redis官网推荐的一个面向java客户端库文件实现了对各类API进行封装调用。 案例 1、pom.xml !--jedis-- dependencygroupIdredis.clients/groupIdartifactIdjedis/artifactIdversion4.3.1/version /dependency 2、测试 public class JedisDemo {public static void main(String[] args){//连接本地的 Redis 服务自己的ip和端口和密码Jedis jedis new Jedis(192.168.111.181,6379);// 如果 Redis 服务设置了密码需要下面这行没有就不需要jedis.auth(111111);//keySetString keys jedis.keys(*);for (Iterator iterator keys.iterator(); iterator.hasNext();) {String key (String) iterator.next();System.out.println(key);}System.out.println(jedis.existsjedis.exists(k2));System.out.println(jedis.ttl(k1));//String//jedis.append(k1,myreids);System.out.println(jedis.get(k1));jedis.set(k4,k4_redis);System.out.println(----------------------------------------);jedis.mset(str1,v1,str2,v2,str3,v3);System.out.println(jedis.mget(str1,str2,str3));//listSystem.out.println(----------------------------------------);//jedis.lpush(mylist,v1,v2,v3,v4,v5);ListString list jedis.lrange(mylist,0,-1);for (String element : list) {System.out.println(element);}//setjedis.sadd(orders,jd001);jedis.sadd(orders,jd002);jedis.sadd(orders,jd003);SetString set1 jedis.smembers(orders);for (Iterator iterator set1.iterator(); iterator.hasNext();) {String string (String) iterator.next();System.out.println(string);}jedis.srem(orders,jd002);System.out.println(jedis.smembers(orders).size());//hashjedis.hset(hash1,userName,lisi);System.out.println(jedis.hget(hash1,userName));MapString,String map new HashMapString,String();map.put(telphone,138xxxxxxxx);map.put(address,atguigu);map.put(email,zzyybs126.com);//课后有问题请给我发邮件jedis.hmset(hash2,map);ListString result jedis.hmget(hash2, telphone,email);for (String element : result) {System.out.println(element);}//zsetjedis.zadd(zset01,60d,v1);jedis.zadd(zset01,70d,v2);jedis.zadd(zset01,80d,v3);jedis.zadd(zset01,90d,v4);ListString zset01 jedis.zrange(zset01, 0, -1);zset01.forEach(System.out::println);} } 集成Lettuce lettuce是什么 Lettuce是一个Redis的Java驱动包Lettuce翻译为生菜没错就是吃的那种生菜所以它的Logo长这样。 Jedis 和 Lettuce 区别 案例 1、pom.xml !--lettuce-- dependencygroupIdio.lettuce/groupIdartifactIdlettuce-core/artifactIdversion6.2.1.RELEASE/version /dependency 2、测试 Slf4j public class LettuceDemo {public static void main(String[] args){//使用构建器 RedisURI.builderRedisURI uri RedisURI.builder().redis(192.168.111.181).withPort(6379).withAuthentication(default,111111).build();//创建连接客户端RedisClient client RedisClient.create(uri);StatefulRedisConnection conn client.connect();//操作命令apiRedisCommandsString,String commands conn.sync();//keysListString list commands.keys(*);for(String s : list) {log.info(key:{},s);}//Stringcommands.set(k1,1111);String s1 commands.get(k1);System.out.println(String s s1);//listcommands.lpush(myList2, v1,v2,v3);ListString list2 commands.lrange(myList2, 0, -1);for(String s : list2) {System.out.println(list sssss);}//setcommands.sadd(mySet2, v1,v2,v3);SetString set commands.smembers(mySet2);for(String s : set) {System.out.println(set sssss);}//hashMapString,String map new HashMap();map.put(k1,138xxxxxxxx);map.put(k2,atguigu);map.put(k3,zzyybs126.com);//课后有问题请给我发邮件commands.hmset(myHash2, map);MapString,String retMap commands.hgetall(myHash2);for(String k : retMap.keySet()) {System.out.println(hash kk , vretMap.get(k));}//zsetcommands.zadd(myZset2, 100.0,s1,110.0,s2,90.0,s3);ListString list3 commands.zrange(myZset2,0,10);for(String s : list3) {System.out.println(zset sssss);}//sortSortArgs sortArgs new SortArgs();sortArgs.alpha();sortArgs.desc();ListString list4 commands.sort(myList2,sortArgs);for(String s : list4) {System.out.println(sort sssss);}//关闭conn.close();client.shutdown();} }集成RedisTemplate推荐使用 连接单机 1、pom.xml !--SpringBoot与Redis整合依赖-- dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-redis/artifactId /dependency 2、yaml # redis单机 spring.redis.database0 # 修改为自己真实IP spring.redis.host192.168.111.185 spring.redis.port6379 spring.redis.password111111 spring.redis.lettuce.pool.max-active8 spring.redis.lettuce.pool.max-wait-1ms spring.redis.lettuce.pool.max-idle8 spring.redis.lettuce.pool.min-idle0 3、Redis配置 import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer;Configuration public class RedisConfig {/*** redis序列化的工具配置类下面这个请一定开启配置* 127.0.0.1:6379 keys ** 1) ord:102 序列化过* 2) \xac\xed\x00\x05t\x00\aord:102 野生没有序列化过* this.redisTemplate.opsForValue(); //提供了操作string类型的所有方法* this.redisTemplate.opsForList(); // 提供了操作list类型的所有方法* this.redisTemplate.opsForSet(); //提供了操作set的所有方法* this.redisTemplate.opsForHash(); //提供了操作hash表的所有方法* this.redisTemplate.opsForZSet(); //提供了操作zset的所有方法* param lettuceConnectionFactory* return*/Beanpublic RedisTemplateString, Object redisTemplate(LettuceConnectionFactory lettuceConnectionFactory){RedisTemplateString,Object redisTemplate new RedisTemplate();redisTemplate.setConnectionFactory(lettuceConnectionFactory);//设置key序列化方式stringredisTemplate.setKeySerializer(new StringRedisSerializer());//设置value的序列化方式json使用GenericJackson2JsonRedisSerializer替换默认序列化redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());redisTemplate.setHashKeySerializer(new StringRedisSerializer());redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());redisTemplate.afterPropertiesSet();return redisTemplate;} }4、Service import lombok.extern.slf4j.Slf4j; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service;import javax.annotation.Resource; import java.util.UUID; import java.util.concurrent.ThreadLocalRandom;Service Slf4j public class OrderService {public static final String ORDER_KEY order:;Resourceprivate RedisTemplate redisTemplate;public void addOrder(){int keyId ThreadLocalRandom.current().nextInt(1000)1;String orderNo UUID.randomUUID().toString();redisTemplate.opsForValue().set(ORDER_KEYkeyId,京东订单 orderNo);log.info(编号keyId的订单流水生成:{},orderNo);}public String getOrderById(Integer id){return (String)redisTemplate.opsForValue().get(ORDER_KEY id);} }5、Controller import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController;import javax.annotation.Resource; import java.util.concurrent.ThreadLocalRandom;Api(tags 订单接口) RestController Slf4j public class OrderController {Resourceprivate OrderService orderService;ApiOperation(新增订单)RequestMapping(value /order/add,method RequestMethod.POST)public void addOrder(){orderService.addOrder();}ApiOperation(按orderId查订单信息)RequestMapping(value /order/{id}, method RequestMethod.GET)public String findUserById(PathVariable Integer id){return orderService.getOrderById(id);} } 6、测试 存结果后出现反序列化问题 原因JDK序列化方式默认惹的祸 org.springframework.data.redis.serializer.JdkSerializationRedisSerializer 默认情况下RedisTemplate 使用该数据列化方式我们来看下源码 RedisTemplate#afterPropertiesSet() 解决方式使用StringRedisTemplate 连接集群 yaml文件 # redis集群 spring.redis.password111111 # 获取失败 最大重定向次数 spring.redis.cluster.max-redirects3 spring.redis.lettuce.pool.max-active8 spring.redis.lettuce.pool.max-wait-1ms spring.redis.lettuce.pool.max-idle8 spring.redis.lettuce.pool.min-idle0 spring.redis.cluster.nodes192.168.111.175:6381,192.168.111.175:6382,192.168.111.172:6383,192.168.111.172:6384,192.168.111.174:6385,192.168.111.174:6386 集群存在的问题 1、模拟节点下线人为模拟master-6381机器意外宕机手动shutdown先对redis集群命令方式手动验证各种读写命令6384上位替换原主节点6381。 原因Redis Cluster集群能自动感知并自动完成主备切换对应的slave6384会被选举为新的master节点。 2、出现经典故障SpringBoot客户端不会动态感知到RedisCluster的最新集群信息 【故障演练】 Redis Cluster集群部署采用了3主3从拓扑结构数据读写访问master节点 slave节点负责备份。当master宕机主从切换成功redis手动OKbut 2个经典故障 3、导致原因 SpringBoot2.X版本Redis默认的连接池采用Lettuce当Redis集群节点发生变化后Lettuce默认是不会刷新节点拓扑。 4、解决方案 排除lettuce采用jedis不推荐 重写连接工厂实例极度不推荐 Beanpublic DefaultClientResources lettuceClientResources() {return DefaultClientResources.create();}Beanpublic LettuceConnectionFactory lettuceConnectionFactory(RedisProperties redisProperties, ClientResources clientResources) {ClusterTopologyRefreshOptions topologyRefreshOptions ClusterTopologyRefreshOptions.builder().enablePeriodicRefresh(Duration.ofSeconds(30)) //按照周期刷新拓扑.enableAllAdaptiveRefreshTriggers() //根据事件刷新拓扑.build();ClusterClientOptions clusterClientOptions ClusterClientOptions.builder()//redis命令超时时间,超时后才会使用新的拓扑信息重新建立连接.timeoutOptions(TimeoutOptions.enabled(Duration.ofSeconds(10))).topologyRefreshOptions(topologyRefreshOptions).build();LettuceClientConfiguration clientConfiguration LettuceClientConfiguration.builder().clientResources(clientResources).clientOptions(clusterClientOptions).build();RedisClusterConfiguration clusterConfig new RedisClusterConfiguration(redisProperties.getCluster().getNodes());clusterConfig.setMaxRedirects(redisProperties.getCluster().getMaxRedirects());clusterConfig.setPassword(RedisPassword.of(redisProperties.getPassword()));LettuceConnectionFactory lettuceConnectionFactory new LettuceConnectionFactory(clusterConfig, clientConfiguration);return lettuceConnectionFactory;} 刷新节点集群拓扑动态感应 官网Redis Cluster · lettuce-io/lettuce-core Wiki · GitHub 改写yaml # redis集群 spring.redis.password111111 # 获取失败 最大重定向次数 spring.redis.cluster.max-redirects3 spring.redis.lettuce.pool.max-active8 spring.redis.lettuce.pool.max-wait-1ms spring.redis.lettuce.pool.max-idle8 spring.redis.lettuce.pool.min-idle0 #支持集群拓扑动态感应刷新,自适应拓扑刷新是否使用所有可用的更新默认false关闭 spring.redis.lettuce.cluster.refresh.adaptivetrue #定时刷新 spring.redis.lettuce.cluster.refresh.period2000 spring.redis.cluster.nodes192.168.111.175:6381,192.168.111.175:6382,192.168.111.172:6383,192.168.111.172:6384,192.168.111.174:6385,192.168.111.174:6386
http://www.dnsts.com.cn/news/164635.html

相关文章:

  • 游戏网站设计风格有哪些烟台高端网站建设公司
  • 网站建设哪个公司好网站后台用什么语言合适
  • 郑州做网站的专业公司wordpress内页锚文本
  • 注册域名和建立网站的过程网页版传奇手游排行榜
  • 集团网站建设工作方案怎么架设网站
  • 教育公司网站建设文案seo顾问是干什么
  • 网站建设市场拓展岗位腾讯企业邮箱官网入口
  • 站酷网官方入口网页版南通五建宏业建设工程有限公司网站
  • 余姚厂家高端网站设计简述jsp网站架构
  • 网站为什么要seo如何做ps4游戏视频网站
  • 做物流网站费用网站底部的制作
  • 做网站需要了解什么软件企业网站开发询问薇
  • 关于小城镇建设的网站西安网站建设招聘
  • jsp购物网站开发 论文上海新闻综合频道
  • 网站样式有哪些风格在线美图
  • 做网站多长时间深圳建网站的公
  • 百度云盘做网站好看的网站模版
  • 找人做logo网站万江东莞网站建设
  • 网站制作比较好的制作公司通信部门网站备案证明
  • 网站建设师做网站主要显哪些内容
  • 网站建设定制网站建设公司wordpress安装无法链接数据库文件
  • 专门做各种产品测评的网站html怎么做音乐网站
  • 网站建设投放广告做园区门户网站的需求分析
  • 仙桃网站设计网站开发建设挣钱吗
  • 仿站 做网站做网站运营好还是SEO好
  • cida室内设计师资格证百度seo关键词优化公司
  • 七台河网站制作做企业网站建设公司哪家好
  • 做微信公众号用什么网站黑龙江省住房和城乡建设部网站
  • 网站设计文字大小申请域名需要多久
  • 建设网站德州seo 服务