Springboot connection redis for crud

Springboot connects redis for CRUD:

1. Add the following dependencies:

 

org.springframework.boot
spring-boot-starter-data-redis


redis.clients
jedis
2.9.0

2. Configure redis parameters in application.properties

spring.redis.database= 0

spring.redis.host
=47.106.198.29
spring.redis.port
=6379
spring.redis.password
=password1
spring.redis.jedis.pool.max
-wait=3600
spring.redis.jedis.pool.max
-active=1
spring.redis.jedis.pool.max
-idle=1
spring.redis.jedis.pool.min
-idle=1
spring.redis.timeout
=3600

3. Write the controller class

import org.springframework.data.redis.core.RedisTemplate;

import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class RedisController {

@Resource
private RedisTemplate redisTemplate;

@RequestMapping(
"/set")
public boolean set() {
ValueOperations
stringStringValueOperations = redisTemplate.opsForValue();
stringStringValueOperations.set(
"keyk", "valuev");
return true;
}

@RequestMapping(
"/get")
public String get() {
ValueOperations
stringStringValueOperations = redisTemplate.opsForValue();
return stringStringValueOperations.get("keyk");
}

@RequestMapping(
"/del")
public boolean del() {
return redisTemplate.delete("keyk");
}

@RequestMapping(
"/update ")
public boolean update() {
ValueOperations
stringStringValueOperations = redisTemplate.opsForValue();
stringStringValueOperations.set(
"keyk", "valuevUpdate");
return true;
}
}

4. Start and run, you can add, delete, modify and check normally.

Reference from: https://blog.csdn.net/aisu_yan/article/details/84787214

< p>

 

org.springframework.boot
spring-boot-starter-data-redis


redis.clients
jedis
2.9.0

spring.redis.database=0

spring.redis.host
=47.106.198.29
spring.redis.port
=6379
spring.redis.password
=password1
spring.redis.jedis.pool.max
-wait=3600
spring.redis.jedis.pool.max
-active=1
spring.redis.jedis.pool.max
-idle=1
spring.redis.jedis.pool.min
-idle=1
spring.redis.timeout
=3600

import org.springframework.data.redis.core.RedisTemplate;

import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class RedisController {

@Resource
private RedisTemplate redisTemplate;

@RequestMapping(
"/set")
public boolean set() {
ValueOperations
stringStringValueOperations = redisTemplate.opsForValue();
stringStringValueOperations.set(
"keyk", "valuev");
return true;
}

@RequestMapping(
"/get")
public String get() {
ValueOperations
stringStringValueOperations = redisTemplate.opsForValue();
return stringStringValueOperations.get("keyk");
}

@RequestMapping(
"/del")
public boolean del() {
return redisTemplate.delete("keyk");
}

@RequestMapping(
"/update ")
public boolean update() {
ValueOperations
stringStringValueOperations = redisTemplate.opsForValue();
stringStringValueOperations.set(
"keyk", "valuevUpdate");
return true;
}
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4715 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.