Javatpoint Logo
Javatpoint Logo

Example in Ubuntu

We can connect to our memcached server in a variety of ways. Here, we will use a Telnet client to connect to the server directly.

For this, type the following command in terminal:

Here, HOST is machine IP and PORT is port number respectively, on which the memcached server is executing.

For Example:

Memcached - Example in Ubuntu

Example:

Let's see an example for simple set and get command.

Memcached - Example in Ubuntu

Example in Windows

In Windows OS, first of all we have to start the memcached server. To start the memcached server, follow the previous chapter. Then connect to our memcached server through telnet.

Let's connect to the memcached server through the following command:

Here, HOST is machine IP and PORT is port number respectively, on which the memcached server is executing.

For Example:

Memcached - Example in Windows

Here, telnet 127.0.0.1 11211 assuming the memcached server is running on the same machine and listening on the default 11211 port.

When you press enter, the following telnet client window will open:

Memcached - Example in Windows

Your memcached service should now run and wait incoming key or value pairs.

Example:

Let's see an example for simple set and get command.

Memcached - Example in Windows

Connection from Java Application

To connect to the memcached server from your java program, we need to add the memcached jar into our classpath. Go to this link https://code.google.com/archive/p/spymemcached/downloads and download the latest version of memcached jar. Here, I will use spymemcached-2.10.3-sources.jar file.

Consider that memcached server is running on host 127.0.0.1and port 11211.

Example:

Output:

Connection to server successfully
set status:true
Get from Cache:memcached.





Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA