Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return {ok,CAS::integer()} instead of ok for all store operations. #86

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -53,7 +53,7 @@ cberl:start_link(cberl_default, 5).
{ok, <0.33.0>}
% Poolname, Key, Expire - 0 for infinity, Value
cberl:set(cberl_default, <<"fkey">>, 0, <<"cberl">>).
ok
{ok,CAS}
cberl:get(cberl_default, <<"fkey">>).
{<<"fkey">>, ReturnedCasValue, <<"cberl">>}
```
Expand Down
2 changes: 1 addition & 1 deletion c_src/cb.c
Expand Up @@ -181,7 +181,7 @@ ERL_NIF_TERM cb_store(ErlNifEnv* env, handle_t* handle, void* obj)
if (cb.error != LCB_SUCCESS) {
return return_lcb_error(env, cb.error);
}
return A_OK(env);
return enif_make_tuple2(env, A_OK(env), enif_make_uint64(env, cb.cas));
}

void* cb_mget_args(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
Expand Down
2 changes: 1 addition & 1 deletion include/cberl.hrl
Expand Up @@ -22,7 +22,7 @@
connected :: true | false,
opts :: list()}).

-type key() :: string().
-type key() :: binary().
-type value() :: string() | list() | integer() | binary().
-type operation_type() :: add | replace | set | append | prepend.
-type instance() :: #instance{}.
Expand Down
24 changes: 12 additions & 12 deletions src/cberl.erl
Expand Up @@ -73,32 +73,32 @@ stop(PoolPid) ->
%%%%%%%%%%%%%%%%%%%%%%%%

%% @equiv add(PoolPid, Key, Exp, Value, standard)
-spec add(pid(), key(), integer(), value()) -> ok | {error, _}.
-spec add(pid(), key(), integer(), value()) -> {ok,integer()} | {error, _}.
add(PoolPid, Key, Exp, Value) ->
add(PoolPid, Key, Exp, Value, standard).

%% @equiv store(PoolPid, add, Key, Value, TranscoderOpts, Exp, 0)
-spec add(pid(), key(), integer(), value(), atom()) -> ok | {error, _}.
-spec add(pid(), key(), integer(), value(), atom()) -> {ok,integer()} | {error, _}.
add(PoolPid, Key, Exp, Value, TranscoderOpts) ->
store(PoolPid, add, Key, Value, TranscoderOpts, Exp, 0).

%% @equiv replace(PoolPid, Key, Exp, Value, standard)
-spec replace(pid(), key(), integer(), value()) -> ok | {error, _}.
-spec replace(pid(), key(), integer(), value()) -> {ok,integer()} | {error, _}.
replace(PoolPid, Key, Exp, Value) ->
replace(PoolPid, Key, Exp, Value, standard).

%% @equiv store(PoolPid, replace, "", Key, Value, Exp)
-spec replace(pid(), key(), integer(), value(), atom()) -> ok | {error, _}.
-spec replace(pid(), key(), integer(), value(), atom()) -> {ok,integer()} | {error, _}.
replace(PoolPid, Key, Exp, Value, TranscoderOpts) ->
store(PoolPid, replace, Key, Value, TranscoderOpts, Exp, 0).

%% @equiv set(PoolPid, Key, Exp, Value, standard)
-spec set(pid(), key(), integer(), value()) -> ok | {error, _}.
-spec set(pid(), key(), integer(), value()) -> {ok,integer()} | {error, _}.
set(PoolPid, Key, Exp, Value) ->
set(PoolPid, Key, Exp, Value, standard).

%% @equiv store(PoolPid, set, "", Key, Value, Exp)
-spec set(pid(), key(), integer(), value(), atom()) -> ok | {error, _}.
-spec set(pid(), key(), integer(), value(), atom()) -> {ok,integer()} | {error, _}.
set(PoolPid, Key, Exp, Value, TranscoderOpts) ->
store(PoolPid, set, Key, Value, TranscoderOpts, Exp, 0).

Expand All @@ -113,7 +113,7 @@ set(PoolPid, Key, Exp, Value, TranscoderOpts) ->
append(PoolPid, _Cas, Key, Value) ->
append(PoolPid, Key, Value).

-spec append(pid(), key(), value()) -> ok | {error, _}.
-spec append(pid(), key(), value()) -> {ok,integer()} | {error, _}.
append(PoolPid, Key, Value) ->
store(PoolPid, append, Key, Value, none, 0, 0).

Expand All @@ -124,7 +124,7 @@ append(PoolPid, Key, Value) ->
prepend(PoolPid, _Cas, Key, Value) ->
prepend(PoolPid, Key, Value).

-spec prepend(pid(), key(), value()) -> ok | {error, _}.
-spec prepend(pid(), key(), value()) -> {ok,integer()} | {error, _}.
prepend(PoolPid, Key, Value) ->
store(PoolPid, prepend, Key, Value, none, 0, 0).

Expand Down Expand Up @@ -212,7 +212,7 @@ unlock(PoolPid, Key, Cas) ->
%% pass 0 for infinity
%% CAS
-spec store(pid(), operation_type(), key(), value(), atom(),
integer(), integer()) -> ok | {error, _}.
integer(), integer()) -> {ok,integer()} | {error, _}.
store(PoolPid, Op, Key, Value, TranscoderOpts, Exp, Cas) ->
execute(PoolPid, {store, Op, Key, Value,
TranscoderOpts, Exp, Cas}).
Expand All @@ -223,7 +223,7 @@ store(PoolPid, Op, Key, Value, TranscoderOpts, Exp, Cas) ->
%% Key the key to get
%% Exp When the object should expire
%% pass a negative number for infinity
-spec mget(pid(), [key()], integer()) -> list().
-spec mget(pid(), [key()], integer()) -> list() | {error, _}.
mget(PoolPid, Keys, Exp) ->
execute(PoolPid, {mget, Keys, Exp, 0}).

Expand All @@ -232,7 +232,7 @@ mget(PoolPid, Keys, Exp) ->
%% HashKey the key to use for hashing
%% Key the key to get
%% Exp When the lock should expire
-spec getl(pid(), key(), integer()) -> list().
-spec getl(pid(), key(), integer()) -> list() | {error, _}.
getl(PoolPid, Key, Exp) ->
execute(PoolPid, {mget, [Key], Exp, 1}).

Expand Down Expand Up @@ -297,7 +297,7 @@ handle_flush_result(PoolPid, FlushMarker, Result={ok, 201, _}) ->
%% Method HTTP method
%% Type Couchbase request type
-spec http(pid(), string(), string(), string(), http_method(), http_type())
-> {ok, binary()} | {error, _}.
-> {ok, integer(), binary()} | {error, _}.
http(PoolPid, Path, Body, ContentType, Method, Type) ->
execute(PoolPid, {http, Path, Body, ContentType, http_method(Method), http_type(Type)}).

Expand Down