2025年yml文件配置redis(yaml配置redis)

yml文件配置redis(yaml配置redis)blockquote package com example boot3 controller import org springframew beans factory annotation Autowired import org springframew data redis core StringRedisT import org blockquote

大家好,我是讯享网,很高兴认识大家。



 <blockquote> 

讯享网

讯享网
package com.example.boot3.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { 
讯享网&#64;Autowired private StringRedisTemplate redisTemplate; &#64;GetMapping(&#34;/hello&#34;) public String Hello(){ return &#34;Hello&#34;; } &#64;GetMapping(&#34;/incr&#34;) public String incr(){ Long haha &#61; redisTemplate.opsForValue().increment(&#34;haha&#34;); return &#34;增加后的为&#34; &#43; haha; } 
}


讯享网

 
 
讯享网&lt;?xml version=“1.0” encoding=“UTF-8”?&gt; &lt;project xmlns=“http://maven.apache.org/POM/4.0.0" xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance" 
 xsi:schemaLocation&#61;&#34;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&#34;&gt; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt; &lt;parent&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt; &lt;version&gt;3.2.1&lt;/version&gt; &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt; &lt;/parent&gt; &lt;groupId&gt;com.example&lt;/groupId&gt; &lt;artifactId&gt;boot3&lt;/artifactId&gt; &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt; &lt;name&gt;boot3&lt;/name&gt; &lt;description&gt;boot3&lt;/description&gt; &lt;properties&gt; &lt;java.version&gt;17&lt;/java.version&gt; &lt;/properties&gt; &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;com.alibaba&lt;/groupId&gt; &lt;artifactId&gt;druid&lt;/artifactId&gt; &lt;version&gt;1.2.16&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-data-redis&lt;/artifactId&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt; &lt;scope&gt;test&lt;/scope&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; 
&lt;/project&gt;
讯享网
server: port: 9999 spring: servlet: 
讯享网multipart: max-file-size: 10MB 
data:
redis: host: 192.168.92.129 port: 6379 database: 0 password: abc123 lettuce: pool: max-active: 8 max-wait: -1ms max-idle: 8 min-idle: 0 timeout: 5000</pre> 
讯享网
&lt;?xml version=“1.0” encoding=“UTF-8”?&gt; &lt;beans xmlns=“http://www.springframework.org/schema/beans" 
讯享网 xmlns:xsi&#61;&#34;http://www.w3.org/2001/XMLSchema-instance&#34; xsi:schemaLocation&#61;&#34;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd&#34;&gt; &lt;bean id&#61;&#34;user&#34; class&#61;&#34;com.example.boot3.bean.User&#34; scope&#61;&#34;prototype&#34;&gt; &lt;property name&#61;&#34;id&#34; value&#61;&#34;1&#34;&gt;&lt;/property&gt; &lt;property name&#61;&#34;name&#34; value&#61;&#34;Jack&#34;&gt;&lt;/property&gt; &lt;/bean&gt; &lt;bean id&#61;&#34;cat&#34; class&#61;&#34;com.example.boot3.bean.Cat&#34;&gt; &lt;property name&#61;&#34;id&#34; value&#61;&#34;2&#34;&gt;&lt;/property&gt; &lt;property name&#61;&#34;name&#34; value&#61;&#34;Rose&#34;&gt;&lt;/property&gt; &lt;/bean&gt; 
&lt;/beans&gt;
 
 
讯享网package com.example.boot3; import com.example.boot3.bean.*; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; @ComponentScan(”com.example“)//改变包扫描路径 @SpringBootApplication(scanBasePackages = ”com.example.boot3“)//手动指定扫描包位置 public class Boot3Application { 
public static void main(String[] args) { var ioc &#61; SpringApplication.run(Boot3Application.class, args); 
// for (String name : ioc.getBeanDefinitionNames()) { // System.out.println(name); // } // Object user = ioc.getBean(”user“); // Object user1 = ioc.getBean(”user“); // System.out.println(user == user1); // System.out.println(ioc.getBean(”fastsqlException“));
讯享网 for (String s : ioc.getBeanNamesForType(Cat.class)) { System.out.println(s); } for (String s : ioc.getBeanNamesForType(Dog.class)) { System.out.println(s); } for (String s : ioc.getBeanNamesForType(User.class)) { System.out.println(s); } Object pig &#61; ioc.getBean(&#34;pig&#34;); System.out.println(pig); 
// for (String s : ioc.getBeanNamesForType(Sheep.class)) { // System.out.println(s); // }
 Object sheep &#61; ioc.getBean(Sheep.class); System.out.println(sheep); } 
}
讯享网

 127.0.0.1:6381&gt; shutdown
not connected&gt; quit
[root@localhost ~]# redis-cli -a abc123 -p 6382 -c –raw
Warning: Using a password with ‘-a’ or ‘-u’ option on the command line interface may not be safe.
127.0.0.1:6382&gt; shutdown
not connected&gt; quit
[root@localhost ~]# redis-server /myredis/redis6379.conf 
[root@localhost ~]# redis-cli -a abc123 -p 6379 –raw
Warning: Using a password with ‘-a’ or ‘-u’ option on the command line interface may not be safe.
127.0.0.1:6379&gt; get haha
12

小讯
上一篇 2025-06-13 22:46
下一篇 2025-04-30 19:09

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/191841.html