一.redis简介

  Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库

    Redis支持数据的持久化,可以将内存中的数据保存在磁盘中,重启的时候可以再次加载进行使用。

    Redis不仅仅支持简单的key-value类型的数据,同时还提供list,set,zset,hash等数据结构的存储。

    Redis支持数据的备份,即master-slave模式的数据备份。

  两种持久化机制:https://www.cnblogs.com/xingzc/p/5988080.html

 二.Spring配置redis

  配置jedis的jar包:pom.xml:

<dependency>
        <groupId>redis.clients</groupId>
        <artifactId>jedis</artifactId>
        <version>3.0.1</version>
</dependency>

  redis.properties(redis配置信息):

redis.hostname=127.0.0.1
redis.port=6379
redis.database=0
redis.pool.maxActive=600
redis.pool.maxIdle=300
redis.pool.maxWait=3000
redis.pool.testOnBorrow=true

   加载redis配置信息:

Spring配置redis及使用

  连接池对象操作类(JedisPoolWriper):

 1 package com.swpu.o2o.cache;
 2 
 3 import redis.clients.jedis.JedisPool;
 4 import redis.clients.jedis.JedisPoolConfig;
 5 
 6 /**
 7  * 强指定redis的JedisPool接口构造函数,这样才能在centos成功创建jedispool
 8  * 
 9  * @author xiangze
10  *
11  */
12 public class JedisPoolWriper {
13     //连接池对象
14     private JedisPool jedisPool;
15 
16     public JedisPoolWriper(final JedisPoolConfig poolConfig, final String host,
17             final int port) {
18         try {
19             //通过连接池配置信息,IP,端口构造连接池对象
20             jedisPool = new JedisPool(poolConfig, host, port);
21         } catch (Exception e) {
22             e.printStackTrace();
23         }
24     }
25     //获取redis连接池对象
26     public JedisPool getJedisPool() {
27         return jedisPool;
28     }
29     //注入redis连接池对象
30     public void setJedisPool(JedisPool jedisPool) {
31         this.jedisPool = jedisPool;
32     }
33 
34 }
View Code

相关文章:

  • 2021-06-22
  • 2022-02-19
  • 2022-12-23
  • 2022-12-23
  • 2021-08-18
  • 2022-12-23
  • 2022-02-21
  • 2021-08-21
猜你喜欢
  • 2021-11-21
  • 2021-10-28
  • 2021-06-22
  • 2022-12-23
相关资源
相似解决方案