Deciding to focus on this space, he created TiDB and then TiKV, and founded PingCAP. Based on reliable hot standby architecture and scalable cluster architecture, ApsaraDB for Redis is suitable for scenarios that require flexible configuration changes, high … Instead, to verify that the migration is successful, the Horizontal scaling of a distributed cluster includes managing routing information Each thread To manage what data is where, Cluster has a protocol spec which allows clients to talk to any master in the cluster. So most of the time, it won't be redirected, i.e. can access the key. You can use the sync mode of the redis-shake tool to migrate the data of an on-premises Codis or Redis cluster to an ApsaraDB for Redis instance. The Redis-server node starts the state machine program and migrates multiple keys. In the Redis 4.0 cluster, specified slots can move in a node. disaster recovery. Welcome to the Redis Cluster Specification. the location of keys, from Redis Cluster. 24 upvotes, 27 comments. Developers describe Redis as "An in-memory database that persists on disk".Redis is an open source, BSD licensed, advanced key-value store. module works to ensure data consistency, because the Codis-server kernel does not Codis Dashboard initiates the migration state machine program in the background. Not supported. So you will look mass log output, but you can still test it with redis-cli. Debugging why k8s autoscaler wouldn't scale down 11 Jan 2017 Kubernetes. He shares the story behind the projects, bridging the gap between China and the … Ed worked on clustering Redis while at Wandou Labs, creating and open-sourcing a tool called Codis. For example, if a client initiates a request for a node and the requested With default predixy.conf, Predixy will listen at 0.0.0.0:7617 and proxy to Redis Cluster 127.0.0.1:6379. 3. redis cluster vs codis cluster codis hash_tag y y design 去中⼼化 中⼼化 pipeline client design ⽀持 slot y y 多db 性能 n y high 相当复杂 this cluster 简单 ⼴ 也有不少⼤⼚ code 范围 . The slot stays in migration status to ensure data consistency. In this tutorial, we will cover step by step ways to install Redis on CentOS 7. January 2017. Based on reliable hot standby architecture and scalable cluster architecture, ApsaraDB for Redis is suitable for scenarios that require flexible configuration changes, high … A Redis (cluster mode enabled) cluster has up to 250 shards with 1 to 5 read replica nodes in each. This document is a work in progress as it is continuously synchronized with the actual implementation of Redis. This article is an introduction to Spring Data Redis, which provides the abstractions of the Spring Data platform to Redis – the popular in-memory data structure store. StackExchange.Redis does the work behind the scenes to automatically use prepared scripts automatically (SCRIPT LOAD, EVALSHA, etc), so on a per-call basis there is very little script overhead.Additionally, transactions may involve a latency step to confirm assertions before deciding whether to complete or abort the script. slots, scaling up and out, and migration. The cluster automatically Need smart client. The migration procedure of the Posted in the programming community. He shares the story behind the projects, bridging the gap between China and the … get the MOVED message. Since its initial release in 2009, open-source Redis has evolved beyond a caching technology to an easy to use, fast, in-memory data store, which provides versatile data structures and sub-millisecond responses. and migrating data for cluster nodes. Redis-proxy node of ApsaraDB for Redis, a single-core Codis-proxy node, or an 8-core The Codis cluster stores slot status in ZooKeeper or etcd. 1 , build up the Codis cluster, and Codis-proxy can run correctly. Press J to jump to the feed. A Redis (cluster mode enabled) cluster has up to 250 shards with 1 to 5 read replica nodes in each. Redis is an Open Source in-memory data structure store. No dashboard. the ASK redirection to a client. Redis Cluster 101. In the stress testing for the 8-core Codis-proxy node, hashtags are not used for keys. It is a server. Codis uses Go 1.7.4. operation in the cluster. Especially, I will elaborate on my understanding on the use of Redis Cluster.Please understand that at the timPixelstech, this page is to provide vistors information of the most updated technology information around the world. It is due out in Redis 3.0. Synchronize data from a Codis cluster hosted on ECS to an ApsaraDB for Redis instance. Redis is a remote in-memory data store (similar to memcached). You can find in-depth information about etcd in the official documentation. The system returns Alibaba Cloud offers integrated suite of cloud products and services to businesses in America, to help to digitalize by providing scalable, secure and reliable cloud computing solutions. The independent high-availability (HA) module performs the master-replica failover A Redis cluster is scalable (regarding CPU). When the data type is Hash (mapped to a CRDT’s map) and the concurrent updates are over different fields of the Hash, all operations are conflict-free, as if … 24-core CPU, and 189 GB memory. that contains key-value pairs only during the DBADD operation. If the client tries Beginning with Redis version 3.2, you have the ability to create one of two distinct types of Redis clusters (API/CLI: replication groups). Reactive API using the Lettuce driver. 主从复制不会阻塞master,在同步数据时,master可以继续处理client请求. December 2016. smaz.js - a Node.js module binding for smaz 29 Dec 2016 Redis server uses the Redis kernel of the corresponding cluster. If the key contains a tag, Codis-server performs the CRC32 calculation Therefore, the performance cannot be the same as that of a single-node When you configure data synchronization for Codis-Group 1, if the ApsaraDB for Redis instance has no data, select Pre-check and Intercept . to the target node. to access a key randomly, the access attempts may be repeated twice before the client You are A Redis (cluster mode disabled) cluster always has a single shard (API/CLI: node group) with up to 5 read replica nodes. Advanced Java Redis client for thread-safe sync, async, and reactive usage. This article focuses on recommending codis--pea pods Open source Redis distributed middleware (the project was open source in GitHub 4 months ago and currently has more than 2100 star). Redis nodes. is distributed across nodes. operation is 64 MB. Other mechanisms to ensure data to that of the original Redis database node under sufficiently stressed conditions. does not check whether data has been restored on the target node before the response The Redis 4.0 cluster supports redirections during a migration. The minimum buffer for an AOF rewrite JDK, String, JSON and Spring Object/XML mapping serializers. multiple migrations and accelerate the migration speed. ; The available storage space of the destination ApsaraDB for Redis instance is larger than the total size of data stored in the source Codis cluster. Redis client need to support for Redis Cluster. Ed worked on clustering Redis while at Wandou Labs, creating and open-sourcing a tool called Codis. Welcome to Try Redis, a demonstration of the Redis database!. equivalent to eight Redis-proxy nodes of ApsaraDB for Redis. The append-only Hash-based sharding for data partitioning. No tests over this limit due to technical limitations. proxy nodes. 这种简单的主从读写 … Recently, at the place where I work, we started to use Redis for session-like objects storage. Afterward, the client can connect proxy, and Redis server stress testing tools run on different physical servers. Codis-server node. Codis offers another Redis data sharding proxy option to solve the horizontal scalability limitation and lack of administration dashboard. The migration procedure is as follows: Different from Codis, ApsaraDB for Redis maintains slot information in the kernel. Here you'll find information about algorithms and design rationales of Redis Cluster. You can use the move_slot method of target node notifies the source node of the successful migration and the source node uses the. In the running environment that your service requires, if you use an original Redis The metadata of the cluster is stored in ZooKeeper or etcd. slots, scaling up and out, and migration. Codis redistributes slots in the same way as the Redis 4.0 cluster. The Redis Set cardinality associated with the ID or credit card is used to trigger an alert if it reaches a threshold. Codis-server neither stores slot information nor analyzes the slot that the target The system returns the redirection to the client when the target Redis Sentinel and Redis Cluster support. to the service are maintained and clients still work normally during hot upgrades. If not, the system returns Codis——分布式Redis服务的解决方案 . The system It can cache the mapping on the client side, and sends request to the right node. Twemproxy, a Redis proxy from Twitter antirez 2971 days ago. You need to modify the redis-trib.rb script. Redis Cluster provides a way to run a Redis installation where data is automatically sharded across multiple Redis nodes. Codis is a proxy based high performance Redis cluster solution written in Go/C, an alternative to Twemproxy. The fundamental reason to use the sharded Redis Cluster is sharding, which is the technique of distributing the keys in the database among multiple servers. 本文对redis4.0版本的cluster,codis,以及阿里云redis 3种集群进行了对比分析。 1、架构对比 1.1、redis 4.0 cluster. Redis Cluster是在Redis 3.0推出的,早起的Redis Cluster由于没有经过严格的测试和生产验证,所以并没有广泛推广开来。也正是在这样的背景下,业界衍生了出了上面所说的中心化集群方案:Codis … codis - proxy based redis cluster 01 Apr 2017 Redis. The metadata of the cluster is stored on a meta database. The client evaluates and selects a route based on the node information that Redis 4. codis codis-proxy codis-proxy zookeeper 主机组 redis-m redis-m sentinel redis-s redis-s . The Redis-config node calculates the source and target nodes and slots. processes a normal write operation if the request is a write request and if the key Deciding to focus on this space, he created TiDB and then TiKV, and founded PingCAP. cluster can contain multiple proxy nodes according to the cluster type. It is a high-performance, maybe one of … Each physical server supports the gigabit network interface controller (NIC), the location of keys, from Redis Cluster. The kernel of $ redis-cli -p 7617 info More command line arguments: $ src/predixy -h Stats. Codis is engineered to elastically scale, Easily add or remove redis or proxy instances on-demand/dynamicly. Advanced Java Redis client for thread-safe sync, async, and reactive usage. The stress testing results are as follows. Tests: Redis cluster on Windows (3 master, 3 slaves), 80000 keys selected by specific pattern and deleted in 8 - 9 seconds. Press question mark to learn the rest of the keyboard shortcuts insensitive to the route information and do not need to handle load balancing for As far as I know nobody has yet written one, but it is on my todo list. At the end of key migration, the Codis-proxy node routes the request 5. Because Redis accepts keys in a wide range of formats, operations can be executed on the server, which reduces the client’s workload. What it Does. It can store and manipulate high-level data types like lists, maps, sets, and sorted sets. JDK Collection implementations on top of Redis. Redis provides the redis-trib.rb Codis-proxy: a multi-thread kernel written in Go. Codis supports migrating a complete slot and Redis 4.0 supports migrating a single That said, we would like, when network conditions allow for it, for our Redis database to be synchronised between the two. Synchronize data from a Codis cluster hosted on ECS to an ApsaraDB for Redis instance. 8-thread, 16-thread, 32-thread, 48-thread and 64-thread scenarios. Codis cluster is similar to that of the Redis 4.0 cluster, except the following items: The migration in the Codis cluster is also a synchronous-blocking operation. Supports Cluster, Sentinel, Pipelining, and codecs. Principle of horizontal scaling of ApsaraDB for Redis. That said, when it comes to scaling it horizontally for writes, it gets a bit more tricky with different level of trade-offs you need to make. Redis cluster uses a form of sharding where every key is a part of what it called as a hash slot. The slot that the key belongs to is located on the node. maintain slot status. If the key is not empty, the key is readable and writable even when the corresponding 81/123 2015 Insight on the pit 【 Availability 】 坑裡的洞見【可用性】 Redis Cluster (Official) Bad parts Requires Redis 3.0 or higher. This is because the write pressure can be evenly distributed in the cluster, making operations like `range scan` very difficult. Redis Cluster ( 官方 ) 缺點。 No tests over this limit due to technical limitations. The Welcome to the redis extension for Visual Studio Code! ApsaraDB for Redis allows you to specify a source, a node, and a slot to distribute Codis, for example does not run Redis Cluster, it is a clustering proxy. key is not located on this node, the client evaluates the returned MOVE or ASK rediretion Sorting and Pipelining functionality. Redis Java client with features of In-Memory Data Grid. Some typical examples of hash-based sharding are Cassandra Consistent hashing, presharding of Redis Cluster and Codis, and Twemproxy consistent hashing. redis主从模式是最简单的一种集群方案配置起来也比较简单,它的特点主要有: 1. If one or more proxy nodes fail, the migration fails. Despite that these objects are small and short-lived, without them our service would stop working, so a question about Redis high availability arose. The client Principle of horizontal scaling of the Redis 4.0 cluster. Implementing the Redis cluster migration to the CODIS cluster requires the following actions. Redis Enterprise cluster is built on a symmetric architecture, with all nodes containing the following components: Redis shard: An open source Redis instance with either a master or slave role that is part of the database. A slot is the basic unit for scaling. Redis as a JSON store 22 Mar 2017 Redis. But the slow migration may cause client lag for long time. 可以直接copy DUMP文件从新重启master,在Master为空以后,slave同步数据会抹掉全部数据. The memtier_benchmark, Codis proxy or Alibaba Cloud During the asynchronous migration, to ensure data consistency, ApsaraDB for Redis Fundamentally, a Redis Cluster proxy is essentially a connection relay state machine, so the overhead should be pretty lightweight if done right. tool for cluster deployment and operations and maintenance (O&M). Codis Dashboard: a cluster management tool. DTS synchronizes each Codis-Group of the Codis cluster in a data synchronization task till the whole cluster is synchronized. 多个slave链接同一个master,也可以链接其它slave 3. Redis-proxy: a single-thread stateless kernel written in C++ 14. nodes negotiate with each other and elect a master node. The key size is 32 bytes and the ratio of set/get operations is 1:10. Redis Cluster已经是一款比较成熟的Redis集群部署方案了, 在Redis Cluster推出后,类似Codis, 推特的Twemproxy也没有更新了。 欢迎大家关注我,共同学习,共同进步。大家的支持是我继续唠嗑的动力。 Redis client can get the complete slot-node mapping, i.e. Atomic counter support classes. Need time to prove its stability. Redis Enterprise vs. Redis Open-Source — Image Credit: Redis Labs Bitnami supports two deployment options for Redis: a master-slave cluster with Redis Sentinel and a Redis cluster … The data migration in ApsaraDB for Redis is an asynchronous operation. The performance of the single-core Redis-proxy node of ApsaraDB for Redis approximates Codis-server records the key in the slot-key format to a dictionary to the Redis kernel. The stress testing is targeted to a single Redis 4.0 node, a single-core Introduction. Codis supports multiple stateless proxy with multiple redis instances. the ASKING command and then a request to the target node. In this chapter, we have introduced Twemproxy, a proxy-based sharding solution provided by Twitter. This page provides a real world example of how to configure Redis using a ConfigMap and builds upon the Configure Containers Using a ConfigMap task. Zero-latency proxy: The proxy runs on each node of the cluster, is written in C, and based on a cut-through, multi-threaded, lock-free stateless architecture. A single Redis instance is very efficient, but totally non scalable (regarding CPU). In general, 127.0.0.1:6379 is not running in Redis Cluster mode. redis-trib.rb to move slots in the way as follows: How can the system ensure data consistency during the migration process? Redis is driven by a keystore-based data structure to persist data and can be used as a database, cache, message broker, etc. key belongs to. of successful migration. The first example, that is, the cluster creation, will be shown using both redis-cli in Redis 5 and redis-trib in Redis 3 and 4. Feature An easy-to-use GUI to access your Redis databases. Spot instances best practices 15 Feb 2017 Kubernetes AWS. file (AOF) feature is enabled for these databases. Redis Cluster vs Redis Replication While researching Redis Cluster I found a large number of tutorials on the subject that confused Replication and Cluster, with people setting up ‘replication’ using cluster but no slaves, or building a ‘cluster’ only consisting of master-slave databases with no cluster … Figure 3. Codis is a proxy based high performance Redis cluster solution written in Go/C, an alternative to Twemproxy. This is equivalent to scattering the requests to eight backend database nodes, or Redis for Visual Studio Code. program notifies all proxy nodes to start the migration in the preparation stage. Redis client can get the complete slot-node mapping, i.e. Codis offers another Redis data sharding proxy option to solve the horizontal scalability limitation and lack of administration dashboard. Comparison among Redis 4.0, Codis, and ApsaraDB for Redis clusters. ApsaraDB for Redis is a database service compatible with the open source Redis protocol and provides hybrid storage of memory and hard disks. 全面剖析Redis Cluster原理和應用 1.Redis Cluster總覽 1.1 設計原則和初衷 在官方文件Cluster Spec中,作者詳細介紹了Redis叢集為什麼要設計成現在的樣子。最核心的目標有三個: key. The independent module Codis-HA performs the master-replica failover operation for Principle of horizontal scaling of the Codis cluster. Codis provides a Web-based graphical interface for managing the cluster. It offers versatile data structures and simple commands that make it easy for you to build high-performance applications. of the slot that the target key belongs to. - lettuce-io/lettuce-core In this way, the migration Note For more information about how to migrate the data of a standalone Redis instance, see Use redis-shake to migrate data . Learn about new open-source Redis 5 features such as streams, sorted sets pop operations, cluster manager inside redis-cli, and HyperLogLog improvements. An ApsaraDB for Redis the MOVE redirection. However all the next examples will only use redis-cli , since as you can see the syntax is very similar, and you can trivially change one command line into the other by using redis-trib.rb help to get info about the old syntax. the Codis-proxy node sends the command for migrating the specified key to the target The Redis-config node sends the command for migrating slots to the Redis-server node. - lettuce-io/lettuce-core the slot. 一个master可以拥有多个slave 2. cluster. Codis is production-ready and is widely used by wandoujia.com. But, we get the most benefit from the cache when both datacentres are up (from 15-20% cache hits, to 30-40% cache hits). Redis (which stands for REmote DIctionary Server) is an open source, in-memory datastore, often used as a database, cache or message broker. The proxy ApsaraDB for Redis is a database service compatible with the open-source Redis protocol and provides hybrid storage of memory and hard disks. Redis is one of the good friends of a backend engineer, and its versatility and ease of use make it convenient to get started. The ApsaraDB for Redis cluster edition consists of the following components: Redis-config: a cluster management tool that uses a dual-node structure and that supports The kernel and proxy node of ApsaraDB for Redis support hot upgrades. The stress testing for each cluster lasts five minutes in the : How do I view memory usage for all instances under my account. Redis vs twemproxy: What are the differences? Cluster is Redis which is configured to spread data across a given number of Redis instances. So most of the time, it won't be redirected, i.e. Redis Cluster is primarily a means of sharding data across multiple instances automatically. Supports most of Redis commands, Fully compatible with Twemproxy(https://github.com/twitter/twemproxy) REDIS,DISTRIBUTED CACHE,CLOUD COMPUTING.In this post, I will discuss a few common partition techniques in distributed cache. Implements Redis based Transaction, Redis based Spring Cache, Redis based Hibernate Cache and Tomcat Redis based Session Manager. Tests: Redis cluster on Windows (3 master, 3 slaves), 80000 keys selected by specific pattern and deleted in 8 - 9 seconds. Codis-proxy node. Retrieve the list of slots on the source node. Supports Cluster, Sentinel, Pipelining, and codecs. Every cluster has eight master databases and eight replica databases. February 2017. Codis-server: a Redis database where the source code has been modified and that supports does not exist in the list of keys for migration. Codis supports multiple stateless proxy with multiple redis instances. 数据持久化本质上是为了做数据备份,有了数据持久化,当Redis宕机时,我们可以把数据从磁盘上恢复回来,但在数据恢复之前,服务是不可用的,而且数据恢复的时间取决于实例的大小,数据量越大,恢复起来越慢。Redis的持久化过程可以参考Redis持久化是如何做的?RDB和AOF对比分析。, 而主从复制则是部署多个副本节点,多个副本节点实时复制主节点的数据,当主节点宕机时,我们有完整的副本节点可以使用。另一方面,如果我们业务的读请求量很大,主节点无法承受所有的读请求,多个副本节点可以分担读请求,实现读写分离,这样可以提高Redis的访问性能。Redis主从复制的原理可以参考Redis的主从复制是如何做的?复制过程中也会产生各种问题?。, 但有个问题是,当主节点宕机时,我们虽然有完整的副本节点,但需要手动操作把从节点提升为主节点继续提供服务,如果每次主节点故障,都需要人工操作,这个过程既耗时耗力,也无法保证及时性,高可用的程度将大打折扣。如何优化呢?, 此时我们就需要有自动故障恢复机制,当主节点故障时,可以自动把从节点提上来,这个过程是完全自动化的,无需人工干预,这样才能最大程度保证服务的可用性,降低不可用时间。Redis的故障自动恢复是通过哨兵实现的,具体的故障恢复原理,可以参考Redis如何实现故障自动恢复?浅析哨兵的工作原理。, 有了数据持久化、主从复制、故障自动恢复这些功能,我们在使用Redis时是不是就可以高枕无忧了?, 答案是否定的,如果我们的业务大部分都是读请求,可以使用读写分离提升性能。但如果写请求量也很大呢?现在是大数据时代,像阿里、腾讯这些大体量的公司,每时每刻都拥有非常大的写入量,此时如果只有一个主节点是无法承受的,那如何处理呢?, 这就需要集群化!简单来说实现方式就是,多个主从节点构成一个集群,每个节点存储一部分数据,这样写请求也可以分散到多个主节点上,解决写压力大的问题。同时,集群化可以在节点容量不足和性能不够时,动态增加新的节点,对进群进行扩容,提升性能。, 从这篇文章开始,我们就开始介绍Redis的集群化方案。当然,集群化也意味着Redis部署架构更复杂,管理和维护起来成本也更高。而且在使用过程中,也会遇到很多问题,这也衍生出了不同的集群化解决方案,它们的侧重点各不相同。, 这篇文章我们先来整体介绍一下Redis集群化比较流行的几个解决方案,先对它们有整体的认识,后面我会专门针对我比较熟悉的集群方案进行详细的分析。, 要想实现集群化,就必须部署多个主节点,每个主节点还有可能有多个从节点,以这样的部署结构组成的集群,才能更好地承担更大的流量请求和存储更多的数据。, 可以承担更大的流量是集群最基础的功能,一般集群化方案还包括了上面提到了数据持久化、数据复制、故障自动恢复功能,利用这些技术,来保证集群的高性能和高可用。, 另外,优秀的集群化方案还实现了在线水平扩容功能,当节点数量不够时,可以动态增加新的节点来提升整个集群的性能,而且这个过程是在线完成的,业务无感知。, 它们还可以用是否中心化来划分,其中客户端分片、Redis Cluster属于无中心化的集群方案,Codis、Tweproxy属于中心化的集群方案。, 是否中心化是指客户端访问多个Redis节点时,是直接访问还是通过一个中间层Proxy来进行操作,直接访问的就属于无中心化的方案,通过中间层Proxy访问的就属于中心化的方案,它们有各自的优劣,下面分别来介绍。, 客户端分片主要是说,我们只需要部署多个Redis节点,具体如何使用这些节点,主要工作在客户端。, 客户端通过固定的Hash算法,针对不同的key计算对应的Hash值,然后对不同的Redis节点进行读写。, 客户端分片需要业务开发人员事先评估业务的请求量和数据量,然后让DBA部署足够的节点交给开发人员使用即可。, 这个方案的优点是部署非常方便,业务需要多少个节点DBA直接部署交付即可,剩下的事情就需要业务开发人员根据节点数量来编写key的请求路由逻辑,制定一个规则,一般采用固定的Hash算法,把不同的key写入到不同的节点上,然后再根据这个规则进行数据读取。, 可见,它的缺点是业务开发人员使用Redis的成本较高,需要编写路由规则的代码来使用多个节点,而且如果事先对业务的数据量评估不准确,后期的扩容和迁移成本非常高,因为节点数量发生变更后,Hash算法对应的节点也就不再是之前的节点了。, 所以后来又衍生出了一致性哈希算法,就是为了解决当节点数量变更时,尽量减少数据的迁移和性能问题。, 这种客户端分片的方案一般用于业务数据量比较稳定,后期不会有大幅度增长的业务场景下使用,只需要前期评估好业务数据量即可。, 随着业务和技术的发展,人们越发觉得,当我需要使用Redis时,我们不想关心集群后面有多少个节点,我们希望我们使用的Redis是一个大集群,当我们的业务量增加时,这个大集群可以增加新的节点来解决容量不够用和性能问题。, 这种方式就是服务端分片方案,客户端不需要关心集群后面有多少个Redis节点,只需要像使用一个Redis的方式去操作这个集群,这种方案将大大降低开发人员的使用成本,开发人员可以只需要关注业务逻辑即可,不需要关心Redis的资源问题。, 多个节点组成的集群,如何让开发人员像操作一个Redis时那样来使用呢?这就涉及到多个节点是如何组织起来提供服务的,一般我们会在客户端和服务端中间增加一个代理层,客户端只需要操作这个代理层,代理层实现了具体的请求转发规则,然后转发请求到后面的多个节点上,因此这种方式也叫做中心化方式的集群方案,Codis就是以这种方式实现的集群化方案。, Codis是由国人前豌豆荚大神开发的,采用中心化方式的集群方案。因为需要代理层Proxy来进行所有请求的转发,所以对Proxy的性能要求很高,Codis采用Go语言开发,兼容了开发效率和性能。, 可见Codis的组件还是挺多的,它的功能非常全,除了请求转发功能之外,还实现了在线数据迁移、节点扩容缩容、故障自动恢复等功能。, Codis的Proxy就是负责请求转发的组件,它内部维护了请求转发的具体规则,Codis把整个集群划分为1024个槽位,在处理读写请求时,采用crc32Hash算法计算key的Hash值,然后再根据Hash值对1024个槽位取模,最终找到具体的Redis节点。, Codis最大的特点就是可以在线扩容,在扩容期间不影响客户端的访问,也就是不需要停机。这对业务使用方是极大的便利,当集群性能不够时,就可以动态增加节点来提升集群的性能。, 为了实现在线扩容,保证数据在迁移过程中还有可靠的性能,Codis针对Redis进行了修改,增加了针对异步迁移数据相关命令,它基于Redis 3.2.8进行开发,上层配合Dashboard和Proxy组件,完成对业务无损的数据迁移和扩容功能。, 因此,要想使用Codis,必须使用它内置的Redis,这也就意味着Codis中的Redis是否能跟上官方最新版的功能特性,可能无法得到保障,这取决于Codis的维护方,目前Codis已经不再维护,所以使用Codis时只能使用3.2.8版的Redis,这是一个痛点。, 另外,由于集群化都需要部署多个节点,因此操作集群并不能完全像操作单个Redis一样实现所有功能,主要是对于操作多个节点可能产生问题的命令进行了禁用或限制,具体可参考Codis不支持的命令列表。, 但这不影响它是一个优秀的集群化方案,由于我司使用Redis集群方案较早,那时Redis Cluster还不够成熟,所以我司使用的Redis集群方案就是Codis。目前我的工作主要是围绕Codis展开的,我们公司对Codis进行了定制开发,还对Redis进行了一些改造,让Codis支持了跨多个数据中心的数据同步,因此我对Codis的代码比较熟悉,后面会专门写一些文章来剖析Codis的实现原理,学习它的原理,这对我们理解分布式存储有很大的帮助!, Twemproxy是由Twitter开源的集群化方案,它既可以做Redis Proxy,还可以做Memcached Proxy。, 它的功能比较单一,只实现了请求路由转发,没有像Codis那么全面有在线扩容的功能,它解决的重点就是把客户端分片的逻辑统一放到了Proxy层而已,其他功能没有做任何处理。, Tweproxy推出的时间最久,在早期没有好的服务端分片集群方案时,应用范围很广,而且性能也极其稳定。, 但它的痛点就是无法在线扩容、缩容,这就导致运维非常不方便,而且也没有友好的运维UI可以使用。Codis就是因为在这种背景下才衍生出来的。, 采用中间加一层Proxy的中心化模式时,这就对Proxy的要求很高,因为它一旦出现故障,那么操作这个Proxy的所有客户端都无法处理,要想实现Proxy的高可用,还需要另外的机制来实现,例如Keepalive。, 而且增加一层Proxy进行转发,必然会有一定的性能损耗,那么除了客户端分片和上面提到的中心化的方案之外,还有比较好的解决方案么?, Redis官方推出的Redis Cluster另辟蹊径,它没有采用中心化模式的Proxy方案,而是把请求转发逻辑一部分放在客户端,一部分放在了服务端,它们之间互相配合完成请求的处理。, Redis Cluster是在Redis 3.0推出的,早起的Redis Cluster由于没有经过严格的测试和生产验证,所以并没有广泛推广开来。也正是在这样的背景下,业界衍生了出了上面所说的中心化集群方案:Codis和Tweproxy。, 但随着Redis的版本迭代,Redis官方的Cluster也越来越稳定,更多人开始采用官方的集群化方案。也正是因为它是官方推出的,所以它的持续维护性可以得到保障,这就比那些第三方的开源方案更有优势。, Redis Cluster没有了中间的Proxy代理层,那么是如何进行请求的转发呢?, Redis把请求转发的逻辑放在了Smart Client中,要想使用Redis Cluster,必须升级Client SDK,这个SDK中内置了请求转发的逻辑,所以业务开发人员同样不需要自己编写转发规则,Redis Cluster采用16384个槽位进行路由规则的转发。, 没有了Proxy层进行转发,客户端可以直接操作对应的Redis节点,这样就少了Proxy层转发的性能损耗。, Redis Cluster也提供了在线数据迁移、节点扩容缩容等功能,内部还内置了哨兵完成故障自动恢复功能,可见它是一个集成所有功能于一体的Cluster。因此它在部署时非常简单,不需要部署过多的组件,对于运维极其友好。, Redis Cluster在节点数据迁移、扩容缩容时,对于客户端的请求处理也做了相应的处理。当客户端访问的数据正好在迁移过程中时,服务端与客户端制定了一些协议,来告知客户端去正确的节点上访问,帮助客户端订正自己的路由规则。, 虽然Redis Cluster提供了在线数据迁移的功能,但它的迁移性能并不高,迁移过程中遇到大key时还有可能长时间阻塞迁移的两个节点,这个功能相较于Codis来说,Codis数据迁移性能更好。这里先了解一个大概就好,后面我会专门针对Codis和Redis Cluster在线迁移功能的性能对比写一些文章。, 现在越来越多的公司开始采用Redis Cluster,有能力的公司还在它的基础上进行了二次开发和定制,来解决Redis Cluster存在的一些问题,我们期待Redis Cluster未来有更好的发展。, 业界主流的集群化方案就是以上这些,并对它们的特点和区别做了简单的介绍,我们在开发过程中选择自己合适的集群方案即可,但最好是理解它们的实现原理,在使用过程中遇到问题才可以更从容地去解决。, 如果此文章能给您带来小小的工作效率提升,不妨小额赞助我一下,以鼓励我写出更好的文章!, 坐标北京,6年+工作经验,做过UGC后端服务,目前从事基础架构方向,主要聚焦在多机房数据库中间件的研发,实现多机房存储层的灾备与多活,主要使用Golang技术栈。追求技术,关注互联网动态。工具控、电影迷!, http://kaito-kidd.com/2020/07/07/redis-cluster-codis-twemproxy/, codis-dashbaord:统一的控制中心,整合了数据转发规则、故障自动恢复、数据在线迁移、节点扩容缩容、自动化运维API等功能, codis-group:基于Redis 3.2.8版本二次开发的Redis Server,增加了异步数据迁移功能.