import java.io.IOException;
import java.net.InetSocketAddress;
import net.spy.memcached.MemcachedClient;
public class MemMain {
public static void main(String[] args) throws IOException {
MemcachedClient c=new MemcachedClient(
new InetSocketAddress("127.0.0.1", 12000));
for(int i=1;i<10;i++){
c.set("T0001"+i, 3600, new User(i+""));
}
// Store a value (async) for one hour
// Retrieve a value (synchronously).
User myObject=(User)c.get("T00011");
System.out.println("get object from mem :"+myObject);
}
}
import java.io.Serializable;
public class User implements Serializable{
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public User(String userId) {
super();
this.userId = userId;
}
String userId;
@Override
public String toString() {
// TODO Auto-generated method stub
StringBuffer sb=new StringBuffer();
sb.append("userId="+this.userId);
return sb.toString();
}
}
import java.net.InetSocketAddress;
import net.spy.memcached.MemcachedClient;
public class MemMain {
public static void main(String[] args) throws IOException {
MemcachedClient c=new MemcachedClient(
new InetSocketAddress("127.0.0.1", 12000));
for(int i=1;i<10;i++){
c.set("T0001"+i, 3600, new User(i+""));
}
// Store a value (async) for one hour
// Retrieve a value (synchronously).
User myObject=(User)c.get("T00011");
System.out.println("get object from mem :"+myObject);
}
}
import java.io.Serializable;
public class User implements Serializable{
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public User(String userId) {
super();
this.userId = userId;
}
String userId;
@Override
public String toString() {
// TODO Auto-generated method stub
StringBuffer sb=new StringBuffer();
sb.append("userId="+this.userId);
return sb.toString();
}
}