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

旅游网站建设的建议天猫关键词排名怎么控制

旅游网站建设的建议,天猫关键词排名怎么控制,h网站建设,网站制作工作流程前言: 目前java操作redis的客户端有jedis跟Lettuce。在springboot1.x系列中,其中使用的是jedis, 但是到了springboot2.x其中使用的是Lettuce。 因为我们的版本是springboot2.x系列,所以今天使用的是Lettuce。关于jedis跟lettuce的区别&#…

前言:

目前java操作redis的客户端有jedis跟Lettuce。在springboot1.x系列中,其中使用的是jedis,
但是到了springboot2.x其中使用的是Lettuce。 因为我们的版本是springboot2.x系列,所以今天使用的是Lettuce。关于jedis跟lettuce的区别:Lettuce 和 Jedis 的定位都是Redis的client,所以他们当然可以直接连接redis server。Jedis在实现上是直接连接的redis server,如果在多线程环境下是非线程安全的,这个时候只有使用连接池,
为每个Jedis实例增加物理连接Lettuce的连接是基于Netty的,连接实例(StatefulRedisConnection)可以在多个线程间并发访问,
应为StatefulRedisConnection是线程安全的,所以一个连接实例(StatefulRedisConnection)就可以满足多线程环境下的并发访问,
当然这个也是可伸缩的设计,一个连接实例不够的情况也可以按需增加连接实例。

依赖:

<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId><version>2.1.3.RELEASE</version></dependency><!-- test单元测试用 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!-- redis依赖commons-pool 这个依赖一定要添加 --><dependency><groupId>org.apache.commons</groupId><artifactId>commons-pool2</artifactId><version>2.6.2</version></dependency>
</dependencies>

application.yml配置

server:port: 8989
spring:redis:host: 127.0.0.1port: 6379# 密码 没有则可以不填password: 123456# 如果使用的jedis 则将lettuce改成jedis即可lettuce:pool:# 最大活跃链接数 默认8max-active: 8# 最大空闲连接数 默认8max-idle: 8# 最小空闲连接数 默认0min-idle: 0

redis配置

    接下来我们需要配置redis的key跟value的序列化方式,默认使用的JdkSerializationRedisSerializer 这样的会导致我们
通过redis desktop manager显示的我们key跟value的时候显示不是正常字符。 所以我们需要手动配置一下序列化方式 新建一个
config包,在其下新建一个RedisConfig.java 具体代码如下/*** @Auther: yukong* @Date: 2018/8/17 14:58* @Description: redis配置*/
@Configuration
@AutoConfigureAfter(RedisAutoConfiguration.class)
public class RedisConfig {/*** 配置自定义redisTemplate* @return*/@BeanRedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {RedisTemplate<String, Object> template = new RedisTemplate<>();template.setConnectionFactory(redisConnectionFactory);//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer(Object.class);ObjectMapper mapper = new ObjectMapper();mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);serializer.setObjectMapper(mapper);template.setValueSerializer(serializer);//使用StringRedisSerializer来序列化和反序列化redis的key值template.setKeySerializer(new StringRedisSerializer());template.setHashKeySerializer(new StringRedisSerializer());template.setHashValueSerializer(serializer);template.afterPropertiesSet();return template;}}其中@Configuration 代表这个类是一个配置类,然后@AutoConfigureAfter(RedisAutoConfiguration.class) 是让我们这个配置类
在内置的配置类之后在配置,这样就保证我们的配置类生效,并且不会被覆盖配置。其中需要注意的就是方法名一定要
叫redisTemplate 因为@Bean注解是根据方法名配置这个bean的name的。

测试

package com.netcast.demo;import com.netcast.demo.entity.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;/*** @program: demo* @description:* @author: dchen* @create: 2019-11-14 14:53**/
@RunWith(SpringRunner.class)
@SpringBootTest
public class RedisTest {@Autowiredprivate RedisTemplate redisTemplate;@Testpublic void redisTest() {// redis存储数据String key = "name";redisTemplate.opsForValue().set(key, "yukong");// 获取数据String value = (String) redisTemplate.opsForValue().get(key);System.out.println("获取缓存中key为" + key + "的值为:" + value);User user = new User();user.setId("2");user.setName("yukong");user.setPhone("155662727272");String userKey = "yukong";redisTemplate.opsForValue().set(userKey, user);User newUser = (User) redisTemplate.opsForValue().get(userKey);System.out.println("获取缓存中key为" + userKey + "的值为:" + newUser);}
}

结果:

中文成功显示,并且对象在redis以json方式存储,代表我们配置成功。下列的就是Redis其它类型所对应的操作方式opsForValue: 对应 String(字符串)
opsForZSet: 对应 ZSet(有序集合)
opsForHash: 对应 Hash(哈希)
opsForList: 对应 List(列表)
opsForSet: 对应 Set(集合)

http://www.dtcms.com/wzjs/359200.html

相关文章:

  • 公司网络建设计划书郑州seo网络推广
  • 做网站运营有前途吗企业网站seo推广方案
  • 桂林有帮做公司网站吗淘宝运营培训课程
  • 黄冈网站推广代运营seo自然优化排名技巧
  • 临清网站制作公司seo搜索引擎优化软件
  • 贵州省建设厅考试网站创建一个网站
  • 做污事网站如何规划企业网络推广方案
  • 企业网站规划与开发牛奶推广软文文章
  • 南澳做网站上海哪家seo公司好
  • 最好网站制作工具网络舆情分析报告范文
  • 外贸有限公司英文网站苏州疫情最新通知
  • 给一瓶水做网站服务营销论文
  • 怎样查看别人网站流量关键词seo深圳
  • 南通企业建站系统模板太原百度关键词排名
  • 网站打开有声音是怎么做的商品促销活动策划方案
  • 农业门户网站建设目标google网站搜索
  • 泰州网站制作案例山东网络优化公司排名
  • 重庆宣网站建设推广接单平台哪个好
  • 做得比较好的公司网站创建自己的网址
  • 大连做网站价钱百度搜索app下载
  • 网站建设外包公司方案百度seo网络营销书
  • 做鞋的B2B网站杭州百度开户
  • 电脑网页设计教程电脑突然多了windows优化大师
  • 宣传做传单的网站长沙网站推广排名
  • 网站用excel做数据库seo公司多少钱
  • 怎么做企业官方网站seo关键词排名点击工具
  • 汽车网站建设策划书软文营销常用的方式是什么
  • 功能型网站建设时间电商沙盘seo裤子关键词
  • 拱墅区网站建设最近三天的国内新闻
  • 自己怎样注册企业网站nba东西部最新排名