• Memcached(一)在Windows上安装和测试memcached


    1)下载memcached的windows安装程序

        memcached-1.2.4-Win32-Preview-20080309_bin.zip 或其他版本

    2)解压memcached  用管理员身份运行cmd.exe cd到解压目录下 执行 memcached.exe -d install   安装memcached

    3)启动memcached   memcached.exe -d start  

    然后测试程序

    package com.guowuxin.memcached; 
     
    import java.io.IOException; 
    import java.net.InetSocketAddress; 
     
    import net.spy.memcached.MemcachedClient; 
     
    public class TestMemcached { 
        public static void main(String[] args) throws IOException { 
            MemcachedClient cache = new MemcachedClient(new InetSocketAddress("127.0.0.1", 11211));
            System.out.println("Connect success");
            for (int i = 1; i < 10; i++) { 
                cache.set("guowuxin" + i, 3600, new User(i + "","guowuxin","guowuxin"));  
            } 
            System.out.println("insert success");
            User myObject = (User) cache.get("guowuxin1"); 
            System.out.println("Get object from mem :" + myObject);  
        }  
    } 
    
    package com.guowuxin.memcached; 
     
    import java.io.Serializable; 
     
     
    public class User implements Serializable{  
     
        private static final long serialVersionUID = -372274003834027815L; 
     
        private String userId; 
         
        private String username;
        
        private String password;
        
        public User(final String userId,final String username,final String password) {  
            super();  
            this.userId = userId;  
            this.username = username;
            this.password = password;
        } 
         
        public String getUserId() {  
            return userId;  
        }  
         
        public void setUserId(String userId) {  
            this.userId = userId;  
        }  
             
        public String getUsername() {
    		return username;
    	}
    
    	public void setUsername(String username) {
    		this.username = username;
    	}
    
    	public String getPassword() {
    		return password;
    	}
    
    	public void setPassword(String password) {
    		this.password = password;
    	}
    
    	@Override  
        public String toString() {  
            StringBuffer sb=new StringBuffer();  
            sb.append("userId="+this.userId); 
            sb.append("&username="+this.username); 
            sb.append("&password="+this.password); 
            return sb.toString();  
        }  
    }  
    

      

    2016-02-25 15:26:17.110 INFO net.spy.memcached.MemcachedConnection: Added {QA sa=/127.0.0.1:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
    Connect success
    2016-02-25 15:26:17.113 INFO net.spy.memcached.MemcachedConnection: Connection state changed for sun.nio.ch.SelectionKeyImpl@fa9cf
    insert success
    Get object from mem :userId=1&username=guowuxin&password=guowuxin

  • 相关阅读:
    ubuntu16.04 下安装opencv2.4.9
    ubuntu16.04下CMake学习
    Ubuntu 16.04上用CMake图形界面交叉编译树莓派的OpenCV3.0
    BMP图片的C++水印算法
    OpenCV 2 学习笔记(9): 定义ROI(regions of interest):给图像加入水印
    OpenCV入门教程
    免费、高性能的人脸检测库(二进制)
    DBCP与C3P0数据库连接池
    (android高仿系列)今日头条 --新闻阅读器 (三) 完结 、总结 篇
    hadoop之WordCount源代码分析
  • 原文地址:https://www.cnblogs.com/wuxinliulei/p/5217148.html
Copyright © 2020-2023  润新知