##telnetで接続
# telnet localhost 11211
Trying ::1...
Connected to localhost.
Escape character is '^]'.
##データの格納
set key1 0 0 6
value1
STORED
ワンライナー
(echo "set key1 0 0 6"; sleep 0.5s; echo "value1"; sleep 0.5s;) | telnet localhost 11211
##データの取得
get key1
VALUE key1 0 6
value1
END
ワンライナー
(echo "get key1"; sleep 0.5s;) | telnet localhost 11211
##データの書換
replace key1 0 0 6
value2
STORED
##格納されているデータの後ろに追記
append key1 0 0 6
value3
STORED
get key1
VALUE key1 0 12
value2value3
##格納されているデータの前に追記
prepend key1 0 0 6
value1
STORED
get key1
VALUE key1 0 18
value1value2value3
END
##データの削除
delete key1
DELETED
##データの加算/減算
set key1 0 0 3
100
STORED
incr key1 1000
1100
decr key1 2000
0
delete key1
DELETED
##切断
quit
Connection closed by foreign host.
#
キー一覧
#!/bin/bash -eu
IFS=$'\n'
hosts=(
localhost
)
ports=(
11211
11212
11213
)
for host in ${hosts[@]}; do
for port in ${ports[@]}; do
keys=()
echo "host:${host}:${port}"
set +e
items=$((echo 'stats items'; sleep 0.5s;) | telnet ${host} ${port} 2>/dev/null | egrep 'items:[0-9]+:number [0-9]+')
set -e
for item in ${items[@]}; do
items=$(echo $item | perl -pe 's/^STAT items:([0-9]+):.+$/$1/')
number=$(echo $item | perl -pe 's/^.+ ([0-9]+)$/$1/')
keys+=($((echo "stats cachedump $items $number"; sleep 0.5s;) | telnet ${host} ${port} 2>/dev/null | egrep -v 'END|^Escape.+|^Trying.+|^Connected.+'))
done
for key in "${keys[@]+"${keys[@]}"}"; do
echo $key | perl -pe 's/^ITEM (.+)?/$1/'
done
done
done