Memcached for windows 简单介绍_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > Memcached for windows 简单介绍

Memcached for windows 简单介绍

 2015/3/13 18:27:06  antlove  程序员俱乐部  我要评论(0)
  • 摘要:1.安装memcachedservera.下载memcached-1.2.6-win32-bin.zipb.解压缩,dos窗口切换到memcached.exe所在目录,运行memcached.exe-dinstallc.启动memcachedServer,直接在dos窗口键入netstart"memcachedServer"(也可在windows服务列表中手动启动)2.memchachedclientmemcached.People.javapackagememcached
  • 标签:Windows for

1. 安装memcached server

a. 下载memcached-1.2.6-win32-bin.zip

b. 解压缩dos 窗口切换到?memcached.exe所在目录,运行memcached.exe -d install

c.启动memcached Server,直接在dos窗口键入?net start "memcached Server" (也可在windows服务列表中手动启动)

?

2. memchached client?

memcached.People.java

class="java">package memcached;

import java.io.Serializable;

/**
 * Created by Administrator on 2015/3/13.
 */
public class People implements Serializable {
    private String id;
    private String name;

    public People() {}

    public People(String id, String name) {
        this.id = id;
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "People{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                '}';
    }
}

?

memcached.Main.java

package memcached;

import net.rubyeye.xmemcached.MemcachedClient;
import net.rubyeye.xmemcached.XMemcachedClient;
import net.rubyeye.xmemcached.XMemcachedClientBuilder;
import net.rubyeye.xmemcached.exception.MemcachedException;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeoutException;

/**
 * Created by Administrator on 2015/3/13.
 */
public class Main {
    public static void main(String[] args) throws Exception {
        List<InetSocketAddress> addresses = new ArrayList<InetSocketAddress>();
        InetSocketAddress inetSocketAddress = new InetSocketAddress("localhost",11211);
        addresses.add(inetSocketAddress);
        XMemcachedClientBuilder memcachedClientBuilder = new XMemcachedClientBuilder(addresses);
        MemcachedClient memcachedClient = memcachedClientBuilder.build();

        String key = "lidabiao";

        // delete value
        System.out.println("--------------------------------- delete value---------------------------------");
        memcachedClient.delete(key);
        System.out.println(memcachedClient.get(key));

        // add value
        System.out.println("--------------------------------- add value---------------------------------");
        memcachedClient.add(key, 1000, "nihaome");
        System.out.println(memcachedClient.get(key));

        // append value
        System.out.println("--------------------------------- append value---------------------------------");
        memcachedClient.append(key,new People("001","二狗子"));
        System.out.println(memcachedClient.get(key));

        // replace value
        System.out.println("--------------------------------- replace value---------------------------------");
        memcachedClient.replace(key,100,"赵三");
        System.out.println(memcachedClient.get(key));

        memcachedClient.shutdown();

    }
}

?

pom.xml

<dependencies>
	<dependency>
		<groupId>org.slf4j</groupId>
		<artifactId>slf4j-log4j12</artifactId>
		<version>1.5.6</version>
	</dependency>

	<!--=========================== memcached =========================== -->
	<dependency>
		<groupId>com.googlecode.xmemcached</groupId>
		<artifactId>xmemcached</artifactId>
		<version>1.3.6</version>
	</dependency>
</dependencies>

?

? ??

  • memcached-1.2.6-win32-bin.zip (36 KB)
  • 下载次数: 0
发表评论
用户名: 匿名