Skip to content

Instantly share code, notes, and snippets.

@cromat
Forked from pcan/README.md
Last active June 30, 2021 15:37
Show Gist options
  • Save cromat/a86511f72e1282c496ba156fb6eb2352 to your computer and use it in GitHub Desktop.
Save cromat/a86511f72e1282c496ba156fb6eb2352 to your computer and use it in GitHub Desktop.
Compile Redis with Cygwin

Prerequisites

Install Cygwin with make, gcc, g++ and tcl.
(If you use apt-cyg you can install them with apt-cyg install make, apt-cyg install gcc-core and apt-cyg install tcl
Download Redis tar.gz package, unpack it.

Patch

Edit deps/hiredis/net.c and add following line before include directives:

#define _POSIX_C_SOURCE 200112L

and add the following lines just after the include directives:

/* Cygwin Fix */
#ifdef __CYGWIN__
#define TCP_KEEPCNT 8
#define TCP_KEEPINTVL 150
#define TCP_KEEPIDLE 14400
#endif

Build

Run the following script:

cd deps/
make lua hiredis linenoise

cd ..
make
# Some tests fail, but mainly working which is suitable for development environments
make test
make install

Test

# Check redis version
redis-cli --version

# Run redis server as deamon
redis-server &

# Test redis
redis-cli PING
# or
redis-cli -h localhost PING

Credits

Thanks to winse, see this blog entry and pcan https://gist.github.com/pcan/44cb2177647f029d457facb31da0883f).

@drnybble
Copy link

drnybble commented Apr 25, 2019

I found another problem if you are using sentinels. You need to change a line in src/sentinel.c:

void sentinelFlushConfig(void) {
...
    if ((fd = open(server.configfile,O_RDONLY)) == -1) goto werr;
    if (fsync(fd) == -1) goto werr;

Change that to O_RDWR because the following fsync will fail on a read-only file descriptor. cygwin ultimately calls the Windows FlushFileBuffers API call that requires GENERIC_WRITE access or it fails with a Permission Denied error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment