Memcached分布式Cache的简单测试

服务器端安装:

 

 

1. 下载win32 版本

 memcached-1.2.1-win32.zip

 

 下载memcache的windows稳定版,解压放在c:/memcached
2. 在终端下输入 'c:/memcached/memcached.exe -d install' 安装
3. 在终端下输入   'c:/memcached/memcached.exe -d start' 启动

 


NOTE: 以后memcached将作为windows的一个服务每次开机时自动启动。

 

 

 

客户端测试:

 

 

下载java client端jar包

 

 

测试代码如下:

 

 

/**
 * MemCached Java client
 * Copyright (c) 2007 Greg Whalin
 * All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the BSD license
 *
 * This library is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.
 *
 * You should have received a copy of the BSD License along with this
 * library.
 *
 * @author greg whalin <greg@meetup.com>
 * @version 1.5.2
 */
package com.danga.MemCached.test;

import com.danga.MemCached.*;
import org.apache.log4j.*;

public class Test  { 
 public static void main(String[] args) {
        // memcached should be running on port 11211 but NOT on 11212

  BasicConfigurator.configure();
  //String[] servers = { "192.168.1.14:11211", "192.168.1.14:11211" };
  String[] servers = { "127.0.0.1:11211" };
  SockIOPool pool = SockIOPool.getInstance();
  pool.setServers( servers );
  pool.setFailover( true );
  pool.setInitConn( 10 );
  pool.setMinConn( 5 );
  pool.setMaxConn( 250 );
  pool.setMaintSleep( 30 );
  pool.setNagle( false );
  pool.setSocketTO( 3000 );
  pool.setAliveCheck( true );
  pool.initialize();

  MemCachedClient memCachedClient = new MemCachedClient();


  
  boolean success1 = memCachedClient.set( "test", "aspboy2009!" );
  System.out.println( (String)memCachedClient.get("test") );
  
  boolean success2 = memCachedClient.set( "k1", "k1value!" );
  System.out.println( (String)memCachedClient.get("k1") );
  
  boolean success3 = memCachedClient.set( "k2", "k2value!" );
  System.out.println( (String)memCachedClient.get("k2") );
  
  
  memCachedClient.statsSlabs();
  memCachedClient.stats();
  
  //memCachedClient.delete("k1");
  
  //memCachedClient.replace("k3", "kkkkk333");
  
 }
}


 

 

上一篇:在 Windows Server 2003 中重置目录服务还原模式的管理员帐户密码


下一篇:中文字体网页开发指南