一、linux安装
-
安装
#ubuntu sudo apt-get update sudo apt-get install redis-server #centos sudo yum instal redis-server
-
启动redis
redis-server
-
查看 redis 是否启动
redis-cli redis 127.0.0.1:6379>
-
开机启动
第一步 编辑文件
# 第一步 sudo vi /etc/init.d/redis
第二步 编辑脚本复制如下代码
注意要修改里面redisd的安装路径(通过命令安装默认路径)
# chkconfig: 2345 90 10 # description: Redis is a persistent key-value database PATH=/usr/local/bin REDISPORT=6379 EXEC=/usr/local/bin/redis-server REDIS_CLI=/usr/local/bin/redis-cli #Redis密码 注意修改成你的 PASSWORD=123456 PIDFILE=/var/run/redis.pid CONF="/usr/local/reids/conf/redis.conf" case "$1" in start) if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already running or crashed" else echo "Starting Redis server..." $EXEC $CONF fi if [ "$?"="0" ] then echo "Redis is running..." fi ;; stop) if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist, process is not running" else PID=$(cat $PIDFILE) echo "Stopping ..." $REDIS_CLI -p $REDISPORT -a $PASSWORD SHUTDOWN while [ -x ${PIDFILE} ] do echo "Waiting for Redis to shutdown ..." sleep 1 done echo "Redis stopped" fi ;; restart|force-reload) ${0} stop ${0} start ;; *) echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2 exit 1 esac
第四步 将启动脚本复制到/etc/init.d目录下,本例将启动脚本命名为redisd(通常都以d结尾表示是后台自启动服务)
cp redisd /etc/init.d/redisd
二、Mac 安装
2.1 如果未安装brew,命令行先输入以下命令安装brew。
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2.2 安装
//可以在redis后面加版本, 例brew install redis@5.5
brew install redis
2.3 启动redis
//普通启动方法
redis-server
//使用配置文件启动
redis-server /usr/local/etc/redis.conf
2.4 停止redis
#方式一
redis-cli shutdown
#方式二
redis-cli -p 6379 -a [密码] shutdown
2.5 进入 redis
redis-cli
2.6 redis配置文件位置
/usr/local/etc/redis.conf
2.7 检测redis服务器是否启动
redis-cli -p 6379 -a lzq ping
#该终端输出
#pong
#说明服务器运作正常。
2.8. 其它
开机启动redis命令
$ ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
使用launchctl启动redis server
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
使用配置文件启动redis server
$ redis-server /usr/local/etc/redis.conf
停止redis server的自启动
$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
redis 配置文件的位置
/usr/local/etc/redis.conf
卸载redis和它的文件
brew uninstallredis rm ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
测试redis server是否启动
$ redis-cli ping
网友评论