Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:19
eredis_pool
eredis_pool-add-watch_transaction-3.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File eredis_pool-add-watch_transaction-3.patch of Package eredis_pool
From e0c06cdd7bf9ce50c9fbe165e1951bf0911fa5ae Mon Sep 17 00:00:00 2001 From: Led <ledest@gmail.com> Date: Wed, 17 Feb 2016 16:29:15 +0200 Subject: [PATCH 2/2] eredis_pool: add watch_transaction/3 --- src/eredis_pool.erl | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/eredis_pool.erl b/src/eredis_pool.erl index d216d36..090f96f 100644 --- a/src/eredis_pool.erl +++ b/src/eredis_pool.erl @@ -17,7 +17,7 @@ %% API -export([start/0, stop/0]). --export([q/2, q/3, qp/2, qp/3, transaction/2, +-export([q/2, q/3, qp/2, qp/3, transaction/2, watch_transaction/3, create_pool/2, create_pool/3, create_pool/4, create_pool/5, create_pool/6, create_pool/7, delete_pool/1]). @@ -143,3 +143,40 @@ transaction(PoolName, Fun) when is_function(Fun) -> end, poolboy:transaction(PoolName, F). + +-spec watch_transaction(PoolName::atom(), Keys::[string()|binary()|atom()], Fun::fun((pid()) -> list())) -> {ok, undefined|binary()|[binary()]} | {error, Reason::binary()|term()}. +watch_transaction(PoolName, [_|_] = Keys, Fun) when is_function(Fun, 1) -> + poolboy:transaction(PoolName, + fun(C) -> + case eredis:q(C, ["WATCH"|Keys]) of + {ok, <<"OK">>} -> + try Fun(C) of + [_|_] = R1 -> + {ok, <<"OK">>} = eredis:q(C, ["MULTI"]), + R2 = eredis:qp(C, R1), + case lists:all(fun({ok, <<"QUEUED">>}) -> true; + (_) -> false + end, R2) of + true -> eredis:q(C, ["EXEC"]); + _ -> + {ok, <<"OK">>} = eredis:q(C, ["DISCARD"]), + io:fwrite(standard_error, + ?MODULE_STRING ": Error in redis watch transaction: ~p~n", + [R2]), + {error, R2} + end; + [] -> + {ok, <<"OK">>} = eredis:q(C, ["UNWATCH"]), + {ok, []}; + E -> + io:fwrite(standard_error, + ?MODULE_STRING ": Error in redis watch: ~p~n", + [E]), + {error, E} + catch Class:Reason -> + {ok, <<"OK">>} = eredis:q(C, ["UNWATCH"]), + {Class, Reason} + end; + E -> E + end + end). -- 2.1.4
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor