http://try.redis.io/ 可以去官网练习redis命令
https://redis.io/download 在官网上下载
Download, extract and compile Redis with:
$ wget http://download.redis.io/releases/redis-5.0.3.tar.gz
$ tar xzf redis-5.0.3.tar.gz
$ cd redis-5.0.3
$ make
The binaries that are now compiled are available in the src
directory. Run Redis with:
$ src/redis-server
You can interact with Redis using the built-in client:
$ src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> <version>2.1.3.RELEASE</version> </dependency>
spring.redis.database=2 spring.redis.host=10.138.60.119 spring.redis.port=6379 spring.redis.timeout=3000 #连接池中最大空闲链接,默认值是8 spring.redis.jedis.pool.max-idle=20 #连接池中最小空闲链接,默认是0 spring.redis.jedis.pool.min-idle=10 ## 如果赋值为-1,则表示不限制;pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽)。 spring.redis.jedis.pool.max-active=200 #等待连接的最长时间 spring.redis.jedis.pool.max-wait=1000
@RestController @RequestMapping("/api/v1/redis") public class RedisController { @Autowired private RedisClient redis; @RequestMapping("/add") public String add() { redis.set("name","kevin"); return "success"; } @RequestMapping("/get") public String get() { return redis.get("name"); } @RequestMapping("/save_user") public boolean saveUser() { User user = new User("kevin","123",30,new Date()); String usr = JsonUtils.obj2String(user); return redis.set("project:user:1001",usr); } @RequestMapping("/find_user") public String getUser() { return redis.get("project:user:1"); } }
public class RedisClient { @Autowired private StringRedisTemplate redisTpl; //jdbcTemplate public boolean set(String key ,String value){ try{ redisTpl.opsForValue().set(key, value); return true; }catch(Exception e){ e.printStackTrace(); return false; } } public String get(String key){ return redisTpl.opsForValue().get(key); } }
public class JsonUtils { private static ObjectMapper objectMapper = new ObjectMapper(); //对象转字符串 public static <T> String obj2String(T obj){ if (obj == null){ return null; } try { return obj instanceof String ? (String) obj : objectMapper.writeValueAsString(obj); } catch (Exception e) { e.printStackTrace(); return null; } } //字符串转对象 public static <T> T string2Obj(String str,Class<T> clazz){ if (StringUtils.isEmpty(str) || clazz == null){ return null; } try { return clazz.equals(String.class)? (T) str :objectMapper.readValue(str,clazz); } catch (IOException e) { e.printStackTrace(); return null; } } }
相关推荐
Java开发案例-springboot-02-整合Redis-源代码+文档.rar Java开发案例-springboot-02-整合Redis-源代码+文档.rar Java开发案例-springboot-02-整合Redis-源代码+文档.rar Java开发案例-springboot-02-整合Redis-源...
springboot-mybatis-mysql-redis demo.zip springboot-mybatis-mysql-redis demo.zip
基于`SpringBoot2.X + Lettuce`实现Redis集成和多库实时切换是一个非常实用的项目。以下是对该项目的一些重点说明: 1. **项目概述** 该项目的主要目标是在`SpringBoot`应用中集成`Lettuce`作为Redis客户端,实现对...
Springboot-redis springboot 之使用redis数据库 Springboot-editor.md springboot 与editor.md 整合 Springboot-filter-listener-interceptor 过滤器、拦截器、监听器 Springboot-mongodb 与MongoDB 整合 ...
最近在学习SpringBoot2.x整合Redis,在这里和大家分享一下,希望对大家有帮助。Redis是开源免费高性能的key-value数据库。有以下的优势(源于Redis官网):1.性能极高–Redis能读的速度是110000次/s,写的速度是81000...
Java开发案例-springboot-29-整合ShedLock实现分布式定时任务(redis版)-源代码+文档.rar Java开发案例-springboot-29-整合ShedLock实现分布式定时任务(redis版)-源代码+文档.rar Java开发案例-springboot-29-整合...
2.springboot-demo2 3.springboot-static 4.springboot-redis 5springboot-quartz-cluster 6.springboot-shiro 7.springboot-admin 8.springboot-html 9.springboot-html 10.springboot-cros 11.springboot-elk 12....
基于springboot的java框架,采用mybatis作为数据ORM层,spingmvc作为业务层和展示层,多种配置方式
Redission分布式锁-本地单机Redis实战-springboot-redis-lock
springboot整合redis做mybatis的二级缓存,含有自定义key,自定义过期时间,自定义序列化方式
springboot+redis+mybati-springboot-redis-mybatis-swagger
springboot整合redis.算是比较全面的一种整合方式了. springboot整合redis.算是比较全面的一种整合方式了.
SpringBoot项目—外卖系统 系统概述 项目分析 SpringBoot-2.4.5 移动端前台:手机号登录(阿里云服务_短信验证码)、菜品浏览、下单、地址管理、菜品规格、购物车、历史订单 客户端用户:登录移动端应用,可以浏览菜...
整合Redis,自定义序列化方式
Springboot-redis springboot 之使用redis数据库 Springboot-editor.md springboot 与editor.md 整合 Springboot-filter-listener-interceptor 过滤器、拦截器、监听器 Springboot-mongodb 与MongoDB 整合 ...
SpringBoot2.X整合Redis实现Redis支持lua脚本代码实例。
shiro+springboot2.x+redis注解方式完整项目,包括自定义realm,整合redis缓存管理器,自定义sessionId,自定义session等等,sql文件就在resource文件夹下
Springboot整合redis使用技巧.pdfSpringboot整合redis使用技巧.pdfSpringboot整合redis使用技巧.pdfSpringboot整合redis使用技巧.pdfSpringboot整合redis使用技巧.pdfSpringboot整合redis使用技巧.pdfSpringboot整合...
基于springboot实现快速构建大部分项目 1、springboot+shardingjdbc 2、redis封装 3、mongodb封装 4、elastic-job例子 5、springboot自定义404、500及常见错误 6、微信第三方平台搭建 7、springboot-autoconfigure-...