Redis-05Redis数据结构--链表( linked-list)

本文涉及的产品
云数据库 Redis 版,社区版 2GB
推荐场景:
搭建游戏排行榜
简介: Redis-05Redis数据结构--链表( linked-list)

概述


链表结构是 Redis 中一个常用的结构,它可以存储多个字符串

它是有序的

能够存储2的32次方减一个节点(超过 40 亿个节点)

Redis 链表是双向的,因此即可以从左到右,也可以从右到左遍历它存储的节点

链表结构查找性能不佳,但 插入和删除速度很快

由于是双向链表,所以只能够从左到右,或者从右到左地访问和操作链表里面的数据节点。 但是使用链表结构就意味着读性能的丧失,所以要在大量数据中找到一个节点的操作性能是不佳的,因为链表只能从一个方向中去遍历所要节点,比如从查找节点 10000 开始查询,它需要按照节点1 、节点 2、节点 3……直至节点 10000,这样的顺序查找,然后把一个个节点和你给出的值比对,才能确定节点所在。如果这个链表很大,如有上百万个节点,可能需要遍历几十万次才能找到所需要的节点,显然查找性能是不佳的。


链表结构的优势在于插入和删除的便利 ,因为链表的数据节点是分配在不同的内存区域的,并不连续,只是根据上一个节点保存下一个节点的顺序来索引而己,无需移动元素。


因为是双向链表结构,所以 Redis 链表命令分为左操作和右操作两种命令,左操作就意味着是从左到右,右操作就意味着是从右到左。


Redis 关于链表的命令


官网 : https://redis.io/commands#list


20190109232922563.png

image.png

image.png


对于很多个节点同时操作的,需要考虑其花费的时间,链表数据结构对于查找而言并不适合于大数据。我们需要考虑插入和删除内容的大小,因为这将是十分消耗性能的命令,会导致 Redis 服务器的卡顿 。对于不允许卡顿的一些服务器,可以进行分批次操作,以避免出现卡顿。

127.0.0.1:6379> flushdb
OK
127.0.0.1:6379> LPUSH list node3 node2 node1
(integer) 3
127.0.0.1:6379> RPUSH list node4
(integer) 4
127.0.0.1:6379> LINDEX list 0
"node1"
127.0.0.1:6379> LLEN list
(integer) 4
127.0.0.1:6379> LPOP list
"node1"
127.0.0.1:6379> RPOP list
"node4"
127.0.0.1:6379> LINSERT list before node2 before_node
(integer) 3
127.0.0.1:6379> LINSERT list after node2 after_node
(integer) 4
127.0.0.1:6379> LPUSHX list head
(integer) 5
127.0.0.1:6379> RPUSHX list end
(integer) 6
127.0.0.1:6379> LRANGE list 0 10
1) "head"
2) "before_node"
3) "node2"
4) "after_node"
5) "node3"
6) "end"
127.0.0.1:6379> LPUSH list node node node 
(integer) 9
127.0.0.1:6379> LREM list 3 node 
(integer) 3
127.0.0.1:6379> LSET list 0 new_head_value
OK
127.0.0.1:6379> LRANGE list 0 10
1) "new_head_value"
2) "before_node"
3) "node2"
4) "after_node"
5) "node3"
6) "end"
127.0.0.1:6379> LTRIM list 0 2 
OK
127.0.0.1:6379> LRANGE list 0 10
1) "new_head_value"
2) "before_node"
3) "node2"
127.0.0.1:6379> 

使用 Spring 操作 Redis 链表命令

配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:p="http://www.springframework.org/schema/p"
  xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context.xsd">
    <context:property-placeholder location="classpath:redis/redis.properties" />
    <!--2,注意新版本2.3以后,JedisPoolConfig的property name,不是maxActive而是maxTotal,而且没有maxWait属性,建议看一下Jedis源码或百度。 -->
    <!-- redis连接池配置 -->
    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <!--最大空闲数 -->
        <property name="maxIdle" value="${redis.maxIdle}" />
        <!--连接池的最大数据库连接数 -->
        <property name="maxTotal" value="${redis.maxTotal}" />
        <!--最大建立连接等待时间 -->
        <property name="maxWaitMillis" value="${redis.maxWaitMillis}" />
        <!--逐出连接的最小空闲时间 默认1800000毫秒(30分钟) -->
        <property name="minEvictableIdleTimeMillis" value="${redis.minEvictableIdleTimeMillis}" />
        <!--每次逐出检查时 逐出的最大数目 如果为负数就是 : 1/abs(n), 默认3 -->
        <property name="numTestsPerEvictionRun" value="${redis.numTestsPerEvictionRun}" />
        <!--逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认-1 -->
        <property name="timeBetweenEvictionRunsMillis" value="${redis.timeBetweenEvictionRunsMillis}" />
      <property name="testOnBorrow" value="true"></property>
    <property name="testOnReturn" value="true"></property>
    <property name="testWhileIdle" value="true"></property>
    </bean>
  <!--redis连接工厂 -->
    <bean id="jedisConnectionFactory"
        class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
        destroy-method="destroy">
        <property name="poolConfig" ref="jedisPoolConfig"></property>
        <!--IP地址 -->
        <property name="hostName" value="${redis.host.ip}"></property>
        <!--端口号 -->
        <property name="port" value="${redis.port}"></property>
        <!--如果Redis设置有密码 -->
        <property name="password" value="${redis.password}" /> 
        <!--客户端超时时间单位是毫秒 -->
        <property name="timeout" value="${redis.timeout}"></property>
        <property name="usePool" value="true" />
        <!--<property name="database" value="0" /> -->
    </bean>
  <!-- 键值序列化器设置为String 类型 -->
  <bean id="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
  <!-- redis template definition -->
  <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"
    p:connection-factory-ref="jedisConnectionFactory"
    p:keySerializer-ref="stringRedisSerializer"
    p:defaultSerializer-ref="stringRedisSerializer"
    p:valueSerializer-ref="stringRedisSerializer">
  </bean>
</beans>


package com.artisan.redis.baseStructure.list;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.redis.connection.RedisListCommands;
import org.springframework.data.redis.core.RedisTemplate;
public class SpringRedisListDemo {
  private static String key = "list";
  public static void main(String[] args) {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:spring/spring-redis-list.xml");
    RedisTemplate redisTemplate = (RedisTemplate) ctx.getBean("redisTemplate");
    // 不管存不存在,先根据key清理掉链表,方便测试
    Boolean flag  = redisTemplate.delete(key);
    System.out.println((flag = true) ? "删除list成功" : "删除list失败");
    // 127.0.0.1:6379> LPUSH list node3 node2 node1
    // (integer) 3
    // 把 node3 插入链表 list
    System.out.println(redisTemplate.opsForList().leftPush(key, "node3"));
    // 相当于 lpush 把多个价值从左插入链表
    List<String> nodeList = new ArrayList<String>();
    for (int i = 2; i >= 1; i--) {
      nodeList.add("node" + i);
    }
    System.out.println(redisTemplate.opsForList().leftPushAll(key, nodeList));
    // 127.0.0.1:6379> RPUSH list node4
    // (integer) 4
    // 从右边插入一个节点
    System.out.println(redisTemplate.opsForList().rightPush(key, "node4"));
    // 127.0.0.1:6379> LINDEX list 0
    // "node1"
    // 获取下标为 0 的节点
    String node = (String) redisTemplate.opsForList().index(key, 0);
    System.out.println("第一个节点:" + node);
    // 127.0.0.1:6379> LLEN list
    // (integer) 4
    // 获取链表长度
    System.out.println(key + "中的总数为:" + redisTemplate.opsForList().size(key));
    // 127.0.0.1:6379> LPOP list
    // "node1"
    // 从左边弹出 一个节点
    String leftPopNode = (String) redisTemplate.opsForList().leftPop(key);
    System.out.println("leftPopNode:" + leftPopNode);
    // 127.0.0.1:6379> RPOP list
    // "node4"
    // 从右边弹出 一个节点
    String rightPopNode = (String) redisTemplate.opsForList().rightPop(key);
    System.out.println("rightPopNode:" + rightPopNode);
    // 注意,需要使用更为底层的命令才能操作 linsert 命令
    // 127.0.0.1:6379> LINSERT list before node2 before_node
    // (integer) 3
    // 使用 linsert 命令在node2 前插入一个节点
    try {
      Long long1 = redisTemplate.getConnectionFactory().getConnection()
          .lInsert(key.getBytes("utf-8"), RedisListCommands.Position.BEFORE, "node2".getBytes("utf-8"), "before_node".getBytes("utf-8"));
      System.out.println(long1);
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }
    // 127.0.0.1:6379> LINSERT list after node2 after_node
    // (integer) 4
    // 使用 linsert 命令在 node2 后插入一个节点
    try {
      Long long2 = redisTemplate.getConnectionFactory().getConnection()
          .lInsert(key.getBytes("utf-8"), RedisListCommands.Position.AFTER, "node2".getBytes("utf-8"), "after_node".getBytes("utf-8"));
      System.out.println(long2);
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }
    // 127.0.0.1:6379> LPUSHX list head
    // (integer) 5
    // 判断 list 是否存在,如果存在则从左边插入 head 节点
    System.out.println(redisTemplate.opsForList().leftPushIfPresent(key, "head"));
    // 127.0.0.1:6379> RPUSHX list end
    // (integer) 6
    // 判断 list 是否存在,如果存在则从右边插入 end 节点
    System.out.println(redisTemplate.opsForList().rightPushIfPresent(key, "end"));
    // 127.0.0.1:6379> LRANGE list 0 10
    // 1) "head"
    // 2) "before_node"
    // 3) "node2"
    // 4) "after_node"
    // 5) "node3"
    // 6) "end"
    List<String> list = redisTemplate.opsForList().range(key, 0, 10);
    for (String string : list) {
      System.out.println("节点:" + string);
    }
    // 127.0.0.1:6379> LPUSH list node node node
    // (integer) 9
    // 在链表左边插入三个值为 node 的节点
    nodeList.clear();
    for (int i = 0; i < 3; i++) {
      nodeList.add("node");
    }
    System.out.println(redisTemplate.opsForList().leftPushAll(key, nodeList));
    // 127.0.0.1:6379> LREM list 3 node
    // (integer) 3
    // 从左到右删除至多三个 node 节点
    System.out.println(redisTemplate.opsForList().remove(key, 3, "node"));
    // 127.0.0.1:6379> LSET list 0 new_head_value
    // OK
    // 给链表下标为 0 的节点设置新值
    redisTemplate.opsForList().set(key, 0, "new_head_value");
    // 127.0.0.1:6379> LRANGE list 0 10
    // 1) "new_head_value"
    // 2) "before_node"
    // 3) "node2"
    // 4) "after_node"
    // 5) "node3"
    // 6) "end"
    list = redisTemplate.opsForList().range(key, 0, 10);
    for (String string : list) {
      System.out.println("节点:" + string);
    }
    // 127.0.0.1:6379> LTRIM list 0 2
    // OK
    redisTemplate.opsForList().trim(key, 0, 2);
    System.out.println("---------------------");
    // 127.0.0.1:6379> LRANGE list 0 10
    // 1) "new_head_value"
    // 2) "before_node"
    // 3) "node2"
    list = redisTemplate.opsForList().range(key, 0, 10);
    for (String string : list) {
      System.out.println("节点:" + string);
    }
  }
}


输出结果:

INFO : org.springframework.context.support.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@73a8dfcc: startup date [Wed Sep 26 10:31:21 CST 2018]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [spring/spring-redis-list.xml]
删除list成功
1
3
4
第一个节点:node1
list中的总数为:4
leftPopNode:node1
rightPopNode:node4
3
4
5
6
节点:head
节点:before_node
节点:node2
节点:after_node
节点:node3
节点:end
9
3
节点:new_head_value
节点:before_node
节点:node2
节点:after_node
节点:node3
节点:end
---------------------
节点:new_head_value
节点:before_node
节点:node2


有些命令 Spring 所提供的 RedisTemplate 并不能支持,比如 linsert 命令。可以使用更为底层的方法去操作 ,如下

redisTemplate.getConnectionFactory().getConnection()
          .lInsert(key.getBytes("utf-8"), RedisListCommands.Position.AFTER, "node2".getBytes("utf-8"), "after_node".getBytes("utf-8"));


在多值操作的时候,往往会使用 list 进行封装 , 比如 leftPushAll 方法,对于很大的 list的操作需要注意性能 , 比如 remove 这样的操作,在大的链表中会消耗 Redis 系统很多的性能。


链表的阻塞命令


上面的这些操作链表的命令都是进程不安全的,因为 当我们操作这些命令的时候,其他 Redis 的客户端也可能操作同一个链表,这样就会造成并发数据安全和一致性的问题,尤其是当你操作一个数据量不小的链表结构时,常常会遇到这样的问题 。 Redis 提供了链表的阻塞命令,它们在运行的时候 , 会给链表加锁,以保证操作链表的命令安全性.



image.png

当使用这些命令时, Redis 就会对对应的链表加锁,加锁的结果就是其他的进程不能再读取或者写入该链表,只能等待命令结束 。 加锁的好处可以保证在多线程并发环境中数据的一致性,保证一些重要数据的一致性,比如账户的金额 、 商品的数量。不过在保证这些的同时也要付出其他线程等待、线程环境切换等代价,这将使得系统的并发能力下

127.0.0.1:6379> flushdb
OK
127.0.0.1:6379> LPUSH list node1 node2 node3 node4 node5
(integer) 5
127.0.0.1:6379> LRANGE list 0 4
1) "node5"
2) "node4"
3) "node3"
4) "node2"
5) "node1"
127.0.0.1:6379> BLPOP list 2
1) "list"
2) "node5"
127.0.0.1:6379> LRANGE list 0 4
1) "node4"
2) "node3"
3) "node2"
4) "node1"
127.0.0.1:6379> BRPOP list 3
1) "list"
2) "node1"
127.0.0.1:6379> LPUSH list2 data1 data2 data3
(integer) 3
127.0.0.1:6379> RPOPLPUSH list list2
"node2"
127.0.0.1:6379> BRPOPLPUSH list list2 3
"node3"
127.0.0.1:6379> LRANGE list 0 10
1) "node4"
127.0.0.1:6379> LRANGE list2 0 10
1) "node3"
2) "node2"
3) "data3"
4) "data2"
5) "data1"

在实际的项目中 , 虽然阻塞可以有效保证了数据的一致性,但是阻塞就意味着其他进程的等待, CPU 需要给其他线程挂起、恢复等操作,更多的时候我们希望的并不是阻塞的处理请求,所以这些命令在实际中使用得并不多.


使用Spring 操作Redis 链表阻塞命令


package com.artisan.redis.baseStructure.list;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.redis.core.RedisTemplate;
public class SpringRedisBlockListDemo {
  private static final String KEY1 = "list1";
  private static final String KEY2 = "list2";
  public static void main(String[] args) {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:spring/spring-redis-list.xml");
    RedisTemplate redisTemplate = ctx.getBean(RedisTemplate.class);
    // 清空操作
    redisTemplate.delete(KEY1);
    redisTemplate.delete(KEY2);
    // 127.0.0.1:6379> LPUSH list node1 node2 node3 node4 node5
    // (integer) 5
    List<String> list = new ArrayList<String>();
    for (int i = 1; i <= 5; i++) {
      list.add("node" + i);
    }
    redisTemplate.opsForList().leftPushAll(KEY1, list);
    scanList(redisTemplate, KEY1, 0, 4);
    System.out.println("---------------------------");
    // 127.0.0.1:6379> BLPOP list 2
    // 1) "list"
    // 2) "node5"
    // Spring 使用参数超时时间作为阻塞命令区分,等价于 blpop 命令,并且可以设置时间参数
    String lefpPodNode = (String) redisTemplate.opsForList().leftPop(KEY1, 2, TimeUnit.SECONDS);
    System.out.println("leftPopNode:" + lefpPodNode);
    System.out.println("---------------------------");
    // 127.0.0.1:6379> LRANGE list 0 4
    // 1) "node4"
    // 2) "node3"
    // 3) "node2"
    // 4) "node1"
    scanList(redisTemplate, KEY1, 0, 4);
    System.out.println("---------------------------");
    // 127.0.0.1:6379> BRPOP list 3
    // 1) "list"
    // 2) "node1"
    // Spring 使用参数超时时间作为阻塞命令区分,等价于 brpop 命令,并且可以设置时间参数
    System.out.println("rightPopNode:" + redisTemplate.opsForList().rightPop(KEY1, 3, TimeUnit.SECONDS));
    System.out.println("---------------------------");
    // 127.0.0.1:6379> LRANGE list 0 4
    // 1) "node4"
    // 2) "node3"
    // 3) "node2"
    scanList(redisTemplate, KEY1, 0, 4);
    System.out.println("---------------------------");
    // 127.0.0.1:6379> LPUSH list2 data1 data2 data3
    // (integer) 3
    List<String> list2 = new ArrayList<String>();
    for (int i = 3; i >= 1; i--) {
      list2.add("data" + i);
    }
    System.out.println(redisTemplate.opsForList().leftPushAll(KEY2, list2));
    System.out.println("---------------------------");
    // 127.0.0.1:6379> RPOPLPUSH list list2
    // "node2"
    // 相当于 rpoplpush 命令,弹出 list1最右边的节点,插入到 list2 最左边
    String value2 = (String) redisTemplate.opsForList().rightPopAndLeftPush(KEY1, KEY2);
    System.out.println("rightPopAndLeftPush:" + value2);
    System.out.println("-------------------");
    // 127.0.0.1:6379> BRPOPLPUSH list list2 3
    // "node3"
    // 相当于 brpoplpush 命令,注意在 Spring 中使用超时参数区分
    String value3 = (String) redisTemplate.opsForList().rightPopAndLeftPush(KEY1, KEY2, 3, TimeUnit.SECONDS);
    System.out.println("rightPopAndLeftPush:" + value3);
    System.out.println("-------------------");
    // 127.0.0.1:6379> LRANGE list 0 10
    // 1) "node4"
    scanList(redisTemplate, KEY1, 0, 10);
    System.out.println("-------------------");
    // 127.0.0.1:6379> LRANGE list2 0 10
    // 1) "node3"
    // 2) "node2"
    // 3) "data3"
    // 4) "data2"
    // 5) "data1"
    scanList(redisTemplate, KEY2, 0, 10);
  }
  private static void scanList(RedisTemplate redisTemplate, String key, int begin, int end) {
    List<String> data = redisTemplate.opsForList().range(key, begin, end);
    for (String string : data) {
      System.out.println("节点:" + string);
    }
  }
}


输出

INFO : org.springframework.context.support.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@73a8dfcc: startup date [Wed Sep 26 12:53:56 CST 2018]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [spring/spring-redis-list.xml]
节点:node5
节点:node4
节点:node3
节点:node2
节点:node1
---------------------------
leftPopNode:node5
---------------------------
节点:node4
节点:node3
节点:node2
节点:node1
---------------------------
rightPopNode:node1
---------------------------
节点:node4
节点:node3
节点:node2
---------------------------
3
---------------------------
rightPopAndLeftPush:node2
-------------------
rightPopAndLeftPush:node3
-------------------
节点:node4
-------------------
节点:node3
节点:node2
节点:data1
节点:data2
节点:data3



上面展示了 Redis 关于链表的阻塞命令,在 Spring 中它和非阻塞命令的方法是一致的,只是它会通过超时参数进行区分,而且我们还可以通过方法设置时间的单位。 注意,它是阻塞的命令,在多线程的环境中,它能在一定程度上保证数据 的一致而性能却不佳。

注意


使用 Spring 提供的 RedisTemplate 去展示多个命令可以学习到如何使用 RedisTemplate 操作 Redis 。 实际工作中并不是那么用的,因为每一 个操作会尝试从连接池里获取 一 个新的 Redis 连接,多个命令应该使用SessionCallback 接口进行操作 。


代码


代码托管到了 https://github.com/yangshangwei/redis_learn

相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore &nbsp; &nbsp; ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库&nbsp;ECS 实例和一台目标数据库&nbsp;RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&amp;RDS资源,30分钟完成数据库上云实战!/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
相关文章
|
2天前
|
存储
数据结构链表详解(不仅顺序表可以,我链表也可以)
数据结构链表详解(不仅顺序表可以,我链表也可以)
11 0
|
3天前
|
存储 监控 NoSQL
Redis处理大量数据主要依赖于其内存存储结构、高效的数据结构和算法,以及一系列的优化策略
【5月更文挑战第15天】Redis处理大量数据依赖内存存储、高效数据结构和优化策略。选择合适的数据结构、利用批量操作减少网络开销、控制批量大小、使用Redis Cluster进行分布式存储、优化内存使用及监控调优是关键。通过这些方法,Redis能有效处理大量数据并保持高性能。
22 0
|
3天前
|
存储 NoSQL 算法
Redis源码、面试指南(2)内存编码数据结构(下)
Redis源码、面试指南(2)内存编码数据结构
20 4
|
3天前
|
存储 NoSQL API
Redis源码、面试指南(2)内存编码数据结构(上)
Redis源码、面试指南(2)内存编码数据结构
14 0
|
3天前
|
存储 缓存 NoSQL
Redis源码(1)基本数据结构(下)
Redis源码(1)基本数据结构
11 1
|
3天前
|
NoSQL 安全 算法
Redis源码(1)基本数据结构(中)
Redis源码(1)基本数据结构
18 5
|
3天前
|
负载均衡 监控 NoSQL
Redis的几种主要集群方案
【5月更文挑战第15天】Redis集群方案包括主从复制(基础,读写分离,手动故障恢复)、哨兵模式(自动高可用,自动故障转移)和Redis Cluster(官方分布式解决方案,自动分片、容错和扩展)。此外,还有Codis、Redisson和Twemproxy等工具用于代理分片和负载均衡。选择方案需考虑应用场景、数据量和并发需求,权衡可用性、性能和扩展性。
33 2
|
3天前
|
存储 监控 负载均衡
保证Redis的高可用性是一个涉及多个层面的任务,主要包括数据持久化、复制与故障转移、集群化部署等方面
【5月更文挑战第15天】保证Redis高可用性涉及数据持久化、复制与故障转移、集群化及优化策略。RDB和AOF是数据持久化方法,哨兵模式确保故障自动恢复。Redis Cluster实现分布式部署,提高负载均衡和容错性。其他措施包括身份认证、多线程、数据压缩和监控报警,以增强安全性和稳定性。通过综合配置与监控,可确保Redis服务的高效、可靠运行。
25 2
|
3天前
|
存储 NoSQL Redis
Redis源码、面试指南(5)多机数据库、复制、哨兵、集群(下)
Redis源码、面试指南(5)多机数据库、复制、哨兵、集群
19 1
http://www.vxiaotou.com