一般情况下,我们用linux作为生产环境,但是开发还是在windows下面,所以我们需要 win版本。。但是memcache官方网站只提供了源码。
下面介绍使用第三方编译的win版本的方法:
这是一个由Kenneth Dalgleish基于Kronuz的1.2.1构建。官方的memcached的团队不对这个版本支持!
核心关键在这个:
http://splinedancer.com/memcached-win32/
memcached for Windows
This is a port of memcached to the win32 architecture by Kenneth Dalgleish, based on Kronuz's 1.2.1 port. This port is not supported by the official memcached team.
Install
The win32 version of memcached can be run both as a NT Service or from the command line. To install memcached as a service, follow the next steps:
- Unzip the binaries in your desired directory (eg. c:\memcached)
- Install the service using the command: 'c:\memcached\memcached.exe -d install' from the command line
- Start the server from the Microsoft Management Console or by running the following command: 'c:\memcached\memcached.exe -d start'
- Use the server, by default listening to port 11211
Building from source
To build from source, you will need Visual Studio 2005 (any edition with C++ should work), Windows SDK (eg.
Windows SDK for Windows Server 2008 and .NET Framework 3.5) and
libevent (win32 binary provided on this page).
- Install Visual Studio 2005
- Install Windows SDK
- Put libevent.lib in Win32-Prj/ folder
- Open solution file and it should build
Downloads
memcached 1.2.4 Win32 Beta
Libevent 1.3e Win32
(Needed if building from source)
Windows下Memcache安装
1、下载memcache for windows。下载地址:http://splinedancer.com/memcached-win32/,解压到d:\memcached。
2、在命令行状态下输入: d:\memcached\memcached.exe -d install 。至此memcached已经安装成windows服务
3、在命令行下输入: d:\memcached\memcached.exe -d start 以启动memcached服务。当然也可以选择在windows服务中启动
就是这么简单,简简单单的三步memcache的服务器端就准备完毕
配置PHP
1、下载php_memcache.dll扩展,下载地址:http://www.php100.com/html/download/server/2010/0125/3858.html,如果你已经拥有php_memcache.dll请略过这一步。
2、在php.ini中添加一行:”extension=php_memcache.dll” 。如果已经存在这一行就把前面的分号去掉
3、重启Apache使用phpinfo()查看,若有memcache相关则证明安装成功
memcached的基本设置:
-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 显示帮助
Memcache环境测试:
运行下面的php文件,如果有输出This is a value!,就表示环境搭建成功。开始领略Memcache的魅力把!
<?php
$mem = new Memcache;
$mem->connect("127.0.0.1", 11211);
$mem->set('key', 'This is a value!', 0, 60);
$val = $mem->get('key');
echo $val;
JAVA下的安装:
2.从https://github.com/gwhalin/Memcached-Java-Client下载Memcached相关的jar包。
测试程序:
import com.danga.MemCached.MemCachedClient;
import com.danga.MemCached.SockIOPool;
public class MemCachedTest {
private static MemCachedClient mcc = new MemCachedClient();
static {
String[] servers = {"192.168.123.100:11211"};
//创建一个连接池
SockIOPool pool = SockIOPool.getInstance();
//设置缓存服务器
pool.setServers(servers);
//设置初始化连接数,最小连接数,最大连接数以及最大处理时间
pool.setInitConn(50);
pool.setMinConn(50);
pool.setMaxConn(500);
pool.setMaxIdle(1000 * 60 * 60);
//设置主线程睡眠时间,每30秒苏醒一次,维持连接池大小
pool.setMaintSleep(30);
//关闭套接字缓存
pool.setNagle(false);
//连接建立后的超时时间
pool.setSocketTO(3000);
//连接建立时的超时时间
pool.setSocketConnectTO(0);
//初始化连接池
pool.initialize();
}
protected MemCachedTest(){
}
public static MemCachedClient getInstance(){
return mcc;
}
public static void main(String[] args) {
MemCachedClient mcc= MemCachedTest.getInstance();
for ( int i = 0; i < 10; i++ ) {
boolean success = mcc.set( "" + i, "Hello!" );
String result = (String)mcc.get( "" + i );
System.out.println( String.format( "set( %d ): %s", i, success ) );
System.out.println( String.format( "get( %d ): %s", i, result ) );
}
System.out.println( "\n\t -- sleeping --\n" );
try { Thread.sleep( 100000 ); } catch ( Exception ex ) { }
for ( int i = 0; i < 10; i++ ) {
boolean success = mcc.set( "" + i, "Hello!" );
String result = (String)mcc.get( "" + i );
System.out.println( String.format( "set( %d ): %s", i, success ) );
System.out.println( String.format( "get( %d ): %s", i, result ) );
}
}
}
参考资料:
对Memcached有疑问的朋友可以参考下列文章:
Linux下的Memcache安装:http://www.ccvita.com/257.html
Windows下的Memcache安装:http://www.ccvita.com/258.html
Memcache基础教程:http://www.ccvita.com/259.html
Discuz!的Memcache缓存实现:http://www.ccvita.com/261.html
Memcache协议中文版:http://www.ccvita.com/306.html
Memcache分布式部署方案:http://www.ccvita.com/395.html
本例的代码经过本人亲自测试!!
分享到:
相关推荐
Memcached服务器(windows版本和Windows server版本)
由windows 的Cygwin编译的版本,可以直接使用,随下随用
在终端(也即cmd命令界面)下输入 ‘c:\memcached\memcached.exe -d install’ 安装 3. 再输入: ‘c:\memcached\memcached.exe -d start’ 启动。NOTE: 以后memcached将作为windows的一个服务每次开机时自动启动...
1、memcache windows x64,x86 ; 2、自带bat脚本(memcached 1.5后的版本好象不支持用服务的方式启动了)。
memcached 1.26 windows 版 配合bat命令控制台使用 强大,你懂的
将这个压缩包解压,就出来一个“鹿头”的memcached.exe文件,没错!就是它了。运行它,会出现一个窗口,这个窗口一直打开着就说明memcached的服务端就一直运行着,那么它就能接收客户端的请求
安装Memcached及Memcached配置
NULL 博文链接:https://geeklee.iteye.com/blog/1607632
memcached缓存安装使用说明,包含windows和linux的安装和使用 集群
1、解压下载的安装包到指定目录 2、在 1.4.5 版本以前 memcached 可以作为一个服务安装,使用管理员权限运行以下命令: 3、然后我们可以使用以下命
Memcached的windows版本安装包,压缩包中有32位和64位两个版本,根据需要下载使用。 Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载。它通过在内存中缓存数据和对象来减少读取...
Memcached的安装步骤: 1.下载memcached的windows稳定版,解压放某个盘下面,比如在c:\memcached 2.在终端(也即cmd命令界面)下输入'c:\memcached\memcached.exe -d install'安装 3.再输入:'c:\memcached\...
memcached_windows 版安装文件memcached_windows 版安装文件memcached_windows 版安装文件memcached_windows 版安装文件
包括32位和64位的Windows版本,是编译好的exe文件。 注意的是从1.4.5版本以后不能作为系统服务启动,开机请用bat启动
在windows下安装memcached时,下了很多资源,很多都不能用或者不确定当前版本是否与本地php版本相对应。于是就整了份完整资料,给有需要的人。本地php是5.3版本的,所以压缩包里放了memcached 2.2.6版的...
已成功在本机安装成功。比其他安装更详细。
Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载。它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态、数据库驱动网站的速度。Memcached基于一个存储键/值对的...
memcached安装软件 libevent-2.0.21-stable.tar.gz magent.tar.gz memcached-1.4.15.tar.gz
Memcached是一个自由开源的,高性能,分布式内存对象缓存系统
memcached windows xp 的稳定版