6

I started up Redis for the first time on my local machine today and then later closed all terminal windows after I shutdown my Rails app. An hour later, I started up the Rails app again and did the following to start the redis server

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

However, it told me

# Opening port 6379: bind: Address already in use

I therefore assumed it was still running its earlier instance even though I closed the terminal windows on my Mac.

Looking at this page http://redis.io/commands/shutdown, I tried to run

SHUTDOWN

in the terminal window but I get this response

SHUTDOWN: NOT super-user

I therefore tried (Even though I didn't use sudo to start it)

sudo SHUTDOWN 

and after it asked me for my password, it output this

usage: shutdown [-] [-h [-u] [-n] | -r [-n] | -s | -k] time [warning-message ...]

but when I randomly ran shutdown -s it said

 SHUTDOWN: NOT super-user

What's the proper way to shutdown Redis when I close up my app?

Cœur
  • 37,241
  • 25
  • 195
  • 267
BrainLikeADullPencil
  • 11,313
  • 24
  • 78
  • 134
  • Hey, I accidentally downvoted your question 15 minutes ago. I've just realized that but I can't undo it. If you edit it I think I can undo it. I'm really, really sorry. – Leandro Fournier Aug 24 '15 at 18:01

3 Answers3

37

Use the built-in redis client: redis-cli shutdown

Alan Dixon
  • 541
  • 4
  • 7
4

This is meant to be sent as a command to redis, not to be executed on your terminal.

In this case you can actually just kill redis from the terminal, since upon receiving a SIGTERM signal it will schedule a SHUTDOWN instead of simply exiting.

For reference see the signal handling doc page.

Nathan
  • 4,017
  • 2
  • 25
  • 20
3

Find out the process id of the Redis instance running on your machine...

> ps aux | grep redis

impadmin 23277  0.0  0.0  35044  1976 pts/2    Sl+  14:19   0:00 src/redis-server

... and then run:

> kill 23277
Nathan Fraenkel
  • 3,422
  • 4
  • 18
  • 21
Chhavi Gangwal
  • 1,166
  • 9
  • 13
  • 2
    I tried this approach, but kept noticing that my `redis-server` process kept changing its PID for some reason... So each time I ran `ps aux | grep redis` the displayed PID would be different from the previous run of `ps aux | grep redis`. Ultimately `redis-cli shutdown` was what I wanted. – mecampbellsoup Feb 12 '16 at 18:54