CentOS安装卸载memcache及JAVA示例
lrwxrwxrwx 1 root root 21 Jan 14 17:47 libevent-1.2.so.1 -> libevent-1.2.so.1.0.3
-rwxr-xr-x 1 root root 264056 Jan 14 17:47 libevent-1.2.so.1.0.3
-rw-r--r-- 1 root root 430396 Jan 14 17:47 libevent.a
-rwxr-xr-x 1 root root 814 Jan 14 17:47 libevent.la
lrwxrwxrwx 1 root root 21 Jan 14 17:47 libevent.so -> libevent-1.2.so.1.0.3
-rwxr-xr-x 1 root root 113188 Jan 14 17:51 /usr/local/bin/memcached
-rwxr-xr-x 1 root root 117535 Jan 14 17:51 /usr/local/bin/memcached-debug
#设置服务器地址
memcached.server=目标服务器ip:11211 #该端口号默认为11211
#容错
memcached.failOver=true
#设置初始连接数
memcached.initConn=20
#设置最小连接数
memcached.minConn=10
#设置最大连接数
memcached.maxConn=250
#设置连接池维护线程的睡眠时间
memcached.maintSleep=3000
#设置是否使用Nagle算法(Socket的参数),如果是true在写数据时不缓冲,立即发送出去
memcached.nagle=false
#设置socket的读取等待超时时间
memcached.socketTO=3000
#设置连接心跳监测开关
memcached.aliveCheck=true
# killall memcached
2.删除memcached目录及文件
# rm -rf /usr/local/memcached
# rm -f /etc/rc.d/init.d/memcached
3.关闭memcached开机启动
# chkconfig memcached off
4.把memcached移出开机启动
# chkconfig --del memcached
/usr/local/bin/memcached: error while loading shared libraries: libevent-1.2.so.1: cannot open shared object file: No such file or directory
<bean id="testCached" class="com.danga.MemCached.MemCachedClient">
<constructor-arg><value>neeaMemcachedPoolUserLogin</value></constructor-arg>
</bean>
<bean id="memcachedPooluserLogin" class="com.danga.MemCached.SockIOPool" factory-method="getInstance"
init-method="initialize" destroy-method="shutDown">
<constructor-arg><value>neeaMemcachedPoolUserLogin</value></constructor-arg>
<property name="servers">
<list>
<value>127.0.0.1:11211</value>
</list>
</property>
<property name="initConn"><value>20</value></property>
<property name="minConn"><value>10</value></property>
<property name="maxConn"><value>800</value></property>
<property name="maintSleep"><value>30</value></property>
<property name="nagle"><value>false</value></property>
<property name="socketTO"><value>3000</value></property>
</bean>
@Component
public class SysCacheHelper {
@Autowired
@Qualifier("testCached")
private MemCachedClient cache;
public boolean setSysCache(int categoryId, TSysConfig sysConfig){
return cache.set(Constants.SYS_PREFIX + categoryId, sysConfig, LoginedCacheHelper.get3DayCalendarTime(Constants.SYS_CACHE_EXPIRED_DAY));
}
public TSysConfig getSysCache(int categoryId){
return (TSysConfig)cache.get(Constants.SYS_PREFIX + categoryId);
}
public boolean removeSysCache(int categoryId){
return cache.delete(Constants.SYS_PREFIX + categoryId);
}
}
可以调用方法查看memcached中的内容。
示例代码只是摘录重要片段。