当前位置:网站首页>windows上安装redis并永久修改密码,及ssm框架集成redis
windows上安装redis并永久修改密码,及ssm框架集成redis
2022-06-28 05:55:00 【不会code的coder】
首先是redis安装,这个在菜鸟教程上介绍的很详细,按照上面说的就可以做到。下面是他的网址:
安装完成后,我们先启动服务器,进入redis目录,按住shift然后右键,打开控制台。然后输入
redis-server.exe redis.windows.conf这样就打开服务器了,现在的redis是没有密码的,然后重复上面的步骤,输入:
redis-cli.exe -h 127.0.0.1 -p 6379 现在是打开客户端了,可以操作了。
我们在修改密码前,可以看下客户端有没有设置密码:
config get requirepass然后我们需要修改密码,这个有两种方式,第一种是直接代码修改,这个是只有当次生效,重新启动redis就没有了。第二种是修改redis配置文件,这样可以永久修改。第一种设置密码代码如下:
config set requirepass "yourpassword"//设置当前密码,服务重新启动后又会置为默认,即无密码;不建议此种方式第二种就需要修改redis安装目录下的redis.windows.conf文件了,找到# requirepass foobared,然后在下面添加一行
requirepass root保存,现在root就是你的密码了。
接下来我们需要关闭redis,重新启动。服务器端启动命令没有变,客户端命令需要在登录时添加上密码:
redis-cli.exe -h 127.0.0.1 -p 6379 -a 123456 //需添加密码参数这样就设置密码成功了。
然后我们需要集成到框架中去
首先,我们需要导入依赖,这个地方有可能出现一个错误,就是依赖版本问题,大家按照我的依赖版本导入是不会出问题的,否则会出现bug的:
<!-- spring 集成redis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
<!-- redis -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.8.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>我们在resources目录下创建一个redis.properties文件保存redis配置信息:
redis.maxIdle=300
redis.minIdle=100
redis.maxWaitMillis=3000
redis.testOnBorrow=true
redis.maxTotal=500
redis.host=127.0.0.1
redis.port=6379
redis.password=root然后,我们创建spring-redis.xml文件,用来配置redis并继承:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:property-placeholder location="classpath:redis.properties" ignore-unresolvable="true"/>
<!--设置数据池-->
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="${redis.maxIdle}"></property>
<property name="minIdle" value="${redis.minIdle}"></property>
<property name="maxTotal" value="${redis.maxTotal}"></property>
<property name="maxWaitMillis" value="${redis.maxWaitMillis}"></property>
<property name="testOnBorrow" value="${redis.testOnBorrow}"></property>
</bean>
<!--链接redis-->
<bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="${redis.host}"></property>
<property name="port" value="${redis.port}"></property>
<property name="password" value="${redis.password}"></property>
<property name="poolConfig" ref="poolConfig"></property>
</bean>
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory"/>
<!--以下针对各种数据进行序列化方式的选择-->
<property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
</property>
<property name="valueSerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
</property>
<property name="hashKeySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
</property>
<property name="hashValueSerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
</property>
</bean>
</beans>然后,我们需要把这些配置放到web.xml中,使得tomcat启动后,就直接加载这些配置文件:
<!-- mybatis 和redis配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-redis.xml,classpath:spring-mybatis.xml</param-value>
</context-param>现在就算集成完毕了,我们可以测试一下,我新建一个controller,
package com.mail.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.AddressException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
/**
* Created by linmeng.
**/
@RestController
public class MailController {
@Resource
private RedisTemplate<String, Object>redisTemplate;
/**
* 发送邮件
*/
@RequestMapping("/email")
public void sendMail(){
Map<String,String> map = new HashMap<>();
map.put("name", "xiaoming");
map.put("age", "18");
redisTemplate.opsForValue().set("name", "xiaoming");
System.out.println(redisTemplate.opsForValue().get("name"));
}
}
如果控制台能够打印出东西,说明已经可以在项目中使用了。
边栏推荐
- Global country (and region) information JSON data
- JSP connects with Oracle to realize login and registration (simple)
- 预训练模型参数不匹配
- UICollectionViewDiffableDataSource及NSDiffableDataSourceSnapshot使用介绍
- Typescript interface
- @Autowired注解为空的原因
- Deep learning 19 loss functions
- Jenkins继续集成2
- Cryptography notes
- Object对象转 List集合
猜你喜欢

Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance

如何在您的Shopify商店中添加实时聊天功能?

Where is the era bonus for developers?

mac下安装多个版本php并且进行管理
![Video tutorial on website operation to achieve SEO operation [21 lectures]](/img/1f/9ae2ed5bfec5749c764630d1daccea.jpg)
Video tutorial on website operation to achieve SEO operation [21 lectures]

什么是WebRTC?

YYGH-BUG-02

FB、WhatsApp群发消息在2022年到底有多热门?

Solution of dam safety automatic monitoring system for medium and small reservoirs

Oracle condition, circular statement
随机推荐
The windows environment redis uses AOF persistence and cannot generate an AOF file. After generation, the content of the AOF file cannot be loaded
Data center: Seven Swords of data governance
电子邮件营销的优势在哪里?为什么shopline独立站卖家如此重视?
简单手写debounce函数
ipvs 导致syn 重传问题
Qtcanpool q05: no border
JQ picture amplifier
19 fonctions de perte d'apprentissage profond
一看就会 MotionLayout使用的几种方式
数据中台:数据治理的七把利剑
小球弹弹乐
Application of Beidou No.3 short message terminal in dam safety monitoring scheme
Taobao seo training video course [22 lectures]
Filecoin hacker song developer competition
Error: the following arguments are required:
[C language practice - printing hollow square and its deformation]
How to do a good job of dam safety monitoring
ES9023音频解码芯片的工作原理
电商转化率这么抽象,到底是个啥?
Filecoin黑客松开发者大赛