memcached-toolを利用してデータ移動

  • 投稿者:
  • 投稿カテゴリー:memcached

memcachedインストール

root@hostname:/home/shimizu# aptitude install memcached
以下の新規パッケージがインストールされます:
  libevent-2.0-5{a} memcached
...

root@hostname:/home/shimizu# memcached -h
memcached 1.4.21
...

memcachedにkey追加と確認

root@hostname:/home/shimizu# telnet localhost 11211
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
set key 0 1000 5
value
STORED
get key
VALUE key 0 5
value
END
quit
Connection closed by foreign host.

memcached-toolを使ってみる

root@hostname:/home/shimizu# /usr/share/memcached/scripts/memcached-tool localhost:11211 display
  #  Item_Size  Max_age   Pages   Count   Full?  Evicted Evict_Time OOM
  1      96B        32s       1       1     yes        0        0    0
root@hostname:/home/shimizu# /usr/share/memcached/scripts/memcached-tool localhost:11211 stats
#localhost:11211   Field       Value
         accepting_conns           1
...

memcached-toolでダンプ

root@hostname:/home/shimizu# /usr/share/memcached/scripts/memcached-tool localhost:11211 dump
Dumping memcache contents
  Number of buckets: 1
  Number of items  : 1
Dumping bucket 1 - 1 total items
add key 0 1447949842 5
value

root@hostname:/home/shimizu# /usr/share/memcached/scripts/memcached-tool localhost:11211 dump > memcached.data
Dumping memcache contents
  Number of buckets: 1
  Number of items  : 1
Dumping bucket 1 - 1 total items

root@hostname:/home/shimizu# cat memcached.data
add key 0 1447949842 5
value

memcached-toolでリストア

root@hostname:/home/shimizu# /etc/init.d/memcached restart
[ ok ] Restarting memcached (via systemctl): memcached.service.

root@hostname:/home/shimizu# cat memcached.data | nc localhost 11211
STORED
^C
root@hostname:/home/shimizu# telnet localhost 11211
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
get key
VALUE key 0 5
value
END

有効期限が0のデータがあるとおかしくなるかも
memcached-toolを使ってmemcachedのデータをエクスポートする

参考URL

memcached-toolの取得方法と使い方
memcachedのデータを移行する