memcache和redis的连接池connection_pool使用

(嗨,大家好!欢迎关注我的公众号“茶歇驿站”,微信号“tech_tea”,请大家多多支持,欢迎大家分享,如若转载请注明出处~~~)

memcache 的Ruby客户端比较常用的是(DalliCache)[https://github.com/mperham/dalli]
连接池项目(connection_pool)[https://github.com/mperham/connection_pool]

实战分析:

在application.rb 中添加

redis

case ENV["RACK_ENV"]
when "production"
REDIS = ConnectionPool::Wrapper.new(size: 10, timeout: 5) {
Redis.new(:driver => :synchrony, :host => "10.1.1.1", :port => 6379)
}
when "development"
REDIS = ConnectionPool::Wrapper.new(size: 10, timeout: 5) {
Redis.new(:driver => :synchrony, :host => "192.168.1.2", :port => 6379)
}
end

memcache

case ENV["RACK_ENV"]
when "production"
Dalli.logger = logger
DALLI_CACHE = ConnectionPool::Wrapper.new(size: 10, timeout: 5) {
Dalli::Client.new("10.1.1.2:11211",
{:threadsafe => true, :failover => true, :expires_in => 1.day, :compress => true})
}
when "development"
DALLI_CACHE = ConnectionPool::Wrapper.new(size: 10, timeout: 5) {
Dalli::Client.new("192.168.1.2:11211",
{:threadsafe => true, :failover => true, :expires_in => 1.day, :compress => true})
}
end

需要使用到redis或者memcache的时候,直接使用即可,并发支持最大量为配置的size的个数,每个连接的超市时间是5秒。

但是DalliCache不支持text协议的memcache集群。

如果需要集群,则只能根据文档来解决。

issues

dalli作者的官方答复:

twemproxy does not support the memcached binary protocol.

Use an SSH tunnel instead.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容