Redis 复制和redis sharding(集群)的区别 [英] Redis replication and redis sharding (cluster) difference

查看:45
本文介绍了Redis 复制和redis sharding(集群)的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 有人知道redis复制和redis分片的区别吗?
  2. 它们有什么用?Redis 将数据存储在内存中,这对复制/分片有何影响?
  3. 可以同时使用它们吗?

推荐答案

分片几乎是复制的对立面,尽管它们是正交的概念并且可以很好地协同工作.

Sharding is almost replication's antithesis, though they are orthogonal concepts and work well together.

Sharding,也叫partitioning,就是把数据按key分割;而复制也称为镜像,就是复制所有数据.

Sharding, also known as partitioning, is splitting the data up by key; While replication, also known as mirroring, is to copy all data.

分片有助于提高性能,减少对任何一种资源的命中和内存负载.复制对于获得读取的高可用性很有用.如果从多个副本读取,也会降低所有资源的命中率,但所有资源的内存需求保持不变.应该注意的是,虽然您可以写入从属设备,但复制只能是主设备-> 从设备.所以你不能以这种方式扩展写入.

Sharding is useful to increase performance, reducing the hit and memory load on any one resource. Replication is useful for getting a high availability of reads. If you read from multiple replicas, you will also reduce the hit rate on all resources, but the memory requirement for all resources remains the same. It should be noted that, while you can write to a slave, replication is master->slave only. So you cannot scale writes this way.

假设您有以下元组:[1:Apple], [2:Banana], [3:Cherry], [4:Durian] 并且我们有两台机器 A 和 B.使用分片,我们可能会存储密钥 2,4 在机器 A 上;和密钥 1,3 在机器 B 上.通过复制,我们将密钥 1,2,3,4 存储在机器 A 上,将密钥 1,2,3,4 存储在机器 B 上.

Suppose you have the following tuples: [1:Apple], [2:Banana], [3:Cherry], [4:Durian] and we have two machines A and B. With Sharding, we might store keys 2,4 on machine A; and keys 1,3 on machine B. With Replication, we store keys 1,2,3,4 on machine A and 1,2,3,4 on machine B.

分片通常通过对密钥执行一致的散列来实现.上面的例子是用下面的哈希函数 h(x){return x%2==0?A:B} 实现的.

Sharding is typically implemented by performing a consistent hash upon the key. The above example was implemented with the following hash function h(x){return x%2==0?A:B}.

为了结合这些概念,我们可能会复制每个分片.在上述情况下,机器 A 的所有数据(2,4)都可以复制到机器 C 上,机器 B 的所有数据(1,3)都可以复制到机器 D 上.

To combine the concepts, We might replicate each shard. In the above cases, all of the data (2,4) of machine A could be replicated on machine C and all of the data (1,3) of machine B could be replicated on machine D.

任何键值存储(Redis 只是其中的一个示例)都支持分片,但某些交叉键功能将不再起作用.Redis 支持开箱即用的复制.

Any key-value store (of which Redis is only one example) supports sharding, though certain cross-key functions will no longer work. Redis supports replication out of the box.

这篇关于Redis 复制和redis sharding(集群)的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆