当前位置:首页 > 开发 > 互联网 > 正文

Memcached for windows 简单介绍

发表于: 2015-03-13   作者:antlove   来源:转载   浏览:
摘要: 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&quo

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

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 for windows 简单介绍

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
原文参考 :http://elf8848.iteye.com/blog/2093463 一、协议 memcached的客户端使用TCP连接同memca
一、MemCached是什么? MemCached是一个免费、开源、高性能、分布式、基于内存的对象缓存系统。一般
一、MemCached是什么? MemCached是一个免费、开源、高性能、分布式、基于内存的对象缓存系统。一般
memcached是高性能的分布式内存缓存服务器。 一般的使用目的是,通过缓存数据库查询结果,减少数据
Windows2008修改密码策略简单介绍 Windows的密码策略,确实是挺繁琐的,刚接触SharePoint2010,装的
在我们调试比较复杂的程序的时候,尤其是多个dll,多线程的情况下debug有时候不是很方便。debugview
面临的问题 对于高并发高访问的Web应用程序来说,数据库存取瓶颈一直是个令人头疼的问题。特别当你
Memcached常用命令及使用说明 一、存储命令 存储命令的格式: 1 2 <command name> <key>
一、下载Memercached For Windows 二、安装步骤 1、解压到指定目录,如:C:\Memcached\memcached-wi
  Memcached是一个高并发的内存键值对缓存系统,它的主要作用是将数据库查询结果,内容,以及其它
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号