MacBookPro 搭建本地redis服务

1.官网下载最新redis版本:

官网地址:http://redis.io

笔者使用的版本是6.0.8,下载的压缩包是:redis-6.0.8.tar。

2.mac 进入 /usr/loca/文件夹,如何进去,点击这里传送门

3.复制解压后的文件夹 redis-6.0.8,放到 /usr/local/ 文件夹中。

4. 终端进入 文件夹 cd /usr/local,然后切换成root  权限:su root,然后进入 redis-6.0.8文件夹: cd redis-6.0.8/

5. 编译文件:sudo make test,出现如下结果表示成功:

笔者在安装到这一步,出现2个error ,没管它继续走。

6.然后开始安装:sudo make install

到这里表明,安装成功。

7. 在 /usr/local/ 文件夹中新建两个文件夹 bin ,etc ,另外在 redis-6.0.8中新建文件夹db 作为存档日志的地方,不过位置不固定,放到 /usr/local/也可以,只要你在后续的redis.conf配置文件中指定好就可以了,安装以后笔者的文件夹/usr/local/里面自动新建了bin文件夹还有一些文件, 如图所示

 

 

8. 将 /usr/local/redis-3.2.5/src 目录下的 mkreleasehdr.sh, redis-benchmark, redis-check-rdb, redis-cli, redis server 拷贝至 /usr/local/bin 目录,不过笔者在安装以后 bin文件夹中出现了个文件,将没有出现的文件复制过来就好。

9.将 redis-6.0.8文件夹中的 redis.conf 拷贝至目录 etc,然后对其修改:

日志文件位置:


# Specify the log file name. Also the empty string 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 /usr/local/redis-6.0.8/log-redis.log

 

指定本地数据库文件名:这里的位置和7中新建db文件夹的位置对应。

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /usr/local/redis-6.0.8/db/

ip地址默认的是127.0.0.1,需要查看下:

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 loopback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1

其他的配置,可以自己后续使用中摸索就好。

10.启动redis服务。

进入 etc文件夹:cd etc/

启动服务:sudo redis-server redis.conf

 

 这样服务端就启动成功了。

查看日志:tail -f /usr/local/redis-6.0.8/log-redis.log

 

关闭服务:redis-cli shutdow

 

11.启动客户端:重新打开一个终端

cd /usr/local/redis-6.0.8

 redis-cli -h 127.0.0.1 -p 6379

这样就连接成功了,测试OK。

可以玩起来了。

其他的地方可以参考末尾的博客。

 

转帖参考博客的其他命令,作为后续查看

删除指定索引的值:del key

清空整个 Redis 服务器的数据:flushall 

清空当前库中的所有 key:flushdb 

关闭客户端,但是不关闭服务器:exit

关闭服务:

1、杀掉进程: 新打开一个终端 查看redis 服务:ps -ef|grep redis  直接杀死进程: kill XXX pid

2、在redis-cli中使用shutdown命令:新开一个终端:使用命令关闭服务:redis-cli shutdown

 

感谢几位博主的分享, 参考博客:

https://blog.csdn.net/qq_38728790/article/details/82703308

https://blog.csdn.net/resilient/article/details/76611390

https://blog.csdn.net/weixin_40841731/article/details/91414886

https://blog.csdn.net/qq_41910367/article/details/82784478

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值