Skip to content

Commit

Permalink
feat: Add krc:ping/2 (#25)
Browse files Browse the repository at this point in the history
* feat: Add krc:ping/1 and krc:ping/2

* this should work

* remove rebar.lock
  • Loading branch information
moritzploss-k authored Jun 11, 2024
1 parent 8068891 commit d7ebcf0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ doc
.emacs*
_build
*~
.vscode/
rebar.lock
4 changes: 4 additions & 0 deletions src/krc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
, get_index_keys/4
, get_index_keys/5
, list_keys/2
, ping/2
, put/2
, put/3
, put_index/3
Expand Down Expand Up @@ -191,6 +192,9 @@ get_index_keys(S, B, I, K, T) ->
%% @doc Get all keys from a bucket B.
list_keys(S, B) -> krc_server:list_keys(S, B).

%% @doc Ping Riak, using the specified timeout.
-spec ping(server(), timeout()) -> whynot(_).
ping(S, Timeout) -> krc_server:ping(S, Timeout).

-spec put(server(), obj()) -> whynot(_).
-spec put(server(), obj(), props()) -> whynot(_).
Expand Down
4 changes: 4 additions & 0 deletions src/krc_mock_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
, get/5
, get_index/5
, get_index/6
, ping/2
, put/4
, start_link/3
]).
Expand Down Expand Up @@ -79,6 +80,7 @@ delete(P, B, K, Os, T) -> call(P, {delete, [B, K, Os, T] }).
get(P, B, K, Os, T) -> call(P, {get, [B, K, Os, T] }).
get_index(P, B, I, K, T) -> call(P, {get_index, [B, I, K, T] }).
get_index(P, B, I, L, U, T) -> call(P, {get_index, [B, I, L, U, T]}).
ping(P, T) -> call(P, {ping, [T] }).
put(P, O, Os, T) -> call(P, {put, [O, Os, T] }).

%% Simulate Riak timeout via gen_server timeout.
Expand Down Expand Up @@ -139,6 +141,8 @@ do(get_index, [B, I, L, U, _], #s{idxs=Idxs} = S) ->
end, [], [K || K <- dict:fetch_keys(Dict), L =< K, K =< U]);
{error, notfound} -> {ok, []}
end};
do(ping, [_], S) ->
{S, ok};
do(put, [O, _, _], #s{tabs=Tabs0, idxs=Idxs0, revdxs=Revdxs0} = S) ->
Bucket = krc_obj:bucket(O),
Key = krc_obj:key(O),
Expand Down
9 changes: 9 additions & 0 deletions src/krc_pb_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
, get_index/5
, get_index/6
, list_keys/3
, ping/2
, put/4
, putwo/4
, set_bucket/4
Expand All @@ -57,6 +58,14 @@ delete(Pid, Bucket, Key, Options, Timeout) ->
get(Pid, Bucket, Key, Options, Timeout) ->
obj_exec(Pid, get, Bucket, Key, Options, Timeout).

ping(Pid, Timeout) ->
try
pong = riakc_pb_socket:ping(Pid, Timeout),
ok
catch
_:Reason -> {error, Reason}
end.

putwo(Pid, Obj, Options, Timeout) -> put(Pid, Obj, Options, Timeout).
put(Pid, Obj, Options, Timeout) ->
obj_exec(Pid, put, Obj, Options, Timeout).
Expand Down
1 change: 1 addition & 0 deletions src/krc_riak_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
-callback delete(_, _, _, _, _) -> _.
-callback get(_, _, _, _, _) -> _.
-callback get_index(_, _, _, _, _) -> _.
-callback ping(_, timeout()) -> ok | {error, _}.
-callback put(_, _, _, _) -> _.
-callback start_link(_, _, _) -> _.

Expand Down
3 changes: 3 additions & 0 deletions src/krc_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
, get_index/5
, get_index/6
, list_keys/2
, ping/2
, put/2
, put/3
, set_bucket/3
Expand Down Expand Up @@ -147,6 +148,7 @@ get_index(GS, B, I, K, T)
get_index(GS, B, I, L, U) -> call(GS, {get_index, [B, I, L, U]}).
get_index(GS, B, I, L, U, T) -> call(GS, {get_index, [B, I, L, U], T}, T).
list_keys(GS, B) -> call(GS, {list_keys, [B]}).
ping(GS, T) -> call(GS, {ping, [], T}, T).
put(GS, O) -> call(GS, {put, [O] }).
put(GS, O, Opts) -> call(GS, {putwo, [O, Opts]}).
set_bucket(GS, B, P) -> call(GS, {set_bucket, [B, P]}).
Expand Down Expand Up @@ -347,6 +349,7 @@ opts(get) -> [ropts()];
opts(get_bucket)-> [];
opts(get_index) -> [];
opts(list_keys) -> [];
opts(ping) -> [];
opts(put) -> [wopts()];
opts(putwo) -> [];
opts(set_bucket)-> [].
Expand Down

0 comments on commit d7ebcf0

Please sign in to comment.