redisをインストール
http://redis.io/download
ここにあるリンクのある最新版を落としてくる。今安定版なのは2.6系。
$ wget http://redis.googlecode.com/files/redis-2.6.12.tar.gz $ tar zxvf redis-2.6.12.tar.gz $ cd redis-2.6.12 $ make $ make install $ redis-server
これで起動できる。
あとはcuiのクライアントで叩いて遊んでみる
$ redis-cli > set hoge piyo > get hoge "piyo"
以下気になる諸々
設定ファイルは?
デフォルトの設定ファイルがtarを解凍してできたディレクトリの中にある。サーバーを起動するときに
$ redis-server /path/to/redis.conf
というようにすれば設定ファイルを読み込んでくれる。
いつ永続化すんの?
永続化できるKVSが売り文句のredis。
永続化のタイミングは設定ファイルに記述できる。デフォは以下のような設定。
################################ SNAPSHOTTING #################################
#
# Save the DB on disk:
#
# save
#
# Will save the DB if both the given number of seconds and the given
# number of write operations against the DB occurred.
#
# In the example below the behaviour will be to save:
# after 900 sec (15 min) if at least 1 key changed
# after 300 sec (5 min) if at least 10 keys changed
# after 60 sec if at least 10000 keys changed
#
# Note: you can disable saving at all commenting all the "save" lines.
#
# It is also possible to remove all the previously configured save
# points by adding a save directive with a single empty string argument
# like in the following example:
#
# save ""save 900 1
save 300 10
save 60 10000
早くても60秒に1回、遅いと900秒に一回のペース。コミットの度にスナップショットとることもできるし、saveコマンドやbgsaveコマンドを使えば即時保存も可能。
何に永続化するの?
当然何かしらのデータファイルに永続化したデータを入れている。
デフォルトではdump.rdbというファイルにデータを保存している。設定ファイル内のdbfilenameディレクティブで名前の変更が可能。
また、rdbファイルの置き場もdirディレクティブで変更可能。デフォは./
トランザクションは?
できる。詳しくはこのへんのドキュメントで。(もう面倒くさくなった)
http://redis.io/topics/transactions
http://redis.shibu.jp/commandreference/alldata.html#command-MULTI
*1:デフォだとログは標準出力