Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to integrate redis with Springboot to achieve simple data writing and reading

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "Springboot how to integrate redis to achieve simple data writing and reading", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how Springboot integrates redis to achieve simple data writing and reading.

Introduce maven dependency: org.redisson redisson-spring-boot-starter ${redission} redisUtil.javapackage com.gllic.workweixin.utils;import org.redisson.api.RBucket;import org.redisson.api.RedissonClient;import org.springframework.stereotype.Component;import javax.annotation.Resource;import java.util.concurrent.TimeUnit;@Componentpublic class RedisUtil {@ Resource private RedissonClient redissonClient; public boolean setString (String key, Object value, long time) {try {RBucket rBucket = redissonClient.getBucket (key) If (time > 0) {rBucket.set (value,time,TimeUnit.SECONDS);} else {rBucket.set (value);} return true;} catch (Exception e) {e.printStackTrace (); return false }} public String getString (String key) {if (key==null) return null; RBucket rBucket=redissonClient.getBucket (key); Object o = rBucket.get (); return o = = null? Null: o.toString ();} / public boolean setString (String key, Object value, long time) {/ / try {/ / if (time > 0) {/ / redisTemplate.opsForValue (). Set (key, value, time, TimeUnit.SECONDS); / /} else {/ / redisTemplate.opsForValue (). Set (key, value) / /} / / return true;//} catch (Exception e) {/ / e.printStackTrace (); / / return false;//} / /} / public String getString (String key) {/ / if (key==null) / / return null;// Object o = redisTemplate.opsForValue (). Get (key) / / return o = = null? Null: o.toString (); / /}} write: RedisUtil.setString ("key", "value", time); read: RedisUtil.getString ("key"); now that you have a deeper understanding of "how Springboot integrates redis to achieve simple data writing and reading", you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report