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

2019为赌博网站做代理被判缓刑太原网站建设谁家好

2019为赌博网站做代理被判缓刑,太原网站建设谁家好,html5手机网站模板,中企做的网站太原目录 一、Jedis 二、Lettuce 三、一个Demo Java集成Redis主要有3个方案:Jedis、Lettuce和Redisson。 其中,Jedis、Lettuce侧重于单例Redis,而Redisson侧重于分布式服务。 项目资源在文末 一、Jedis 1、创建SpringBoot项目 2、引入依赖 …

目录

一、Jedis

二、Lettuce

三、一个Demo


Java集成Redis主要有3个方案:Jedis、Lettuce和Redisson。

其中,Jedis、Lettuce侧重于单例Redis,而Redisson侧重于分布式服务。

项目资源在文末


一、Jedis

1、创建SpringBoot项目

2、引入依赖

其中,jedis是所需要的依赖,lombok是为了方便后续配置

        <dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency>

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

3、 配置yml

#redis配置--jedis版
jedis:pool:#redis服务器的IPhost: localhost#redis服务器的Portport: 6379#数据库密码password:#连接超时时间timeout: 7200#最大活动对象数maxTotall: 100#最大能够保持idel状态的对象数maxIdle: 100#最小能够保持idel状态的对象数minIdle: 50#当池内没有返回对象时,最大等待时间maxWaitMillis: 10000#当调用borrow Object方法时,是否进行有效性检查testOnBorrow: true#当调用return Object方法时,是否进行有效性检查testOnReturn: true#“空闲链接”检测线程,检测的周期,毫秒数。如果为负值,表示不运行“检测线程”。默认为-1.timeBetweenEvictionRunsMillis: 30000#向调用者输出“链接”对象时,是否检测它的空闲超时;testWhileIdle: true# 对于“空闲链接”检测线程而言,每次检测的链接资源的个数。默认为3.numTestsPerEvictionRun: 50

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

4、导入配置文件和加载配置类

导入配置文件:JedisProperties,导入yml文件内容

加载配置类:JedisConfig,加载JedisProperties内容

①JedisProperties

package com.example.redis_java.config;import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;@Component
@ConfigurationProperties(prefix = "jedis.pool")
@Getter
@Setter
public class JedisProperties {private int maxTotall;private int maxIdle;private int minIdle;private int maxWaitMillis;private boolean testOnBorrow;private boolean testOnReturn;private int timeBetweenEvictionRunsMillis;private boolean testWhileIdle;private int numTestsPerEvictionRun;private String host;private String password;private int port;private int timeout;
}

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

②JedisConfig

说明:如果SpringBoot是2.x版本,JedisConfig请使用注释掉的两行代码而不是它们对应的上面的代码

package com.example.redis_java.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;import java.time.Duration;@Configuration
public class JedisConfig {/*** jedis连接池** @param jedisProperties* @return*/@Beanpublic JedisPool jedisPool(JedisProperties jedisProperties) {JedisPoolConfig config = new JedisPoolConfig();config.setMaxTotal(jedisProperties.getMaxTotall());config.setMaxIdle(jedisProperties.getMaxIdle());config.setMinIdle(jedisProperties.getMinIdle());config.setMaxWait(Duration.ofMillis(jedisProperties.getMaxWaitMillis()));// config.setMaxWaitMillis(jedisProperties.getMaxWaitMillis());config.setTestOnBorrow(jedisProperties.isTestOnBorrow());config.setTestOnReturn(jedisProperties.isTestOnReturn());config.setTimeBetweenEvictionRuns(Duration.ofMillis(jedisProperties.getTimeBetweenEvictionRunsMillis()));// config.setTimeBetweenEvictionRunsMillis(jedisProperties.getTimeBetweenEvictionRunsMillis());config.setTestWhileIdle(jedisProperties.isTestWhileIdle());config.setNumTestsPerEvictionRun(jedisProperties.getNumTestsPerEvictionRun());if (StringUtils.hasText(jedisProperties.getPassword())) {return new JedisPool(config, jedisProperties.getHost(), jedisProperties.getPort(), jedisProperties.getTimeout(), jedisProperties.getPassword());}return new JedisPool(config, jedisProperties.getHost(), jedisProperties.getPort(), jedisProperties.getTimeout());}
}

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

③项目结构

5、测试

①测试前

②测试类

package com.example.redis_java;import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;@SpringBootTest
public class JedisTest {@Autowiredprivate JedisPool jedisPool;@Testpublic void testConnection() {System.out.println(jedisPool);Jedis jedis = jedisPool.getResource();jedis.set("name", "Trxcx");System.out.println(jedis.get("name"));jedis.sadd("mySet", "a", "b", "d");System.out.println(jedis.smembers("mySet"));// jedis的方法名就是redis的命令jedis.close();}
}

③项目结构

  

④运行测试类

⑤测试后

说明:jedis的方法名就是redis的命令。如sadd、smembers。


二、Lettuce

Lettuce配置比较简单,这里直接在上一个项目的基础上进行配置,新项目配置Lettuce方法一致。

1、引入依赖

        <!--Lettuce依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency>

2、配置yml

如果有密码,设置对应的密码。

spring:redis:host: 127.0.0.1port: 6379# password: admin

3、测试

①编写测试类

package com.example.redis_java;import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;@SpringBootTest
public class LettureTest {@Autowiredprivate StringRedisTemplate template;// 约定:// 操作redis的key是字符串// value是字符串类型或字符串类型元素@Testpublic void testRedis() {template.opsForValue().set("name", "Trxcx");System.out.println(template.opsForValue().get("name"));template.opsForSet().add("Games","RDR2","CS2","ACOd");System.out.println(template.opsForSet().members("Games"));// 操作string// template.opsForValue().xx();// 操作hash// template.opsForHash().xx();// 操作list// template.opsForList().xx();// 操作set// template.opsForSet().xx();// 操作zset// template.opsForZSet().xx();// spring-data-redis方法是redis命令全称// template.opsForList().rightPush()  //rpush// 全局命令在template类上// template.keys("*");}
}

②项目结构

③运行测试类

4、说明:

①Lettuce使用StringRedisTemplate的一个对象完成对Redis的操作,不存在像Jedis那样获取Redis资源使用完再关闭的情况。

②Lettuce通过opsForxxx完成对不同value类型的操作,例如

  • opsForValue()是操作String类型的
  • opsForHash()是操作Hash类型的
  • opsForList()是操作List类型的
  • opsForSet()是操作Set类型的
  • opsForZSet()是操作Zset类型的

③Lettuce的方法名是Redis命令的全称

例如:template.opsForList().rightPush(),对应Redis中的rpush命令

④全局命令作用在StringRedisTemplate对象上

例如:template.keys("*");


三、一个Demo

这个demo实现了每次刷新或者访问网页时,阅读量+1的效果。

启动SpringBoot项目后,访问http://localhost:8080/detail.html,每次刷新页面阅读量+1。 


项目资源链接:

1、【免费】Redis-Java.zip资源-CSDN文库

2、【免费】RedisDemo.zip资源-CSDN文库 

http://www.mmbaike.com/news/50336.html

相关文章:

  • 用jsp做校园网站怎样推广网站
  • 建设微信商城网站电子商务网店运营推广
  • 网站注册页面推广app的方法和策略
  • 做网站的语言有哪些优秀的营销策划案例
  • 重庆公司网站开发网络服务合同
  • 网站制作哪里好薇少儿编程培训机构排名前十
  • 网站开发怎么实现用户一对一发文字图片杭州百度代理公司
  • 内蒙古城乡建设和住房建设厅网站重庆网站页面优化
  • 中国人民建设银行网站怎样建立网站免费的
  • 淘宝网站咋做淘宝关键词优化
  • 做程序开发的网站seo免费推广软件
  • 网站建设公司销售电脑优化大师哪个好
  • 徐州品牌网站建设湖南seo网站策划
  • 惠州做棋牌网站建设哪家便宜seo优化需要做什么
  • 营销网站开发网站的推广方式
  • wordpress图片上传后显示不出来厦门关键词seo排名网站
  • 游戏网站建设内容seo搜索引擎是什么意思
  • 中医协会网站建设方案网址搜索引擎入口
  • 什么是网站空间seo顾问
  • wordpress如何和curl通信seo实战教程
  • 甘肃网站建站系统平台百度网站排名seo
  • 网站怎么做跳转链接seo优化搜索结果
  • iis7 无法添加网站链友之家
  • 做宣传语的网站怎么开发自己的网站
  • 网站开发语言包括哪些全球最大的中文搜索引擎
  • 怎么做网页 在浏览器上seo整站优化报价
  • 网站建设安全级别谷歌广告代运营
  • 网站建设 系统维护seo权重查询
  • 做电影网站收入外贸网站
  • 网站建设里怎么写文章国内十大软件培训机构