sharded_eredis

本文涉及的产品
云数据库 Tair(兼容Redis),内存型 2GB
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
简介:

Copyright (c) 2012 PlayMesh, Inc.

sharded_eredis is collection of pools of Redis clients, using eredis and poolboy. Each pool points to a different shard.

This project modifies the original repository by including a consistent hashing library to simplify presharding, suggested by antirez. Read the original blogpost here.

The name has been changed so as not to induce confusion for those originally using hiroeorz's sharded_eredis; the functionality has changed significantly.

eredis: https://github.com/wooga/eredis

poolboy: https://github.com/devinus/poolboy

Caveats!!

This library uses Redis but in a distributed fashion. Multi-object operations are no longer guaranteed to be atomic and are not supported by this library. Examples include multisets, multigets, source-destination operations, and multi-object transactions. Transactions technically still work if all keys involved in the transaction are on the same machine but the Redis transaction was not built to be distributed.

Setup

  • git clone git://github.com/jeremyong/sharded_eredis.git
  • cd eredis_pool
  • make get-deps
  • make

Testing

make test

Config

Add new pools. This configuration specifies 4 shards.

  {env, [
          {global_or_local, local}
          {pools, [
                   {pool0, [
                              {size, 10},
                              {max_overflow, 20}
                              {host, "127.0.0.1"},
                              {port, 6378}
                             ]},
                   {pool1, [
                              {size, 10},
                              {max_overflow, 20},
                              {host, "127.0.0.1"},
                              {port, 6380}
                             ]},
                   {pool2, [
                              {size, 10},
                              {max_overflow, 20},
                              {host, "127.0.0.1"},
                              {port, 6381},
                             ]}
                   {pool3, [
                              {size, 10},
                              {max_overflow, 20},
                              {host, "127.0.0.1"},
                              {port, 6382},
                             ]}
                  ]}
        ]}

You can include this using the erlang -config option.

The global_or_local option is used to determine whether the pools are registered as local or global. Personally, I start this application on every instance and run pools on each instance locally to minimize network latency.

Examples

application start.

 sharded_eredis:start().
 ok

key-value set and get

 sharded_eredis:q(["SET", "foo", "bar"]).
 {ok,<<"OK">>}
 
 sharded_eredis:q(["GET", "foo"]).       
 {ok,<<"bar">>}

Note that the name of the pool does not need to be supplied with each query (in contrast to prior behavior). The library will automatically determine which pool associated to the correct shard should be invoked.

The Redis documentation can be referred to here.






本文作者:陈群
本文来自云栖社区合作伙伴rediscn,了解相关信息可以关注redis.cn网站。
相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore &nbsp; &nbsp; ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库&nbsp;ECS 实例和一台目标数据库&nbsp;RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&amp;RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
目录
相关文章
|
存储 索引
Cluster 与 Replication
Cluster 与 Replication
120 1
|
NoSQL
How to Create Highly Available MongoDB Databases with Replica Sets
Find out how you can create MongoDB databases with high availability by backing up data through replica set elections.
4127 0
How to Create Highly Available MongoDB Databases with Replica Sets
|
NoSQL
An Insight into MongoDB Sharding Chunk Splitting and Migration
Sharding is a method of data distribution across multiple machines. MongoDB uses sharding to support deployments with very large data sets and high throughput operations.
3094 0
|
存储 算法 NoSQL
Sharded源码分析
1. 概述 当业务的数据量非常庞大时,需要考虑将数据存储到多个缓存节点上,如何定位数据应该存储的节点,一般用的是一致性哈希算法。 Jedis在客户端角度实现了一致性哈希算法,对数据进行分片,存储到对应的不同的redis实例中。
1239 0
|
NoSQL MongoDB 数据安全/隐私保护