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

文字生成器在线制作夫唯老师seo

文字生成器在线制作,夫唯老师seo,php做网站示例,html5 网站源代码步骤 引入依赖配置数据库参数编写配置类构造RedisTemplate创建测试类测试 1.引入依赖 不写版本号&#xff0c;也是可以的 在pom中引入 <!--redis配置--> <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-…

步骤

  1. 引入依赖
  2. 配置数据库参数
  3. 编写配置类
  4. 构造RedisTemplate
  5. 创建测试类测试

1.引入依赖

不写版本号,也是可以的

在pom中引入

<!--redis配置-->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

2.配置数据库参数

在SpringBoot的yaml配置文件中引入,如果你用的是properties格式,那么去转换一下就行了,把yaml转换成properties

spring:redis:# Redis数据库索引(默认为0)database: 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 RedisTemplate<String,Object> redisTemplate(RedisConnectionFactory factory) {RedisTemplate<String,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.dinnco.com/news/46317.html

相关文章:

  • 唐山网站建设互众动力青岛seo软件
  • web前端开发是干什么的北京seo百科
  • 同江佳木斯网站建设怎么投放网络广告
  • 做网站开发哪种语言更稳定高效天天seo站长工具
  • 做外贸一定要独立网站吗今日新闻热点大事件
  • 用word做网站苏州seo建站
  • 小说网站开发成本广州seo公司排名
  • wordpress 浏览量墨子学院seo
  • 婚纱摄影网站管理系统seo优化大公司排名
  • 太和网站建设数据库营销
  • wordpress仿站开发广州google推广
  • 企业网站怎么备案网店代运营可靠吗
  • 石家庄网站排名优化搜狗推广登录入口
  • 个人网站首页设计欣赏浑江区关键词seo排名优化
  • 农业门户网站建设目标交换友情链接
  • 怎么注册公司域名邮箱优化大师人工服务电话
  • 表白墙网站怎么做杭州搜索引擎推广排名技术
  • 在axure中做网站首页抖音推广
  • 湖南建设部网站宁波受欢迎全网seo优化
  • 山东做网站的公司有哪些友情链接分析
  • 嵌入式软件开发工程师证书南京seo推广公司
  • 自己做个网站怎么做如何加入广告联盟赚钱
  • 做网站需要相机吗网络优化工程师骗局
  • 外贸网站模板外贸网站建设长沙百度开户
  • 网站代码隐蔽代码建立网站的流程
  • 上海影视传媒公司排名网站排名优化方法
  • 国内知名的网站建设公司win10优化大师免费版
  • 织梦快速建站百度官方版下载
  • 襄阳哪里做网站2022最好的百度seo
  • 大气红色网站宁波网站建设团队