Linux安裝Redis服務


tar xf /home/source/redis-3.0.6.tar.gz

cd redis-3.0.6

make PREFIX=/usr/local/redis install

mkdir /etc/redis

/bin/cp -f redis.conf /etc/redis/redis.conf

sed -i 's@^daemonize no@daemonize yes@'    /etc/redis/redis.conf



redis服務腳本

#!/bin/sh

#

# chkconfig : 2345 45 90

# as it does use of the /proc filesystem.


REDISPORT=6379

EXEC=/usr/local/redis/bin/redis-server

CLIEXEC=/usr/local/redis/bin/redis-cli


PIDFILE=/var/run/redis.pid

CONF="/etc/redis/redis.conf"


start() {

        if [ -f $PIDFILE ]

        then

                echo "$PIDFILE exists, process is already running or crashed"

        else

                echo "Starting Redis server..."

                $EXEC $CONF

        fi

}


stop() {

        if [ ! -f $PIDFILE ]

        then

                echo "$PIDFILE does not exist, process is not running"

        else

                PID=$(cat $PIDFILE)

                echo "Stopping ..."

                $CLIEXEC -p $REDISPORT shutdown

                while [ -x /proc/${PID} ]

                do

                    echo "Waiting for Redis to shutdown ..."

                    sleep 1

                done

                echo "Redis stopped"

        fi

}


case "$1" in

    start)

        start

        ;;

    stop)

        stop

        ;;

    restart)

        stop

        start

        ;;

    *)

        echo "Please use start or stop as first argument"

        ;;

esac


啓動redis

[root@iZ25jyqlmgdZ ~]# /etc/init.d/redis start

連接redis

[root@iZ25jyqlmgdZ ~]# /usr/local/redis/bin/redis-cli -h 127.0.0.1
127.0.0.1:6379>

獲取redis中所有的key

127.0.0.1:6379> keys *







發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章