Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java by Spy Memcached to cache data     - Upgrading to MySQL 5.7 partitioning problem solving (Database)

- How to Install Redis server on CentOS 7 (Server)

- CentOS 6.5 makes the LAN http source (Linux)

- Tmux Crash Course: Tips and adjustment (Linux)

- Linux System Getting Started Learning: Using yum to download the RPM package without installing (Linux)

- Use Visual Studio to compile and use WinGDB remote debugging embedded Linux programs (Programming)

- Python virtual environment: Virtualenv (Linux)

- How nodeclub constructed Docker image (Server)

- Depth understanding of the use of Spring Redis (Programming)

- Linux common network tools: batch scanning of nmap hosting service (Linux)

- ORA-00020: No more process state objects available (Database)

- Based Corosync + Pacemaker + DRBD + LNMP Web server to achieve high availability cluster (Server)

- Memcached installation, configuration and monitoring (Server)

- Ubuntu under VirtualBox virtual machine serial port settings (Linux)

- Use FirewallD build dynamic firewall (Linux)

- Java development environment to build under Ubuntu (Linux)

- Ubuntu 12.04 commonly use shortcuts finishing Share (Linux)

- VMware virtual machine Ubuntu install arm-linux-gcc cross-compiler environment (Linux)

- Java call by value and by reference (Programming)

- Oracle11g build physical standby database (Database)

 
         
  Java by Spy Memcached to cache data
     
  Add Date : 2018-11-21      
         
         
         
  After configuring Magent + memcached, input and output of data between the obvious is through a proxy server, magent proxy server is doing is evident in memecached call java driver magent apply.

Pick SpyMemcached to cache data.

1. Define a User

Note: The type must be serialized

package memdemo;

import java.io.Serializable;

public class User implements Serializable {

/ **

    *

    * /

    private static final long serialVersionUID = 1L;

private int id;

private String name;

private int age;

public int getId () {

    return id;

}

public void setId (int id) {

    this.id = id;

}

public String getName () {

    return name;

}

public void setName (String name) {

    this.name = name;

}

public int getAge () {

    return age;

}

public void setAge (int age) {

    this.age = age;

}

@Override

public String toString () {

    return "User [id =" + id + ", name =" + name + ", age =" + age + "]";

}

}

2. Write a test class


package memdemo;

 

import java.io.IOException;

import java.net.InetSocketAddress;

 

import org.junit.Test;

 

import net.spy.memcached.MemcachedClient;

 

public class SpyMemcachedTest {

private static MemcachedClient client;

static {

    InetSocketAddress ia = new InetSocketAddress ( "127.0.0.1", 2222);

    try {

        client = new MemcachedClient (ia);

    } Catch (IOException e) {

        // TODO Auto-generated catch block

        e.printStackTrace ();

    }

}

@Test

public void add () {

    client.add ( "swder", 1, "maybo");

    System.out.println (client.get ( "swder") toString ().);

}

@Test

public void addUser () {

    User user = new User ();

    user.setAge (23);

    user.setId (1);

    user.setName ( "maybo");

    //client.add("user123 ", 0, user);

    System.out.println (client.get ( "user123") toString ().);

}

}
     
         
         
         
  More:      
 
- SQLite (Database)
- Getting Started with Linux system to learn: how to get the process ID (PID) in the script (Linux)
- Linux crontab commands and detailed usage examples (Linux)
- VirtualBox virtual machine to install Linux (Linux)
- FPM quickly create packages with RPM (Linux)
- Ubuntu 15.04 / 14.04 install Ubuntu After Install 2.6 (Linux)
- Install Jetty on CentOS / RHEL 6.X (Server)
- Linux process management related content (Linux)
- Linux log management tools Logrotate (Linux)
- Linux, C programming language library file handling and preparation of Makefile (Programming)
- Use HttpClient remote interface testing (Programming)
- Linux package manager - yum (Linux)
- Understand the profound discussion of some of the options for wireless encryption (Linux)
- You can not ignore the seven Git tips (Linux)
- extundelete: the Linux-based open source data recovery tools (Linux)
- Java MD5 encryption implementation (Programming)
- Three strategies to teach you to release the device memory (Linux)
- How to convert images, audio and video formats on Ubuntu (Linux)
- PHP 7.0 Upgrade Notes (Linux)
- Ubuntu system grub repair method (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.