在mod_perl下创建持久性memcached连接的最佳方法是什么? [英] What is the best way to create persistent memcached connections under mod_perl?

查看:78
本文介绍了在mod_perl下创建持久性memcached连接的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有一个像Apache::DBI这样的模块,允许使用mod_perl下的数据库永久连接.

I know there is a module like Apache::DBI which allows to use persistent connections to database under mod_perl.

有没有简单的方法可以制作这样的东西?您能推荐任何memcached池软件包吗?

Is there an easy way to make something like this? Could you recommend any memcached pooling package?

推荐答案

如果查看Apache :: DBI的源代码,您会发现它只是将数据库句柄放在包顶部的词法范围内.为Memcached做到这一点很容易.制作一个新的程序包,并在顶部使用my $memcached;,然后使用init()方法进行连接并将其保存在该词法中.然后使用getConnection()方法在代码中获取连接.该方法需要检查连接是否仍然有效,并在需要时重新连接.

If you look at Apache::DBI's source code, you'll see that it just puts the database handle in a lexical scoped at the top of the package. It's easy enough to do this for Memcached. Make a new package, with a my $memcached; at the top, then have an init() method make the connection and save it in that lexical. Then have a getConnection() method to fetch the connection in your code. That method needs to check if the connection is still alive and reconnect if needed.

最后,设置一个PerlChildInitHandler来调用init()(请参阅Apache :: DBI connect_on_init()).

Lastly, setup a PerlChildInitHandler to call init() (see Apache::DBI connect_on_init()).

这篇关于在mod_perl下创建持久性memcached连接的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆