windows 64下mamcached安装以及java测试
2016-02-18 15:15
423 查看
windows 64 环境下安装memcached
1、下载后解压到D:\memcached (下载地址:http://download.csdn.net/detail/luohaiqing123456/9435521)
2、安装到windows服务,打开cmd命令行,进入memcached目录,执行memcached -d install命令,安装服务。
如果在没有安装过的情况下,出现"failed to install service or service already installed"错误,可能是cmd.exe需要用管理员身份运行。
3、启动服务,执行memcached -d start
4、参数介绍
-p 监听的端口
-l 连接的IP地址, 默认是本机
-d start 启动memcached服务
-d restart 重起memcached服务
-d stop|shutdown 关闭正在运行的memcached服务
-d install 安装memcached服务
-d uninstall 卸载memcached服务
-u 以的身份运行 (仅在以root运行的时候有效)
-m 最大内存使用,单位MB。默认64MB
-M 内存耗尽时返回错误,而不是删除项
-c 最大同时连接数,默认是1024
-f 块大小增长因子,默认是1.25
-n 最小分配空间,key+value+flags默认是48
-h 显示帮助
5、修改参数,windows下需要通过修改注册表信息进行设置,打开注册表,找
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\memcached
在其中有一个“ImagePath”项,值为:
"D:\memcached\memcached.exe" -d runservice
在后面加上“-m 1024 -c 2048 -p 11210”。等即可。重启服务后生效
测试代码(工具包:http://download.csdn.net/detail/luohaiqing123456/9435526)
//java测试memcached类
package com.icardpay.business.manager;
import java.io.IOException;
import java.net.InetSocketAddress;
import net.spy.memcached.MemcachedClient;
public class MemCachedManager {
private static MemcachedClient client = null;
private MemCachedManager() {
try {
client = new MemcachedClient(new InetSocketAddress("127.0.0.1",11210));
} catch (IOException e) {
e.printStackTrace();
}
}
public static MemcachedClient getClient(){
if(client==null){
new MemCachedManager();
}
return client;
}
}
//实体类
package com.icardpay.business.manager;
import java.io.Serializable;
public class TBean implements Serializable {
private static final long serialVersionUID = 1945562032261336919L;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
//测试类
package com.icardpay.business.manager;
import net.spy.memcached.MemcachedClient;
import org.junit.Test;
import junit.framework.TestCase;
public class TestMemcached extends TestCase {
private static MemcachedClient cache;
@Test
public void testCache() {
cache=MemCachedManager.getClient();
//存储字符串
String key="strKey";
String value="存储字符串";
int expiration=0;
cache.set(key, expiration, value);
//取缓存中key对应的值
System.out.println("name=" +cache.get("strKey"));
//存储对象
TBean tb = new TBean();
tb.setName("存储对象");
String keyBean="bean";
int expirationBean=0;
cache.set(keyBean, expirationBean,tb);
//取缓存中对象的值
TBean tbGet=(TBean) cache.get("bean");
System.out.println("name=" +tbGet.getName());
}
}
1、下载后解压到D:\memcached (下载地址:http://download.csdn.net/detail/luohaiqing123456/9435521)
2、安装到windows服务,打开cmd命令行,进入memcached目录,执行memcached -d install命令,安装服务。
如果在没有安装过的情况下,出现"failed to install service or service already installed"错误,可能是cmd.exe需要用管理员身份运行。
3、启动服务,执行memcached -d start
4、参数介绍
-p 监听的端口
-l 连接的IP地址, 默认是本机
-d start 启动memcached服务
-d restart 重起memcached服务
-d stop|shutdown 关闭正在运行的memcached服务
-d install 安装memcached服务
-d uninstall 卸载memcached服务
-u 以的身份运行 (仅在以root运行的时候有效)
-m 最大内存使用,单位MB。默认64MB
-M 内存耗尽时返回错误,而不是删除项
-c 最大同时连接数,默认是1024
-f 块大小增长因子,默认是1.25
-n 最小分配空间,key+value+flags默认是48
-h 显示帮助
5、修改参数,windows下需要通过修改注册表信息进行设置,打开注册表,找
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\memcached
在其中有一个“ImagePath”项,值为:
"D:\memcached\memcached.exe" -d runservice
在后面加上“-m 1024 -c 2048 -p 11210”。等即可。重启服务后生效
测试代码(工具包:http://download.csdn.net/detail/luohaiqing123456/9435526)
//java测试memcached类
package com.icardpay.business.manager;
import java.io.IOException;
import java.net.InetSocketAddress;
import net.spy.memcached.MemcachedClient;
public class MemCachedManager {
private static MemcachedClient client = null;
private MemCachedManager() {
try {
client = new MemcachedClient(new InetSocketAddress("127.0.0.1",11210));
} catch (IOException e) {
e.printStackTrace();
}
}
public static MemcachedClient getClient(){
if(client==null){
new MemCachedManager();
}
return client;
}
}
//实体类
package com.icardpay.business.manager;
import java.io.Serializable;
public class TBean implements Serializable {
private static final long serialVersionUID = 1945562032261336919L;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
//测试类
package com.icardpay.business.manager;
import net.spy.memcached.MemcachedClient;
import org.junit.Test;
import junit.framework.TestCase;
public class TestMemcached extends TestCase {
private static MemcachedClient cache;
@Test
public void testCache() {
cache=MemCachedManager.getClient();
//存储字符串
String key="strKey";
String value="存储字符串";
int expiration=0;
cache.set(key, expiration, value);
//取缓存中key对应的值
System.out.println("name=" +cache.get("strKey"));
//存储对象
TBean tb = new TBean();
tb.setName("存储对象");
String keyBean="bean";
int expirationBean=0;
cache.set(keyBean, expirationBean,tb);
//取缓存中对象的值
TBean tbGet=(TBean) cache.get("bean");
System.out.println("name=" +tbGet.getName());
}
}
相关文章推荐
- MyEclipse6.5中配置web开发环境
- mark关于Java语言Static的生命周期
- RxJava 操作符分类
- Java基础 —— 数据类型
- Java集合
- java switch 异常 case expressions must be constant expressions
- eclipse导入项目出错
- Springmvc整合tiles框架简单入门示例(maven)
- Java——静态导入
- JavaSE入门学习22:Java面向对象之final关键字
- Java——List的实现类
- JAVA_JCF(Java Collection Framework)学习笔记(五)
- java类加载和初始化顺序
- eclipse安装color theme插件
- 【转】Java-----jar反编译修改重新打包
- Java IO:基于字节的IO操作
- java泛型表达式和方法工作原理小结
- Java 设计模式——静态代理模式和动态代理模式
- 从头认识Spring-2.7 自动检测Bean(3)-过滤器<context:exclude-filter/>
- MyEclipse 10 使用优化方法