Skip to content

Instantly share code, notes, and snippets.

@tylerflint
Created September 14, 2011 18:00
Show Gist options
  • Save tylerflint/1217271 to your computer and use it in GitHub Desktop.
Save tylerflint/1217271 to your computer and use it in GitHub Desktop.
erlang function to add a shard with simple error handling
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