Chat to memcached by
“memcached-cli”
@key_amb
In Gotanda.pm #8
Slide 2
Slide 2 text
Who am I ?
❏ @key_amb
❏ Software Engineer
❏ Serverside, Web
❏ https://github.com/key-amb
❏ https://metacpan.org/author/KEYAMB
Slide 3
Slide 3 text
Overview of “memcached-cli”
❏ https://github.com/key-amb/perl5-App-
Memcached-CLI
❏ `cpanm App::Memcached::CLI` to install
❏ Interactive and Batch interface
❏ Based on Memcached Text Protocol
❏ Covers ALL commands described in
memcached/protocol.txt
❏ And More!
Slide 4
Slide 4 text
Motivation
● Do you remember how to “set” a data into
Memcached?
● Do you know the way to investigate when
there are evictions on Memcached?
Slide 5
Slide 5 text
“set” by telnet is difficult
% telnet localhost 11211
...Escape character is ‘^]’
set foo 0 0 3
Foo
STORED
get foo
VALUE foo 0 3
Foo
END
Slide 6
Slide 6 text
When evictions detected
1. `memcached-tool SERVER:PORT` to check
in which class evictions are.
2. `stats cachedump CLASS NUM` via telnet to
see keys and expiration time
3. `get KEY` to see data value
4. And so on.
… Needs some efforts.
Slide 7
Slide 7 text
In “memcached-cli”
● Interactive, friendly Interface.
● So powerfull that it covers most commands
of Memcached.
● Useful features for Ops and Admin.
Slide 8
Slide 8 text
Run “memcached-cli”
// Interactive Mode
% memcached-cli [localhost]
Type '\h' or 'help' to show help.
[email protected]:11211> \q // quit
// Batch mode
% memcached-cli get foo bar
Key:foo Value:Foo Length:3B Flags:0
Key:bar Value:Bar Length:3B Flags:0
Slide 9
Slide 9 text
Basic Commands
Slide 10
Slide 10 text
get, gets
[email protected]:11211> gets bar
key: bar
value: Bar
length: 3B
flags: 0
cas: 2
[email protected]:11211> get foo baz
Key:foo Value:Foo Length:3B Flags:0
Key:baz Value:Baz Length:3B Flags:0
Slide 11
Slide 11 text
set, add, replace
memcached@~> set foo Foo
OK
memcached@~> add foo Whooah!
Failed to add item. KEY foo, VALUE Whooah!
memcached@~> replace foo Hoohoo.
OK
memcached@~> get foo
key: foo
value: Hoohoo.
length: 7B
flags: 0
Slide 12
Slide 12 text
Other data manipulation commands
❏ append, prepend … add prefix/suffix to
data
❏ cas … check-and-set for transaction
❏ touch … update expiration time
❏ incr, decr … add or reduce numeric data
value
❏ delete … remove data
Slide 13
Slide 13 text
Stats Commands
Slide 14
Slide 14 text
What is “stats” commands?
❏ Built-in Memcached commands to get server
internal statistics
❏ stats … general statistics
❏ stats … various stats
❏ settings … server settings
❏ items … number / eviction / expire, etc.
❏ slabs … chunk / page / memory used
❏ conns … state / peer addr of active connections
❏ cachedump … sample some data of a slab
❏ sizes … item count per size ※Hold Lock
❏ detail … get / hit / set / del stats per namespace
Other Commands & Features
❏ randomset … random data generator
❏ dump_all / restore_dump … dump / restore
whole data in server
❏ call [] … execute any
command to server
❏ Term::ReadLine … support command
history
Slide 20
Slide 20 text
DEMO
Slide 21
Slide 21 text
Conclusion
Enjoy chatting to memcached by
“memcached-cli” !!
Slide 22
Slide 22 text
Thank you!
Slide 23
Slide 23 text
Appendix: Related softwares
❏ andrewgross/memcache-cli (Python)
❏ libmemcached#client-apps (C)