现在的位置: 首页 > 综合 > 正文

memcached学习 windows安装

2013年10月24日 ⁄ 综合 ⁄ 共 4117字 ⁄ 字号 评论关闭
文章目录

 

Memcached介绍:
Memcached是高性能的,分布式的内存对象缓存系统,用于在动态应用中减少数据库负载,提升访问速度。Memcached由Danga Interactive开发,用于提升LiveJournal.com访问速度的。LJ每秒动态页面访问量几千次,用户700万。Memcached将数据库负载大幅度降低,更好的分配资源,更快速访问。
svn:http://code.sixapart.com/svn/memcached/trunk/

Memcache工作原理:

首先 memcached 是以守护程序方式运行于一个或多个服务器中,随时接受客户端的连接操作,客户端可以由各种语言编写,目前已知的客户端 API 包括 Perl/PHP/Python/Ruby/Java/C#/C 等等。客户端在与 memcached 服务建立连接之后,接下来的事情就是存取对象了,每个被存取的对象都有一个唯一的标识符 key,存取操作均通过这个 key 进行,保存到 memcached 中的对象实际上是放置内存中的,并不是保存在 cache 文件中的,这也是为什么 memcached 能够如此高效快速的原因。注意,这些对象并不是持久的,服务停止之后,里边的数据就会丢失。

 

与许多 cache 工具类似,Memcached 的原理并不复杂。它采用了C/S的模式,在 server 端启动服务进程,在启动时可以指定监听的 ip,自己的端口号,所使用的内存大小等几个关键参数。一旦启动,服务就一直处于可用状态。Memcached 的目前版本是通过C实现,采用了单进程,单线程,异步I/O,基于事件 (event_based) 的服务方式.使用 libevent 作为事件通知实现。多个 Server 可以协同工作,但这些 Server 之间是没有任何通讯联系的,每个 Server 只是对自己的数据进行管理。Client 端通过指定 Server 端的 ip 地址(通过域名应该也可以)。需要缓存的对象或数据是以 key->value 对的形式保存在Server端。key 的值通过 hash 进行转换,根据 hash 值把 value传递到对应的具体的某个 Server 上。当需要获取对象数据时,也根据 key 进行。首先对 key 进行 hash,通过获得的值可以确定它被保存在了哪台 Server 上,然后再向该 Server 发出请求。Client 端只需要知道保存 hash(key) 的值在哪台服务器上就可以了。

 

        其实说到底,memcache 的工作就是在专门的机器的内存里维护一张巨大的 hash 表,来存储经常被读写的一些数组与文件,从而极大的提高网站的运行效率。

 

 

Memcached Users

 

安装过程如下:
  1. 下载 windows 下的 memcache 服务端
  2. 解压到任意目录
    • 安装: x:/memcached/memcached -d install
    • 启动: x:/memcached/memcached -d start
    • 停止: x:/memcached/memcached -d stop
    • 重启: x:/memcached/memcached -d restart
    • 帮助: x:/memcached/memcached -h
  3. 安装成功, 用下面的代码测试一下 :D

 

memcache 服务端页面内容如下:

 

This is a port of memcached to the win32 architecture by Kronuz
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:

  1. Unzip the binaries in your desired directory (eg. c:/memcached)
  2. Install the service using the command: 'c:/memcached/memcached.exe -d install' from either the command line
  3. Start the server from the Microsoft Management Console or by running the following command: 'c:/memcached/memcached.exe -d start'
  4. Use the server, by default listening to port 11211

Use 'memcached.exe -h' for extra help and command line server
You can check the ChangeLog to see what's new.

Old files:

 

 

示例代码:

 

 

 

抱歉!评论已关闭.