79

I used brew to install redis (a key/value store database server) for my node.js app.

brew install redis

However, it seems to disappear and is very volatile. Because I'm using redis as my session store, I need to be able to quickly restart it on my mac when this happens.

How do I restart redis that I installed with brew?

slhck
  • 235,242
chovy
  • 1,195

7 Answers7

75

update

brew services expired due to no one want to maintain it. check below: https://github.com/Homebrew/homebrew/issues/28657

check launchctl function instead.

or lunchy

So instead of:

launchctl load ~/Library/LaunchAgents/io.redis.redis-server.plist

you can do this:

lunchy start redis

and:

lunchy ls

references: https://github.com/eddiezane/lunchy

It used to be able to use as below:

brew services restart redis

should be the restart command You want. You can also run

brew services list

which will give you list of your brew services.

ken
  • 994
49

As of Dec-7-2015 You can use brew services.

You need to brew tap homebrew/services and then thw following will work as expected:

install brew install redis

start brew services start redis

stop brew services stop redis

restart brew services restart redis

More info here: https://github.com/Homebrew/homebrew-services

microspino
  • 1,041
23

Brew doesn't support the services command anymore.

The recommended way is to use os x's launchctl command.

First you need to setup redis as a service managed by launchctl:

$ ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents

Then you can use launchctl load/ launchctl unload to start/stop the service:

$ # start redis server
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
$
$ # stop redis server
$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
oDDsKooL
  • 331
19

I found all these options listed in brew package (brew info redis) to be very buggy. For example redis throws a bunch of errors if it isn't started with root. I ended up just doing the direct call with sudo and removing launchctl files.

sudo redis-server /usr/local/etc/redis.conf

I was hoping there was a way to easily restart redis from the command line, but that doesn't seem possible. Therefore, I run with daemon mode set to 'no' and watch it log to stdout, then I can kill it easily.

slhck
  • 235,242
chovy
  • 1,195
1

For Homebrew 1.5.14

redis-server

0

If you are successfully running brew services start redis or brew services restart redis, then seeing "Could not connect to Redis at 127.0.0.1:6379: Connection refused" when attempting to run redis-cli, you should verify the existence of your redis configuration file.

You can run touch /usr/local/etc/redis.conf or similar to create an empty configuration file.

Then run brew services restart redis and redis-cli, then voila!

127.0.0.1:6379> PING
PONG
0

You can restart your redis server with brew services restart redis

if you want to change your redis configuration you can execute: brew info redis

to know where is your config file, in my case is inside /opt/homebrew/opt/redis/bin/redis-server /opt/homebrew/etc/redis.conf

there you can change your port or wherever you want, i just changed my default port because i was trying to use :6379 for other things and that was generating some issues with my server.