redislite icon indicating copy to clipboard operation
redislite copied to clipboard

server shutdown mandatory?

Open lindycoder opened this issue 9 years ago • 3 comments

Hi, i've been playing around with your server with this little script:

import redislite
from redis import Redis

server=redislite.Redis(serverconfig={'port': '35000'})

print server.keys()

client = Redis(port=35000)

client.rpush("mykey", "hey")

print server.lpop("mykey")

And i was surprised i couldn't launch the same script twice in a row or else i'd get this error:

Traceback (most recent call last):
  File "redislite_test.py", line 4, in <module>
    server=redislite.Redis(serverconfig={'port': '35000'})
  File ".tox/py27/lib/python2.7/site-packages/redislite/client.py", line 330, in __init__
    self._start_redis()
  File ".tox/py27/lib/python2.7/site-packages/redislite/client.py", line 188, in _start_redis
    'The redis-server process failed to start'
redislite.client.RedisLiteServerStartError: The redis-server process failed to start

After some testing i found that if i add

server.shutdown()

at the end of my script i can run it over and over.

I don't know how much of a bug this is but i couldn't find this in your doc, maybe at least say we need to shutdown manually.

here's some system specs redislite==3.0.271 OS X El Capitan 10.11.3 Python 2.7.11

Have a nice day

lindycoder avatar Feb 24 '16 16:02 lindycoder

Well it would seem that i overlooked that a process is created with the server that persists after the python program ends, so i couldn't start a new server on the same port because there was already one running.

It feels a little counter intuitive that a server started by a python script would not end with its termination.

I use this for integration testing of an application so my tests starts and ends the server, so maybe it's only my use-case.

lindycoder avatar Feb 24 '16 18:02 lindycoder

It doesn't shutdown the server process if there active connections to the redis server process that where not created by the current process.

If all activity to the redis server is through redislite Redis or StrictRedis classes then the last process with a connection to the redis server will terminate the redis server. If however a connection is made without going through redislite it's possible for the redis-server process to remain running if that connection is still active when the process that has redislite running terminates.

dwighthubbard avatar Mar 12 '16 20:03 dwighthubbard

Okay, that sounds fine.

My use case being exactly connecting without going through redislite so it was confusing for me.

My suggestion was merely to add a little note to the doc, but if you don't feel like it, you can close this issue i won't mind :)

lindycoder avatar Mar 15 '16 13:03 lindycoder