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

网站建设的流程 步骤网站推广策略

网站建设的流程 步骤,网站推广策略,上海社会建设网站,网站图片规格前言: 目前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/302143.html

相关文章:

  • 网站首页banner动态化怎么做市场营销和推广
  • qq刷网站空间关键词排名优化系统
  • 万网域名中文网站查询百度网页版下载安装
  • 网站建立的流程灰色关键词排名
  • 网站建设费账务处理百度最怕哪个部门去投诉
  • wordpress 两个导航扬州整站seo
  • 平顶山做网站哪家好培训机构排名前十
  • 网站建设网站服务西安百度推广竞价托管
  • 网站制作现状解决方案外贸平台有哪些?
  • 动态网站中如何做项目栏百度seo关键词排名查询工具
  • 来个可以做渗透的网站企业营销推广
  • 做网站需要哪些程序员百度首页排名优化服务
  • 岳阳做网站哪家好打开百度一下搜索
  • 精品课程网站建设方案深圳网络营销策划公司
  • wordpress自动汉化版宁波seo推广定制
  • 上海网站搜索排名自助建站系统破解版
  • 万江仿做网站网站怎么做到秒收录
  • 网站前置审批在哪里办百度一下移动版首页
  • 江苏高效网站制作公司深圳网络优化推广公司
  • 临沂公司做网站网建
  • 专业苏州网站建设公司最新域名解析
  • 网站上做地图手机上显示免费的网页入口
  • 企业网站首页设计原则湖南平台网站建设设计
  • wordpress 营销模板下载百度网站推广排名优化
  • wordpress错误怎么解决西安seo优化培训
  • 做网站优化词怎么选择前端seo搜索引擎优化
  • 品牌营销策划方案ppt个人做seo怎么赚钱
  • 建立一个自己的网站需要多少钱竞价推广托管公司介绍
  • 动态html做网站背景搜索引擎内部优化
  • 邯郸商城网站建站大的网站建设公司