Giter VIP home page Giter VIP logo

eredis_pool's Introduction

eredis_pool

eredis_pool is Pool of Redis clients, using eredis and poolboy.

eredis: github.com/wooga/eredis

poolboy: github.com/devinus/poolboy

Setup

$ git clone git://github.com/hiroeorz/eredis_pool.git
$ cd eredis_pool
$ make get-deps
$ make

Testing

$ make test

Settings

edit src/eredis_pool.app.src

{application, eredis_pool,
 [
  {description, ""},
  {vsn, "1"},
  {registered, []},
  {applications, [
                  kernel,
                  stdlib
                 ]},
  {mod, { eredis_pool_app, []}},
  {env, [
          {global_or_local, local},
          {pools, [
                   {default, [
                              {size, 10},
                              {max_overflow, 20}
                             ], [] }
                  ]}
        ]}
 ]}.

add new pools.

{env, [
        {global_or_local, local},
        {pools, [
                 {default, [
                            {size, 10},
                            {max_overflow, 20}
                           ], []},
                 {pool1, [
                            {size, 30},
                            {max_overflow, 20}
                           ], [
                            {host, "127.0.0.1"},
                            {port, 6379}
                           ]},
                 {pool2, [
                            {size, 20},
                            {max_overflow, 20}
                         ], [
                            {host, "127.0.0.1"},
                            {port, 6379},
                            {database, "user_db"},
                            {password, "abc"},
                            {reconnect_sleep, 100}
                           ]}
                ]}
      ]}

Examples

application start.

eredis_pool:start().
ok

key-value set and get

eredis_pool:q({global, dbsrv}, ["SET", "foo", "bar"]).
{ok,<<"OK">>}

eredis_pool:q({global, dbsrv}, ["GET", "foo"]).       
{ok,<<"bar">>}

Redis Pipeline

Pipeline = [["SET", a, "1"],
     ["LPUSH", b, "3"],
     ["LPUSH", b, "2"]].
eredis_pool:qp({global,dbsrv}, Pipeline).

create new pool with default settings.

eredis_pool:create_pool(pool1, 10).
{ok,<0.64.0>}

and omissible argments(host, port, database, password reconnect_sleep).

eredis_pool:create_pool(pool1, 10, "127.0.0.1", 6379, 1, "abc", 100).
{ok,<0.64.0>}

using new pool

eredis_pool:q(pool1, ["GET", "foo"]).
{ok,<<"bar">>}

delete pool

eredis_pool:delete_pool(pool1).    
ok

Other commands is here. redis.io/commands

eredis_pool's People

Contributors

atulpundhir avatar hiroeorz avatar sveinnfannar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

eredis_pool's Issues

Documentation state database is a name (string), but it needs to be an integer

Database in Redis are just integer, not names.

Reference: http://stackoverflow.com/questions/6618291/why-does-redis-use-integer-database-numbers

When you create an eredis_pool, with a database name, you have the following crash:(push-

api@mr-macbook)3> 21:49:22.213 [error] CRASH REPORT Process <0.209.0> with 0 neighbours exited with reason: bad argument in call to erlang:integer_to_list("user_db") in eredis_client:init/1 line 73 in gen_server:init_it/6 line 328

default env does not allow application to start

Hi, with the default {env, []} in eredis_pool.app.src, I could not start the application before I start/add a pool.
Can it be modified so that application can start without starting any pool ?
I guess following can do: {env, [{pools,[]}, {global_or_local, local}]} ?

returning worker to pool too early?

Hi,

I was just reading through your code (planning to use poolboy for a connection pool myself), when I noticed something weird in eredis_pool:q/3:

q(PoolName, Command, Timeout) ->
Worker = poolboy:checkout(PoolName),
poolboy:checkin(PoolName, Worker),
Reply = eredis:q(Worker, Command, Timeout),
Reply.

shouldn't the poolboy:checkin.. really happen after the Worker has done its eredis:q... request? like so:

q(PoolName, Command, Timeout) ->
Worker = poolboy:checkout(PoolName),
Reply = eredis:q(Worker, Command, Timeout),
poolboy:checkin(PoolName, Worker),
Reply.

otherwise the worker immediately becomes available to other concurrent clients, even before it is done with the request, no?

I am not really planning to use redis at the moment, so ignore / delete at your leisure, but since I already spotted it, I figured I may as well drop you a note.

Fabian

supervisor using default config fails.

using the master branch with the default config fails.
i confirmed i was able to connect to the same IP+port and query the redis server.

it build ok but a simple run as well as eunit fail:

$ make
==> eredis (clean)
==> poolboy (clean)
==> edown (clean)
==> eredis_pool (clean)
==> eredis (compile)
Compiled src/eredis.erl
Compiled src/eredis_client.erl
Compiled src/eredis_sub_client.erl
Compiled src/basho_bench_driver_erldis.erl
Compiled src/eredis_sub.erl
Compiled src/basho_bench_driver_eredis.erl
Compiled src/eredis_parser.erl
==> poolboy (compile)
Compiled src/poolboy_sup.erl
Compiled src/poolboy.erl
==> edown (compile)
Compiled src/edown_make.erl
Compiled src/edown_lib.erl
Compiled src/edown_xmerl.erl
Compiled src/edown_doclet.erl
Compiled src/edown_layout.erl
==> eredis_pool (compile)
Compiled src/eredis_pool_app.erl
Compiled src/eredis_pool.erl
Compiled src/eredis_pool_sup.erl
==> eredis_pool (xref)

$ erl -boot start_sasl -pa ebin/
Erlang R14B04 (erts-5.8.5) [source] [64-bit] [smp:16:16] [rq:16] [async-threads:0] [kernel-poll:false]

=PROGRESS REPORT==== 21-Mar-2012::18:28:17 ===
supervisor: {local,sasl_safe_sup}
started: [{pid,<0.35.0>},
{name,alarm_handler},
{mfargs,{alarm_handler,start_link,[]}},
{restart_type,permanent},
{shutdown,2000},
{child_type,worker}]

=PROGRESS REPORT==== 21-Mar-2012::18:28:17 ===
supervisor: {local,sasl_safe_sup}
started: [{pid,<0.36.0>},
{name,overload},
{mfargs,{overload,start_link,[]}},
{restart_type,permanent},
{shutdown,2000},
{child_type,worker}]

=PROGRESS REPORT==== 21-Mar-2012::18:28:17 ===
supervisor: {local,sasl_sup}
started: [{pid,<0.34.0>},
{name,sasl_safe_sup},
{mfargs,
{supervisor,start_link,
[{local,sasl_safe_sup},sasl,safe]}},
{restart_type,permanent},
{shutdown,infinity},
{child_type,supervisor}]

=PROGRESS REPORT==== 21-Mar-2012::18:28:17 ===
supervisor: {local,sasl_sup}
started: [{pid,<0.37.0>},
{name,release_handler},
{mfargs,{release_handler,start_link,[]}},
{restart_type,permanent},
{shutdown,2000},
{child_type,worker}]

=PROGRESS REPORT==== 21-Mar-2012::18:28:17 ===
application: sasl
started_at: nonode@nohost
Eshell V5.8.5 (abort with ^G)
1> eredis_pool:start().

=SUPERVISOR REPORT==== 21-Mar-2012::18:28:30 ===
Supervisor: {local,eredis_pool_sup}
Context: start_error
Reason: {'EXIT',
{undef,
[{poolboy,start_link,
[[{name,{global,dbsrv}},
{worker_module,eredis},
{size,10},
{max_overflow,30},
{host,"10.10.0.141"},
{port,6379}]]},
{supervisor,do_start_child,2},
{supervisor,start_children,3},
{supervisor,init_children,2},
{gen_server,init_it,6},
{proc_lib,init_p_do_apply,3}]}}
Offender: [{pid,undefined},
{name,dbsrv},
{mfargs,{poolboy,start_link,
[[{name,{global,dbsrv}},
{worker_module,eredis},
{size,10},
{max_overflow,30},
{host,"10.10.0.141"},
{port,6379}]]}},
{restart_type,permanent},
{shutdown,5000},
{child_type,worker}]

=INFO REPORT==== 21-Mar-2012::18:28:30 ===
application: eredis_pool
exited: {shutdown,{eredis_pool_app,start,[normal,[]]}}
type: temporary
{error,{shutdown,{eredis_pool_app,start,[normal,[]]}}}
2>
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
(v)ersion (k)ill (D)b-tables (d)istribution
a

$ make check
==> eredis_pool (eunit)
Compiled src/eredis_pool.erl
Compiled src/eredis_pool_sup.erl
Compiled test/eredis_pool_tests.erl
Compiled src/eredis_pool_app.erl

=ERROR REPORT==== 21-Mar-2012::18:29:25 ===
** Generic server <0.109.0> terminating
** Last message in was {'EXIT',<0.108.0>,
{{badmatch,
{error,
{'EXIT',
{function_clause,
[{string,tokens1,[false,":/@",[]]},
{eredis,parse_redistogo_uri,0},
{eredis,start_link,1},
{supervisor,do_start_child_i,3},
{supervisor,handle_call,3},
{gen_server,handle_msg,5},
{proc_lib,init_p_do_apply,3}]}}}},
[{poolboy,new_worker,2},
{poolboy,prepopulate,4},
{poolboy,init,2},
{gen_fsm,init_it,6},
{proc_lib,init_p_do_apply,3}]}}
*
When Server state == {state,
{<0.109.0>,poolboy_sup},
simple_one_for_one,
[{child,undefined,eredis,
{eredis,start_link,
[[{size,10},
{max_overflow,30},
{host,"10.10.0.141"},
{port,6379}]]},
temporary,brutal_kill,worker,
[eredis]}],
{dict,0,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],
[]},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],[],
[],[]}}},
0,1,[],poolboy_sup,
{eredis,
[{size,10},
{max_overflow,30},
{host,"10.10.0.141"},
{port,6379}]}}
** Reason for termination ==
* {{badmatch,
{error,
{'EXIT',
{function_clause,
[{string,tokens1,[false,":/
@",[]]},
{eredis,parse_redistogo_uri,0},
{eredis,start_link,1},
{supervisor,do_start_child_i,3},
{supervisor,handle_call,3},
{gen_server,handle_msg,5},
{proc_lib,init_p_do_apply,3}]}}}},
[{poolboy,new_worker,2},
{poolboy,prepopulate,4},
{poolboy,init,2},
{gen_fsm,init_it,6},
{proc_lib,init_p_do_apply,3}]}

=INFO REPORT==== 21-Mar-2012::18:29:25 ===
application: eredis_pool
exited: {shutdown,{eredis_pool_app,start,[normal,[]]}}
type: temporary
eredis_pool_tests: basic_test_ (get and set)...failed
::exit:{noproc,{gen_fsm,sync_send_event,
[{global,dbsrv},{checkout,true,5000},5000]}}
in function gen_fsm:sync_send_event/3
in call from eredis_pool:q/3
in call from eredis_pool_tests:'-basic_test_/0-fun-2-'/0
in call from eredis_pool_tests:'-basic_test_/0-fun-6-'/0

eredis_pool_tests: basic_test_ (delete test)...failed
::exit:{noproc,{gen_fsm,sync_send_event,
[{global,dbsrv},{checkout,true,5000},5000]}}
in function gen_fsm:sync_send_event/3
in call from eredis_pool:q/3
in call from eredis_pool_tests:'-basic_test_/0-fun-7-'/0
in call from eredis_pool_tests:'-basic_test_/0-fun-11-'/0

eredis_pool_tests: basic_test_ (mset and mget)...failed
::exit:{noproc,{gen_fsm,sync_send_event,
[{global,dbsrv},{checkout,true,5000},5000]}}
in function gen_fsm:sync_send_event/3
in call from eredis_pool:q/3
in call from eredis_pool_tests:'-basic_test_/0-fun-12-'/1
in call from eredis_pool_tests:'-basic_test_/0-fun-16-'/0

eredis_pool_tests: basic_test_ (new pool create and delete)...failed
::exit:{noproc,
{gen_server,call,
[eredis_pool_sup,
{start_child,
{pool1,
{poolboy,start_link,
[[{name,{global,...}},
{worker_module,eredis},
{size,...},
{...}]]},
permanent,5000,worker,
[poolboy,eredis]}},
infinity]}}
in function gen_server:call/3
in call from eredis_pool_tests:'-basic_test_/0-fun-17-'/0
in call from eredis_pool_tests:'-basic_test_/0-fun-23-'/0

Failed: 4. Skipped: 0. Passed: 0.
Cover analysis: /home/dirt/eredis_pool/.eunit/index.html
ERROR: One or more eunit tests failed.
make: *** [check] Error 1

Failed on poolboy master branch

Eshell V5.9.2  (abort with ^G)
1> eredis_pool:start().
ok
2> eredis_pool:q(default, ["SET", "foo", "bar"]).
** exception exit: {noproc,{gen_fsm,sync_send_event,
                                    [default,{checkout,true,5000},5000]}}
     in function  gen_fsm:sync_send_event/3 (gen_fsm.erl, line 214)
     in call from poolboy:transaction/2 (src/poolboy.erl, line 45)
3> 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.