Any way to ask redis-server to start on an OS-chosen port?

53 views
Skip to first unread message

Caleb Spare

unread,
Dec 30, 2016, 5:19:55 PM12/30/16
to Redis DB
I'd like to ask redis to start on an unoccupied OS-chosen port. I tried --port 0 but, as the docs say, "If port 0 is specified Redis will not listen on a TCP socket."

Is there some way I'm overlooking of doing this? If not, is it a reasonable feature request?

(In case you're curious, I need to run a redis-server subprocess for some tests and it's nicer to start on arbitrary open port rather than hard-code a port to use which can collide with some other server -- perhaps even a concurrent test invocation. My plan was to ask redis to start on port 0, so the OS would choose the port, and then parse the "* The server is now ready to accept connections on port nnnn" line from the log output.)

Thanks!
Caleb

Dvir Volk

unread,
Jan 2, 2017, 2:48:53 AM1/2/17
to Redis DB
Depending on the language you are writing your tests in, there are libraries that do that for you from within your tests, using random port selection.
Here's one I've written in Go: https://github.com/EverythingMe/disposable-redis

and a bit of googling will get you more in other major languages. 

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

Caleb Spare

unread,
Jan 3, 2017, 4:00:54 PM1/3/17
to Redis DB
Thanks for the pointer. That's certainly a workable approach. Seems like a slightly unpleasant workaround, though; it would be nicer if redis-server let me use this existing OS feature.

-Caleb

hva...@gmail.com

unread,
Jan 3, 2017, 10:25:45 PM1/3/17
to Redis DB
This is a very rare feature you're asking for.  Mostly because there's no mechanism to inform the client of the correct port to use when it wants to connect to the server.  Especially when the client is on a different server, which is the vast majority of use cases.
Reply all
Reply to author
Forward
0 new messages