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

梧州网站设计公司深圳网络seo推广

梧州网站设计公司,深圳网络seo推广,服务平台名称,网站开发难题步骤 引入依赖配置数据库参数编写配置类构造RedisTemplate创建测试类测试 1.引入依赖 不写版本号#xff0c;也是可以的 在pom中引入 !--redis配置-- dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-…步骤 引入依赖配置数据库参数编写配置类构造RedisTemplate创建测试类测试 1.引入依赖 不写版本号也是可以的 在pom中引入 !--redis配置-- dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-redis/artifactId /dependency 2.配置数据库参数 在SpringBoot的yaml配置文件中引入如果你用的是properties格式那么去转换一下就行了把yaml转换成properties spring:redis:# Redis数据库索引默认为0database: 11# Redis服务器地址host: localhost# Redis服务器连接端口port: 6379# Redis服务器连接密码默认为空password: # 连接超时时间毫秒timeout: 1000 3.编写配置类 package com.kyw.config;import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.RedisSerializer;Configuration public class RedisConfig {Beanpublic RedisTemplateString,Object redisTemplate(RedisConnectionFactory factory) {RedisTemplateString,Object template new RedisTemplate();template.setConnectionFactory(factory);// 设置key的序列化方式template.setKeySerializer(RedisSerializer.string());// 设置value的序列化方式template.setValueSerializer(RedisSerializer.json());// 设置hash的key序列化方式template.setHashKeySerializer(RedisSerializer.string());// 设置hash的value序列化方式template.setHashValueSerializer(RedisSerializer.json());// 在设置完参数后生效template.afterPropertiesSet();return template;}} 4.构造RedisTemplate 上面的配置类中就构造好了 5.测试 这里用的是junit测试是常用的测试工具没有导入的小伙伴导入一下网上搜一下很简单。 编写测试类 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.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner;RunWith(SpringRunner.class) SpringBootTest //下面括号里面classes SpringBootDemoApplication.class如果报错那你转换成自己的SpringBoot启动类的类名就行 ContextConfiguration(classes SpringBootDemoApplication.class) public class RedisTest {Autowiredprivate RedisTemplate redisTemplate;}测试String /***String 测试*/ Test public void testStrings(){String redisKey test:count;//设置一个 key valueredisTemplate.opsForValue().set(redisKey,1);//获取valueSystem.out.println(redisTemplate.opsForValue().get(redisKey));//value自增System.out.println(redisTemplate.opsForValue().increment(redisKey));//value自减System.out.println(redisTemplate.opsForValue().decrement(redisKey)); }测试哈希 /***哈希 测试*/ Test public void testHashes(){String redisKey test:user;redisTemplate.opsForHash().put(redisKey,id,1);redisTemplate.opsForHash().put(redisKey,username,张三);System.out.println(redisTemplate.opsForHash().get(redisKey,id));System.out.println(redisTemplate.opsForHash().get(redisKey,username)); }测试list /***list 类测试*/ Test public void testLists(){String redisKey test:ids;redisTemplate.opsForList().leftPush(redisKey,101);redisTemplate.opsForList().leftPush(redisKey,102);redisTemplate.opsForList().leftPush(redisKey,103);System.out.println(redisTemplate.opsForList().size(redisKey));System.out.println(redisTemplate.opsForList().index(redisKey,0));System.out.println(redisTemplate.opsForList().range(redisKey,0,2));System.out.println(redisTemplate.opsForList().leftPop(redisKey));System.out.println(redisTemplate.opsForList().leftPop(redisKey));System.out.println(redisTemplate.opsForList().leftPop(redisKey));} 测试set /***set 测试*/ Test public void testSets(){String redisKey test:teachers;redisTemplate.opsForSet().add(redisKey,鸣人,路飞,韩立,炭治郎,祖国人);System.out.println(redisTemplate.opsForSet().size(redisKey));System.out.println(redisTemplate.opsForSet().pop(redisKey));System.out.println(redisTemplate.opsForSet().pop(redisKey));} 测试zset Test public void testSortSets(){String redisKey test:students;redisTemplate.opsForZSet().add(redisKey,少年鸣人,10);redisTemplate.opsForZSet().add(redisKey,仙人鸣人,60);redisTemplate.opsForZSet().add(redisKey,九尾鸣人,70);redisTemplate.opsForZSet().add(redisKey,九喇嘛联结鸣人,80);redisTemplate.opsForZSet().add(redisKey,六道鸣人,90);System.out.println(redisTemplate.opsForZSet().zCard(redisKey));System.out.println(redisTemplate.opsForZSet().score(redisKey,六道鸣人));System.out.println(redisTemplate.opsForZSet().reverseRank(redisKey,六道鸣人));System.out.println(redisTemplate.opsForZSet().range(redisKey,0,4));System.out.println(redisTemplate.opsForZSet().removeRange(redisKey,0,2));} 测试通用操作 /***测试通用操作*/ Test public void testKeys(){redisTemplate.delete(test:user);System.out.println(redisTemplate.hasKey(test:user));redisTemplate.expire(text:students,10, TimeUnit.SECONDS); } 测试绑定key到变量的操作 /***测试 绑定一个key 的操作*/ Test public void testBondOperations(){String redisKey test:count;//用 BoundValueOperations 将一个key绑定到对象上方便后面的操作//绑定的是 String 那就 BoundValueOperations是set 那就BoundSetOperations,其余同理BoundValueOperations operations redisTemplate.boundValueOps(redisKey);System.out.println(operations.get());operations.increment();operations.increment();System.out.println(operations.get());} 如果您觉得文章还不错麻烦点个赞吧
http://www.hkea.cn/news/14388535/

相关文章:

  • 网站开发需要哪些人才淘宝seo排名优化
  • 深圳定制专业网站网站建设与管理案例教程教学大纲
  • 一站式建设网站电子商务网站有哪些?
  • 天津专业网站设计报价自己怎么优化网站
  • 天津怎样做网站推广泰安企业网站制作
  • 银川网站建设价格六安做网站多少钱
  • 北京建设招聘信息网站分销系统合法吗
  • 环保局网站建设wordpress导入项目
  • 如何提高网站收录数同城信息网站建设
  • 加强政协机关网站建设wordpress图片添加音乐
  • 国外对旅游网站建设的现状竞价托管一般多少
  • 姚家园做网站开发工具包
  • python 营销型网站建设查询关键词排名工具
  • 网站建设论文模板深圳住房建设局网站首页
  • 朝阳区网站开发公司wordpress查询功能
  • 用vs2005做网站设计安庆注册公司
  • 上海湖南网站建设外包公司要不要去
  • 仿静态网站wordpress注册页面不跳转
  • 网站建设费用能否计入广告费房地产销售新手入门知识
  • 江苏网站建设电话用凡科网做网站怎么保存到桌面
  • 东莞在哪里学网站建设青岛做网络直播的网站
  • 怎样建设大型网站网站建设公司知名企业
  • 陕西建设厅官方网站seo交流网
  • 蚌埠建设银行网站粤嵌嵌入式培训
  • 网站开发系统的可行性研究报告网站建设公司西安
  • 北京网站建设cnevo莱州网页
  • 网站建设有哪些企业搜索推广图片
  • 做外贸网站公司哪家好wordpress建立cms
  • 烟台H5网站设计莱芜杂谈 莱芜话题
  • 建设门户网站的申请如何做招聘网站的对比