The *riak-client* var

62 views
Skip to first unread message

David James

unread,
Jan 21, 2013, 5:01:54 PM1/21/13
to clojur...@googlegroups.com
I was a little surprised that Welle holds the client in the *riak-client* var. It makes the API clean for a single connection. However, how would one handle multiple connections?

Are there other API styles that were considered? (Such as passing a database handle to the API returning a new 'updated' handle?) Perhaps the other styles they passed over for some reason or another? I'm just trying to understand.

Thanks,
David

Michael Klishin

unread,
Jan 21, 2013, 5:25:37 PM1/21/13
to clojur...@googlegroups.com

2013/1/22 David James <david...@gmail.com>

Are there other API styles that were considered? (Such as passing a database handle to the API returning a new 'updated' handle?) Perhaps the other styles they passed over for some reason or another? I'm just trying to understand.

For multiple connections, there is welle.core/with-client:
connection functions that simply returns a client instance rather than altering the var.

Apps that use multiple clients is a rare case. Having a more straightforward API for the common case
is way more important. This is also how Monger, Neocons, Elastisch and Langohr work.

If with-client is missing from the docs, it should be added. Feel free to submit a pull request (see 

Oleksandr Petrov

unread,
Jan 21, 2013, 5:26:25 PM1/21/13
to clojur...@googlegroups.com
I would say that Refs actually serve quite a different purpose.

`alter-var-root` is not the core feature of dynamic vars. Although, bindings are. *riak-client* is a dynamic var (which is indicated by its name). 

For example, marco `with-connection`: https://github.com/michaelklishin/welle/blob/master/src/clojure/clojurewerkz/welle/core.clj#L105-L108 would not be as easy to implement and use with refs. Bindings are thread and scope local, so you can be absolutely sure that client instance that you're passing and using within binding is used there exclusively.

Also, it eases testing. As you can see `alter-var-root` is used only once, after that, for ease of use, same instance is passed along. Nothing forbids you from creating an arbitrary number of clients and using them in binding.

Thanks for checking out Welle.
Alex
--
alex p

David James

unread,
Jan 22, 2013, 10:12:07 AM1/22/13
to clojur...@googlegroups.com
Thanks for explaining.

"Nothing forbids you from creating an arbitrary number of clients and using them in binding." Do you have a quick example of how to do this?

Michael Klishin

unread,
Jan 22, 2013, 10:46:29 AM1/22/13
to clojur...@googlegroups.com

2013/1/22 David James <david...@gmail.com>

"Nothing forbids you from creating an arbitrary number of clients and using them in binding." Do you have a quick example of how to do this?

This is what with-client is for.

Reply all
Reply to author
Forward
0 new messages