zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

Redis下载部署并加入idea应用的小结

2023-06-13 09:19:48 时间
1.打开网址:github上的redis安装包,找到Redis on Windows,点击 release page。

2.选择你要下载的版本,点击安装程序进行下载

3.安装 一直点 下一步 直至完成安装就行,注意自己的安装目录(下面的配置环境变量要用到,我自己的路径是D:\Redis)

二、配置环境变量

1.右击我的电脑,选择属性

2.点击 高级系统设置 ,我这是win11系统,你们自己找哈!

3.点击环境变量

4.双击Path

5.点击新建,把安装redis的对应目录写进去,然后确定。

6.点击win+R,输入cmd

7.输入命令redis-cli,连接成功!

到这里redis部署就完成了!!!下面是redis在idea里面的应用! 三、redis在idea的应用 1.打开pom.xml文件,引入redis架包,代码如下

代码如下:

dependency
groupId org.springframework.boot /groupId
artifactId spring-boot-starter-data-redis /artifactId
/dependency

2.打开application.properties配置文件,写入redis的相关配置

代码如下:

# RedisProperties
#redis一共有16(0-15)个数据库,随便给一个
spring.redis.database=11
spring.redis.host=localhost
spring.redis.port=6379

3.新建一个配置类redisConfig.java文件,代码如下

package com.example.community.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;

/**
* @ClassName redisConfig
* @Description TODO
* @Author 加辣椒了吗?
* @Date 2022/4/28 2:33
* @Version 1.0
**/
@Configuration
public class redisConfig {
@Bean
public RedisTemplate String,Object redisTemplate(RedisConnectionFactory factory){
// 将redis注入工厂
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.测试 在测试类里面添加测试方法,测试通过

代码如下:

package com.example.community.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;

/**
* @ClassName redisConfig
* @Description TODO
* @Author 加辣椒了吗?
* @Date 2022/4/28 2:33
* @Version 1.0
**/
@Configuration
public class redisConfig {
@Bean
public RedisTemplate String,Object redisTemplate(RedisConnectionFactory factory){
// 将redis注入工厂
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;
}
}

或者
打开redis控制台,输入以下命令,测试通过!

到此这篇关于Redis下载部署并加入idea应用的文章就介绍到这了,更多相关Redis下载部署内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!


我想要获取技术服务或软件
服务范围:MySQL、ORACLE、SQLSERVER、MongoDB、PostgreSQL 、程序问题
服务方式:远程服务、电话支持、现场服务,沟通指定方式服务
技术标签:数据恢复、安装配置、数据迁移、集群容灾、异常处理、其它问题

本站部分文章参考或来源于网络,如有侵权请联系站长。
数据库远程运维 Redis下载部署并加入idea应用的小结