51

I want to stop the redis server and it just keeps going and going. I am using redis-2.6.7

Check that it is running:

redis-server

It says "...bind: Address already in use" so it is already running.

I have tried

redis-cli
redis 127.0.0.1:6379> shutdown

It just hangs and nothing happens. I break out and check, yes, it is still running.

I have tried

redis-server stop

I get "can't open config file 'stop'"

I tried:

killall redis-server

Still running.

The reason that I want to stop it is that it is just hanging when I try to set or get a value via Python. So I thought that I would restart it.

EDIT:

No commands seem to work from redis-cli. I also tried INFO and it just hangs.

user984003
  • 28,050
  • 64
  • 189
  • 285
  • 3
    Curious why someone is voting to close this? – user984003 Feb 26 '13 at 11:42
  • Because it's not a programming question in SO terms, but rather belongs on SuperUser. – John Zwinck Feb 26 '13 at 11:50
  • 7
    I see lots of questions dealing with redis on stackoverflow, including another one that specifically asks about shutting down the redis server. That's the question that gave me the ideas to try (and which didn't work). Not sure what could be more relevant to programming. Maybe you don't know redis? Anyway, I hope someone helps because I am completely stuck with something that just hangs. – user984003 Feb 26 '13 at 11:55
  • I do know Redis. But I think the key is that no amount of programming per se is going to give a satisfactory answer to this question. Your problem is one of understanding how to use a piece of software, and it's not a compiler. So I suggest you post on SuperUser. – John Zwinck Feb 26 '13 at 11:58
  • 6
    Just looked at superuser. They don't have a tag for Redis and I'm not allowed to create a new tag. So that is out. And this question does follow StackOverflow's guidelines for questions: "software tools commonly used by programmers" and "practical, answerable problems that are unique to the programming profession" The other question on redis shutdown question http://stackoverflow.com/questions/6910378/stop-redis-server got 11 up-votes (22 up-votes for the question) so clearly this is relevant. – user984003 Feb 26 '13 at 12:03
  • For what it's worth, all your commands work for me except the obviously-broken `redis-server stop`. What OS are you using? – John Zwinck Feb 26 '13 at 12:08
  • I am running this on Webfaction. Linux web232.webfaction.com 2.6.18-308.8.2.el5PAE #1 SMP Tue Jun 12 10:37:15 EDT 2012 i686 i686 i386 GNU/Linux – user984003 Feb 26 '13 at 12:09
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/25144/discussion-between-john-zwinck-and-user984003) – John Zwinck Feb 26 '13 at 12:23
  • Flushdb after system restart issue. Any idea? – Dhaduk Mitesh Jul 02 '21 at 05:14

16 Answers16

43

I finally got it down.

Get the PID of the process (this worked in Webfaction):

ps -u my_account -o pid,rss,command | grep redis

Then

> kill -9 the_pid

I was able to REPRODUCE this issue:

Start redis-server
Then break it using Pause/Break key

Now it hangs and it won't shutdown normally. Also the Python program trying to set/get a key hangs. To avoid this: Just close the window after starting redis-server. It's now running normally.

Naveed Ahmad
  • 3,176
  • 1
  • 15
  • 18
user984003
  • 28,050
  • 64
  • 189
  • 285
  • 1
    you could narrow down the first bit to find redis easier with a grep ps -u my_user -o pid,rss,command | grep redis 54577 812 redis-server *:6379 – David Morrow May 01 '15 at 22:46
  • In order to start the server again, i also needed to delete the PID file, in my case it's /var/run/redis_6379.pid – Alex2php Apr 09 '16 at 12:20
  • 9
    This solution didn't work for me. However, this did: `sudo systemctl stop redis.service` – drishit96 Apr 06 '18 at 07:24
  • 3
    +1 drishit96. For me it was `sudo systemctl stop redis-server.service` to shut it down without it automatically restarting. None of the other commands or usual methods worked for me either. – Joe Feb 15 '19 at 07:58
  • i don't know why i get this error `(54333) - No such process ` when i try to kill redis-server with pid. – Mojtaba Arezoomand Jul 29 '21 at 12:37
25

I can't reproduce the problem anymore, but shutdown NOSAVE helped me, when I was playing with redis and couldn't get it to shut down:

redis-cli
127.0.0.1:6379> shutdown
(error) ERR Errors trying to SHUTDOWN. Check logs.
127.0.0.1:6379> shutdown NOSAVE
not connected>
LarS
  • 1,324
  • 20
  • 27
21

Shutdown Redis Server $ redis-cli -a password -p 6379 shutdown

Start Redis Server $ sudo service redis_6379 start

It works on Ubuntu Server 14.04 x86 Redis v2.8.15.

xuri
  • 840
  • 7
  • 18
9

Depending on your setup, either of the following solutions might fail, with redis-server just restarting with a new PID:

1.

redis-cli -a password shutdown

or, 2.

ps aux|grep redis
kill -9 <redis pid>

But the below command works.

/etc/init.d/redis-server stop

My server is Ubuntu 18.04.2 and Redis version is v4.0.9

abe
  • 355
  • 2
  • 9
DavidLin3
  • 353
  • 3
  • 7
7

The normal way of doing this is to connect to a client like redis-cli and execute "shutdown" command. I've found some issues trying to shutdown because redis-server doesn't have right permissions to edit db dump file (RDB) prior to quit. Then redis remains started and you have to kill the process with kill -9 pid. But this is not a redis problem as you may know.

Example of this problem:

# User requested shutdown...
[16560] 10 Sep 11:21:17.672 * Saving the final RDB snapshot before exiting.
[16560] 10 Sep 11:21:17.672 # Failed opening .rdb for saving: Permission denied
[16560] 10 Sep 11:21:17.672 # Error trying to save the DB, can't exit.
Emilio
  • 1,024
  • 4
  • 16
  • 33
  • I believe this is the problem the original poster has, but they were not aware of the RDB write issue. How does one solve this? No amount of permission changing on my write directory will solve this. – almel Jun 20 '18 at 04:33
2

If You use Ubuntu or other linux distros try stop redis server:

sudo service redis-server stop
Jonatas Eduardo
  • 834
  • 9
  • 18
1

i think shutdown command can shutdown the redis server. Maybe strange,after typed shutdown command,the redis-cli does not exit.Meanwhile ,the server has shutdowned.

user188826
  • 11
  • 2
1

This is possibly an really important note for some people reading this. If your redis doesn't seem to be responding to a shutdown. CHECK THE LOGS.

They may say something like this:

Apr 24 00:48:54 redis[828]: Received SIGTERM, scheduling shutdown...
Apr 24 00:48:54 redis[828]: User requested shutdown, saving DB...
Apr 24 00:55:37 redis[828]: DB saved on disk

Maybe your DB is multiple GB, or tens of GBs in which case it will take time to shutdown. If instead you want to clean out all keys, there is a better way to do that than shutdown. FLUSHALL

Jono
  • 3,393
  • 6
  • 33
  • 48
1

On windows this worked:

Open terminal(PowerShell/CMD), type: wsl --shutdown

It will end your virtual machine.

Aleksandar
  • 844
  • 1
  • 8
  • 18
0

net stop redis

should do the trick

to start :

net start redis

see this https://stackoverflow.com/a/20153062

Community
  • 1
  • 1
Arif
  • 315
  • 2
  • 10
0

When setting up the server to require auth...

The redis start and shutdown script utilizes redis-cli, which means that shutdown will not happen without auth and the server will hang in a loop waiting for redis to shutdown, which won't ever happen without auth.

So in the shutdown script you have to change

$CLIEXEC -p $REDISPORT shutdown

to

$CLIEXEC -a 'authpassword' -p $REDISPORT shutdown

in order to allow your redis service to shutdown without hassle.

Billy
  • 886
  • 8
  • 18
0

You use the following command to kill the running redis-server process.

ps aux |grep redis

This will list all the running processes for redis-server. Then you can use the following command to kill the redis processes

sudo kill <pid for redis>

sample here

sudo kill 7229 //for the above sample.
Smart Manoj
  • 5,230
  • 4
  • 34
  • 59
bpathak
  • 127
  • 1
  • 4
0

Best way check pid of redis opened port :

lsof -i:<redis-port>

for default redis port

lsof -i:6379

kill -9 <pid>
Prashant Srivastav
  • 1,723
  • 17
  • 28
0

I had a Could not connect to Redis at 127.0.0.1:6379: Connection refused error and nothing worked for me from the suggested solutions.

My solution: run sudo redis-server /etc/redis.conf command in the terminal.

After running the command I was able to use Redis again without that error.

Note: I do not know if it is OS-dependent, but I use Manjaro Linux. I am not sure if it will work the same on a different OS.

Nairum
  • 1,217
  • 1
  • 15
  • 36
-1

on redis-cli command "shutdown SAVE" or "shutdown NOSAVE" will work.

Prashant Sharma
  • 375
  • 3
  • 5
-2
start redis: $REDIS_HOME/src/redis-server
stop redis: $REDIS_HOME/src/redis-cli shutdown

$REDIS_HOME where you have installed/extracted redis.

Deepak Punjabi
  • 483
  • 1
  • 7
  • 17