memcache library

126 views
Skip to first unread message

Brad Fitzpatrick

unread,
Jun 28, 2011, 9:51:12 PM6/28/11
to golang-nuts
I wrote a memcache client library:


It has some tests and seems to work but I haven't heavily stressed it yet.

Feedback or feature requests welcome!

Brad

Andrew Chilton

unread,
Aug 14, 2011, 5:38:52 AM8/14/11
to golang-nuts
Hi GoNuts and Brad,

On 29 June 2011 13:51, Brad Fitzpatrick <brad...@golang.org> wrote:
> I wrote a memcache client library:
> https://github.com/bradfitz/gomemcache/

Firstly, thanks for this. I have been experimenting with it, but just
looking to figure out the best idiomatic way to use it in a webapp.

My first take on it was to create the memcache client inside each
request (just to get it working), but this isn't the best way. So I
figured I'd just stick it as a global which my handlers could see ...
in other languages this has served me well. Finally I came upon the
init() function, so ended up with something like the following. Does
this look like a remotely decent way of doing this, or is there a
better suggestion from anyone else?

* https://gist.github.com/1144739

Note: the reason I figured it was ok to put it as a global is because
in the docs it says that the Memcache Client is "... safe for unlocked
use by multiple concurrent goroutines". Am I correct in presuming
doing it this way is safe?

Many thanks,
Andy

--
contact: Andrew Chilton
website: http://www.chilts.org/blog/

Brad Fitzpatrick

unread,
Aug 14, 2011, 1:16:51 PM8/14/11
to Andrew Chilton, golang-nuts
On Sun, Aug 14, 2011 at 2:38 AM, Andrew Chilton <andyc...@gmail.com> wrote:
Hi GoNuts and Brad,

On 29 June 2011 13:51, Brad Fitzpatrick <brad...@golang.org> wrote:
> I wrote a memcache client library:
>     https://github.com/bradfitz/gomemcache/

Firstly, thanks for this. I have been experimenting with it, but just
looking to figure out the best idiomatic way to use it in a webapp.

My first take on it was to create the memcache client inside each
request (just to get it working), but this isn't the best way.

Yeah, don't do that.  If you do, the TCP connections to each shard will be re-created each time, which isn't good.
 
So I
figured I'd just stick it as a global which my handlers could see ...
in other languages this has served me well. Finally I came upon the
init() function, so ended up with something like the following. Does
this look like a remotely decent way of doing this, or is there a
better suggestion from anyone else?

* https://gist.github.com/1144739

Note: the reason I figured it was ok to put it as a global is because
in the docs it says that the Memcache Client is "... safe for unlocked
use by multiple concurrent goroutines". Am I correct in presuming
doing it this way is safe?

Yup, that works.  Either a global, or put it as a field in a struct implementing http.Handler.
Reply all
Reply to author
Forward
0 new messages