Created
September 14, 2011 18:00
-
-
Save tylerflint/1217271 to your computer and use it in GitHub Desktop.
erlang function to add a shard with simple error handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_shard(Master, Slave) -> | |
ErrorMsg = "unable to add shard", | |
case ?NEW_SHARD_KEY of | |
{error, _Msg} -> | |
{error, ErrorMsg}; | |
ShardId -> | |
case ?SHARD_KEY_FOR_MEMBERS(ShardId) of | |
{error, _Msg} -> | |
{error, ErrorMsg}; | |
ShardKey -> | |
Members = ?ENCODE_MASTER_SLAVE(Master,Slave), | |
case ?REDIS(["SET",ShardKey,Members]) of | |
{error, _Msg} -> {error, ErrorMsg}; | |
_AnythingElse -> {ok, ShardId} | |
end | |
end | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment