Memcached list all keys – How we do this on a telnet session?
The Memcached list all keys option gives an insight into the cache server contents.
Caching systems like Memcached store its keys in slabs. And, website owners tweak settings based on the available data.
At Bobcares, users often approach us with queries regarding Memcached keys, as a part of our Server Management Services.
Today, let’s see have a look at Memcached and see how our Support Engineers list the keys in a telnet session.
What is Memcached?
Memcached is an open-source, high-performance, memory caching system. We use it to speed up dynamic web applications by reducing the database load. The Memcached server is a big hash table suitable for websites with high database load.
Before listing the keys, let’s have a closer look at Memcached. We can connect to the Memcached server using the telnet command,
telnet <HOST> <PORT>
A key is a name used to store and retrieve data from Memcached. We can manage data using several commands like set, add, replace, append, etc.
Additionally, the stats command gives the server statics regarding the items, slabs, etc.
How to list keys in Memcached?
Now let’s see how our Support Engineers list all the keys in Memcached.
To list the keys first we telnet to the Memcached server. Here localhost is the Memcached server. So we connect to it as,
telnet localhost 11211
Then we need slab IDs to list the keys. There are two ways to obtain the slab ID. Firstly, we list the items using the command,
And the output appears as,
stats items STAT items:1:number 2 STAT items:1:age 92 STAT items:1:evicted 0 STAT items:1:evicted_nonzero 0 . . . END
Here the value after STAT items is the slab ID, which is ‘1’.
Alternatively, we can obtain the slab ID using the command,
And the result appears as,
stats slabs STAT 1:chunk_size 96 STAT 1:chunks_per_page 10922 STAT 1:total_pages 1 STAT 1:total_chunks 10922 STAT 1:used_chunks 2 . . . END
Here the value after STAT is the slab ID, that is ‘1’.
Later we can list the keys in the slab using the slab ID. For this, we use the command,
stats cachedump slab_ID number_of_items_to_list
But the value ‘0’ indicates all items. The sample output of this appears as,
This way we listed the keys in Memcached.
[Are you still having trouble setting up Memcached? – Our Experts are available 24/7.]
In short, to list all keys in Memcached, we obtain the slab ID then list the keys using stats cachedump command. Today, we saw how our Support Engineers do this.