Table of Contents

22.10.1 Excursus: Memcached server - installation and test

If you want to test the gb.memcached component - which provides you with a Memcached client - then you need the Memcached server (MCS) on your system.

22.10.1.1 Installing the Memcached server

You can find a detailed description of the Memcached server protocol on the following websites

https://github.com/memcached/memcached/blob/master/doc/protocol.txt

The Memcached server can be installed via the application management or you can enter the following lines in a terminal:

  $ sudo apt-get update
  $ sudo apt-get upgrade
  $ sudo apt-get install memcached 

22.10.1.2 Memcached server status and Memcached server control

This is how you determine the status of the Memcached server, as the Memcached server is started immediately after installation and listens on the (standard) port 11211:

  $ service memcached status			
  or
  $ /etc/init.d/memcached status

Output in a console:

hans@mint20:~$ service memcached status
● memcached.service - memcached daemon
     Loaded: loaded (/lib/systemd/system/memcached.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-03-23 11:53:29 CET; 33min ago
       Docs: man:memcached(1)
   Main PID: 4900 (memcached)
      Tasks: 10 (limit: 18941)
     Memory: 2.0M
     CGroup: /system.slice/memcached.service
             └─4900 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1 -P /var/run/memcached/memcached.pid

Mär 23 11:53:29 mint20 systemd[1]: Started memcached daemon.

Generally applies to the controller:

  $ /etc/init.d/memcached {start|stop|restart|force-reload|status}  
  or
  $ service memcached {start|stop|restart|force-reload|status}

If you are constantly working with the Memcached server, it is worth creating starters on the desktop for selected actions such as starting or stopping; the default configuration does not normally need to be changed. The configuration file can be found here:

/etc/memcached.conf

and log files there:

/var/log/memcached.log

22.10.2 Memcached server - 1st test

For an initial test, which should also show you the basic operation of the MC-Server and MC-Client, you can use the telnet programme as a Memcached client - with the IP address 127.0.0.1 and port 11211.

The following concept should be implemented:

Console:

# telnet hostname/ip port
hans@mint20:~$ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
# version
version
VERSION 1.5.22
# set key_name meta_data expiry_time_in_seconds length_in_bytes
set TESTKEY 0 100 8 # + ENTER
MINISINI
STORED
# get key_name
get TESTKEY
VALUE TESTKEY 0 8
MINISINI
END
# replace key_name meta_data expiry_time_in_seconds length_in_bytes
replace TESTKEY 0 100 9
GIANLUIGI
STORED
# delete key_name
delete TESTKEY
DELETED
# stats
stats
STAT pid 4900
STAT uptime 9032
STAT time 1616505839
STAT version 1.5.22
...
STAT direct_reclaims 0
STAT lru_bumps_dropped 0
END
# flush_all
flush_all
OK
# quit
quit
Connection closed by foreign host.
hans@mint20:~$ 

Overview of selected messages of the MC server:

22.10.3 Memcached server - 2nd test

The Memcached server only shows its strengths when you save the data to be saved in a modified form.

# telnet hostname/ip port
hans@mint20:~$ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
# set key_name meta_data expiry_time_in_seconds length_in_bytes
set TestKey 0 100 6 # ENTER
Gambas
STORED
# get key_name
get TestKey
VALUE TestKey 0 6
Gambas
END
# replace key_name meta_data expiry_time_in_seconds length_in_bytes
replace TestKey 0 100 13
Gambas 3.15.2
STORED
# delete key_name
delete TestKey
DELETED
# stats
stats
STAT pid 4900
STAT uptime 9032
STAT time 1616505839
STAT version 1.5.22
...
STAT direct_reclaims 0
STAT lru_bumps_dropped 0
END
# flush_all
flush_all
OK
# quit
quit
Connection closed by foreign host.
hans@mint20:~$ 

Whether Memcached is the best option as a caching solution depends on the requirements and complexity of the respective application. The temporary storage system is particularly useful for web applications with high traffic and pages that access huge databases, for example.