redisに挑戦してみる

$ wget http://redis.googlecode.com/files/redis-2.4.7.tar.gz
$ tar xzvf redis-2.4.7.tar.gz
$ cd redis-2.4.7
$ make PREFIX=$HOME/usr/local
$ make install PREFIX=$HOME/usr/local
$ cd src/
$ ./redis-server ../redis.conf
[26021] 11 Feb 15:24:41 * Server started, Redis version 2.4.7
[26021] 11 Feb 15:24:41 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[26021] 11 Feb 15:24:41 * The server is now ready to accept connections on port 6379
[26021] 11 Feb 15:24:42 - 0 clients connected (0 slaves), 717480 bytes in use
$ cd src
$ ./redis-cli
redis 127.0.0.1:6379> ping
PONG
redis 127.0.0.1:6379> set foo 1
OK
redis 127.0.0.1:6379> get foo
"1"
$ cpanm Redis
  • 設定ファイル
$ diff -Naur redis.conf ~/.redis/redis.conf
--- redis.conf  2012-02-02 23:29:24.000000000 +0900
+++ /home/ymko/.redis/redis.conf        2012-02-11 20:41:54.000000000 +0900
@@ -14,11 +14,11 @@

 # By default Redis does not run as a daemon. Use 'yes' if you need it.
 # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
-daemonize no
+daemonize yes

 # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
 # default. You can specify a custom pid file location here.
-pidfile /var/run/redis.pid
+pidfile /home/ymko/.redis/redis.pid

 # Accept connections on the specified port, default is 6379.
 # If port 0 is specified Redis will not listen on a TCP socket.
@@ -45,12 +45,14 @@
 # verbose (many rarely useful info, but not a mess like the debug level)
 # notice (moderately verbose, what you want in production probably)
 # warning (only very important / critical messages are logged)
-loglevel verbose
+#loglevel verbose
+loglevel notice

 # Specify the log file name. Also 'stdout' can be used to force
 # Redis to log on the standard output. Note that if you use standard
 # output for logging but daemonize, logs will be sent to /dev/null
-logfile stdout
+#logfile stdout
+logfile /home/ymko/.redis/redis.log

 # To enable logging to the system logger, just set 'syslog-enabled' to yes,
 # and optionally update the other syslog parameters to suit your needs.
@@ -84,8 +86,8 @@
 #   Note: you can disable saving at all commenting all the "save" lines.

 save 900 1
-save 300 10
-save 60 10000
+#save 300 10
+#save 60 10000

# Compress string objects using LZF when dump .rdb databases?
# For default that's set to 'yes' as it's almost always a win.
@@ -104,7 +106,8 @@
# Also the Append Only File will be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
-dir ./
+dir /home/ymko/.redis/
$ diff -Naur utils/redis_init_script ~/bin/redis_init_script
--- utils/redis_init_script     2012-02-11 20:18:18.000000000 +0900
+++ /home/ymko/bin/redis_init_script    2012-02-11 20:37:14.000000000 +0900
@@ -7,8 +7,8 @@
 EXEC=$HOME/usr/local/bin/redis-server
 CLIEXEC=$HOME/usr/local/bin/redis-cli

-PIDFILE=$HOME/.redis/redis_${REDISPORT}.pid
-CONF="$HOME/.redis/${REDISPORT}.conf"
+PIDFILE=$HOME/.redis/redis.pid
+CONF="$HOME/.redis/redis.conf"

 case "$1" in
     start)
@@ -36,6 +36,15 @@
                 echo "Redis stopped"
         fi
         ;;
+    status)
+        if [ -f $PIDFILE ]
+        then
+                PID=$(cat $PIDFILE)
+                echo "running Redis server... $PID"
+        else
+                echo "Redis stopping"
+        fi
+        ;;
     *)
         echo "Please use start or stop as first argument"
         ;;