xmemcached spring 配置文件
memcached spring 配置文件
<bean class="java.net.InetSocketAddress" name="server1"> <constructor-arg> <value>${memcached.server1.host}</value> </constructor-arg> <constructor-arg> <value>${memcached.server1.port}</value> </constructor-arg> </bean> <!-- # memcachedClientBuilder failureMode=false 是否启用failure模式,true为启用,默认不启用。所谓failure模式是指, #connectionPoolSize=1 nio连接池大小,默认对一个memcached节点只有一个连接,这在通常情况 下已经有非常优异的表现。但是在典型的高并发环境下,nio的单连接也会遇到性能瓶颈。可通过调整 连接池数量,允许建立多个连接到同一个memcached节点,但是请注意,这些连接之间是不同步的, 因此你的应用需要自己保证数据更新的同步 --> <bean id="memcachedClientBuilder" class="net.rubyeye.xmemcached.XMemcachedClientBuilder" p:connectionPoolSize="${memcached.connectionPoolSize}" p:failureMode="${memcached.failureMode}" p:connectTimeout="${memcached.connectTimeout}"> <!-- XMemcachedClientBuilder have two arguments.First is server list,and second is weights array. --> <!-- # 服务器节点:形如:"主节点1:port,备份节点1:port 主节点2:port,备份节点2:port"的字符串, #可以不设置备份节点,主备节点逗号隔开,不同分组空格隔开 #由于该应用功能是加载数据,可以只考虑分布式,即以空格分隔ip的配置方式,不考虑主备关系 --> <constructor-arg> <list> <bean class="java.net.InetSocketAddress"> <constructor-arg> <value>${memcached.server1.host}</value> </constructor-arg> <constructor-arg> <value>${memcached.server1.port}</value> </constructor-arg> </bean> <!-- <bean class="java.net.InetSocketAddress"> <constructor-arg> <value>${memcached.server2.host}</value> </constructor-arg> <constructor-arg> <value>${memcached.server2.port}</value> </constructor-arg> </bean> <bean class="java.net.InetSocketAddress"> <constructor-arg> <value>${memcached.server3.host}</value> </constructor-arg> <constructor-arg> <value>${memcached.server3.port}</value> </constructor-arg> </bean> --> </list> </constructor-arg> <!-- # 与servers对应的节点的权重,格式同服务器节点,权重是用来调节memcached的负载,设置的权重越高, 该memcached节点存储的数据将越多,所承受的负载越大。 --> <constructor-arg> <list> <value>${memcached.server1.weight}</value> <!-- <value>${memcached.server2.weight}</value> <value>${memcached.server3.weight}</value> --> </list> </constructor-arg> <!-- - #授权验证信息:形如: #"主节点1用户名:密码,备份节点1用户名:密码 主节点2用户名:密码,备份节点2用户名:密码"的字符串 #与服务器节点个数一致,密码不允许有空格与: #举例如:authInfo=user1:pwd1 user2:pwd2,此处的用户名密码memcached服务器主机的linux操作系统的用户名密码, 且必须被添加到可访问memcached服务用户列表中,此处使用上面配置的用户portaluser --> <property name="authInfoMap"> <map> <entry key-ref="server1"> <bean class="net.rubyeye.xmemcached.auth.AuthInfo" factory-method="typical"> <constructor-arg index="0"> <value>a2f5428b3fff4899</value> </constructor-arg> <constructor-arg index="1"> <value>HO9le5lecache</value> </constructor-arg> </bean> </entry> <!-- <entry key-ref="server2"> <bean class="net.rubyeye.xmemcached.auth.AuthInfo" factory-method="typical"> <constructor-arg index="0"> <value>>${memcached.server2.username}</value> </constructor-arg> <constructor-arg index="1"> <value>${memcached.server2.password}</value> </constructor-arg> </bean> </entry> <entry key-ref="server3"> <bean class="net.rubyeye.xmemcached.auth.AuthInfo" factory-method="typical"> <constructor-arg index="0"> <value>>${memcached.server3.username}</value> </constructor-arg> <constructor-arg index="1"> <value>${memcached.server3.password}</value> </constructor-arg> </bean> </entry> --> </map> </property> <!-- (1) 协议工厂 net.rubyeye.xmemcached.command.BinaryCommandFactory(二进制) (2) 协议工厂 net.rubyeye.xmemcached.command.TextCommandFactory(文本) (3) 协议工厂 net.rubyeye.xmemcached.command.KestrelCommandFactory(可靠获取) --> <property name="commandFactory"> <bean class="net.rubyeye.xmemcached.command.BinaryCommandFactory" /> </property> <property name="sessionLocator"> <!-- (1) net.rubyeye.xmemcached.impl.KetamaMemcachedSessionLocator 分布策略,一致性哈希(用于增加主机时降低未命中率问题的解决) (2) ArrayMemcachedSessionLocator(默认) ,默认分布的策略是按照key的哈希值模以连接数得到的余数,对应的连接就是将要存储的节点, 本应用只需使用默认策略即可。 --> <bean class="net.rubyeye.xmemcached.impl.KetamaMemcachedSessionLocator" /> </property> <!-- # 序列化转换器,默认使用net.rubyeye.xmemcached.transcoders.SerializingTranscoder --> <property name="transcoder"> <bean class="net.rubyeye.xmemcached.transcoders.SerializingTranscoder" /> </property> </bean> <!-- Use factory bean to build memcached client 当一个memcached节点down掉的时候,发往这个节点的请求将直接失败,而不是发送给下一个有效的memcached节点。 --> <bean id="memcachedClient" factory-bean="memcachedClientBuilder" factory-method="build" destroy-method="shutdown" />