美文网首页
memcache和redis的连接池connection_poo

memcache和redis的连接池connection_poo

作者: maiyang | 来源:发表于2015-12-30 09:14 被阅读755次

(嗨,大家好!欢迎关注我的公众号“茶歇驿站”,微信号“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.

相关文章

网友评论

      本文标题:memcache和redis的连接池connection_poo

      本文链接:https://www.haomeiwen.com/subject/mvsihttx.html