1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Memcachedを使う

Last updated at Posted at 2014-12-03

memcachedを使う

オリジナルサイト
http://memcached.org/

コンパイル

configure

shell
    ./configure \
        --prefix=${PREFIX_DIR} \
        --libdir=${TARGETLIB_DIR} \
        --sysconfdir=/etc

make手順

shell
$ make
# make install

デーモン起動

起動例

shell
$ memcached -u nobody \
            -p 31385 \
            -U 31385 \
            -m 64 \
            -d -P /var/run/memcached.pid

-vv オプションを付けてデバッグメッセージを表示することもできる

説明

shell
$ memcached -u ${MEMCACHED_USER} \
            -p ${TCP_PORT} \
            -U ${UDP_PORT} \
            -m ${CACHE_SIZE} \
            -d -P ${PIDFILE}

※CACHE_SIZEはMB単位で指定する。指定されたサイズを超えてデータを登録しようとした場合は、一番古いデータから削除されて登録される

終了

プロセスに対してシグナルを送る

shell
$ pkill -TERM memcached

※ Memcachedを終了すると保存されたデータは全て削除される

telnetでデーモンに接続

shell
$ telnet localhost ${PORT_NUMBER}

PORT_NUMBER を省略した場合は 11211 番で接続する

プロトコル

値を設定

memcached
set ${key} ${flags} ${exptime} ${bytes}
  • key・・・・key
  • flags・・・取りあえず 0
  • exptime・・値の有効期限 0:無期限、Unix timeもしくは現在からの秒数
  • bytes・・・データのバイト数

値を取得

memcached
get ${key}

有効期限を変更する

memcached
touch ${key} ${exptime}

libmemcached

C言語プログラムからmemcachedにアクセスするには libmemcached を使うといい

オリジナルサイト
http://libmemcached.org/libMemcached.html

コンパイル

configureには特にオプションはない。以下くらいで十分だろう

shell
$ ./configure \
      --prefix=${PREFIX_DIR} \
      --libdir=${TARGETLIB_DIR} \
      --sysconfdir=/etc

makeも特に考えることはない

shell
$ make
# make install
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?