<div id="Article">
<h3>redis增删改查之Spring+redis代码实例</h3>
<p>java 文件</p>
<pre class="brush:sql;">
package ******.redis;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
/**
* Created by asdas 2017/11/9.
* for test
*/
public class TestRedis {
private static RedisTemplate redisTemplate;
private static ListOperations hellolistops;
public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext(new String[]{"applicationContext-redis.xml"});
//从Spring容器中根据bean的id取出我们要使用的userService对象
redisTemplate = (RedisTemplate) ac.getBean("redisTemplate");
hellolistops = redisTemplate.opsForList();
TestRedis tr = new TestRedis();
tr.addHello("test1", "first");
tr.addHello("test2", "second");
tr.addHello("test3", "third");
tr.delHello("test3");
tr.modHello("test2", "di er ge");
System.out.println(tr.getHello("test1"));
System.out.println(tr.getHello("test2"));
System.out.println(tr.getHello("test3"));
}
</pre>
<pre class="brush:sql;">
//////////增
public void addHello(String id, String hello) {
hellolistops.leftPush(id, hello);
//System.out.println(l);
}
/////////删
public void delHello(String id) {
redisTemplate.delete(id);
}
/////////改
public void modHello(String id, String hello_mod) {
redisTemplate.delete(id);
hellolistops.leftPush(id, hello_mod);
}
////////查
public String getHello(String id) {
return hellolistops.range(id, 0, -1).toString();
}
}</pre>
<p>pom文件</p>
<pre class="brush:sql;">
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
相关推荐
<modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.4.RELEASE</version> <relativePath/> <!-- ...
- `<modelVersion>`:定义POM的版本,通常是4.0.0。 - `<groupId>`:代表项目的组织标识,一般为域名反写。 - `<artifactId>`:父项目的唯一标识,不包含子项目名称。 - `<version>`:项目版本号。 - `...
<modelVersion>4.0.0</modelVersion> <groupId>com.taotao</groupId> <artifactId>taotao-parent</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <!-- 集中定义依赖版本号 --&...
<modelVersion>4.0.0</modelVersion><!--基本固定值--> <parent><!--继承的父POM--> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.6....
<modelVersion>4.0.0</modelVersion> <groupId>com.itmuch.maven.hello</groupId> <artifactId>hello-first</artifactId> <version>0.0.1-SNAPSHOT</version> ``` #### Maven目录约定 Maven遵循一套约定的...
<modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.5</version> <relativePath/> <!-...
<modelVersion>4.0.0</modelVersion> <groupId>com.hadoop.mapreduce</groupId> <artifactId>wordcount</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>wordcount</name...
<modelVersion>4.0.0</modelVersion> <groupId>Demo</groupId> <artifactId>Demo</artifactId> <version>1.0-SNAPSHOT</version> <!-- 配置资源文件 --> <build> <resources> <resource> <directory>src/...
<modelVersion>4.0.0</modelVersion> <groupId>test</groupId> <artifactId>SeleniumJava</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>SeleniumJava Maven Webapp</...
<modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.15</version> <relativePath/> <!-- lookup ...
<modelVersion>4.0.0</modelVersion> <groupId>com.lin</groupId> <artifactId>ssm_project</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <!-- 以下为依赖配置 --> ...
<modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.5.RELEASE</version> <relativePath/> ...
<modelVersion>4.0.0</modelVersion> <groupId>cn.itcast.maven</groupId> <artifactId>ssh</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <!-- 定义工具类的依赖 --> ...
<modelVersion>4.0.0</modelVersion> <groupId>io.grpc</groupId> <artifactId>protoc-gen-grpc-java</artifactId> <version>1.40.0</version> <packaging>pom</packaging> <name>io.grpc:grpc-compiler</name...
<modelVersion>4.0.0</modelVersion> <groupId>com.maven.test</groupId> <artifactId>springMybaits</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>springMybaits</name...
<modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <!-- 更多配置 --> </project> ``` - 注意:复制pom.xml时需确保`groupId`和`artifactId`字段正确无误。 通过以上步骤,可以成功搭建起...
<modelVersion>4.0.0</modelVersion> <groupId>com.xxx</groupId> <artifactId>ssmm0</artifactId> <version>1.0-SNAPSHOT</version> <name>ssmm0</name> <packaging>pom</packaging> <!-- 父模块 --> ...
<modelVersion>4.0.0</modelVersion> <groupId>parentwenjuan</groupId> <artifactId>wenjuan</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>wenjuan</name> </project> ...
<modelVersion>4.0.0</modelVersion> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch-analysis-hanlp</artifactId> <version>1.2.4</version> <packaging>jar</packaging> <name>elastic...
<modelVersion>4.0.0</modelVersion> <groupId>name.quanke</groupId> <artifactId>elasticsearch-java-study</artifactId> <version>1.0-SNAPSHOT</version> <build> <plugins> <plugin> <groupId>org....