Install Redis and set multiple Redis instances on Mac OS
Install Redis with brew, if you don’t have brew installed yet, google how to install brew on Mac.
[code language=”shell”]
brew install redis
[/code]
To have redis started on login.
[code language=”shell”]
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
[/code]
Start redis with launchctl.
[code language=”shell”]
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
[/code]
Start redis with redis-server command.
[code language=”shell”]
redis-server /usr/local/etc/redis.conf
[/code]
To enter redis interactive console.
[code language=”shell”]
redis-cli
[/code]
To list all keys in redis.
[code language=”shell”]
keys *
[/code]
To clear all redis keys.
[code language=”shell”]
flushall
[/code]
To exit redis interactive console.
[code language=”shell”]
exit
[/code]
To set a new instance of redis, all you need is a new redis config file, start redis with that config file and you will have a second redis instance up and running.
1. Copy the default redis config file that is used for the default redis instance.
[code language=”shell”]
cp /usr/local/etc/redis.conf /usr/local/etc/redis2.conf
[/code]
2. Open the redis2.conf and change the configuration for deamonize, pidfile, port, unixsocket, logfile and dbfilename to the below
[code language=”shell”]
daemonize yes
pidfile /usr/local/var/run/redis-2.pid
port 6380
unixsocket /tmp/redis-2.sock
logfile "/usr/local/var/log/redis-2.log"
dbfilename dump-2.rdb
[/code]
3. Create launch on login config file.
[code language=”shell”]
cp ~/Library/LaunchAgents/homebrew.mxcl.redis.plist ~/Library/LaunchAgents/homebrew.mxcl.redis2.plist
[/code]
4. Open ~/Library/LaunchAgents/homebrew.mxcl.redis2.plist and change the configuration as need so it will look like the below
[code language=”xml”]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
<string>homebrew.mxcl.redis2</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/redis/bin/redis-server</string>
<string>/usr/local/etc/redis2.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>/usr/local/var</string>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/redis-2.log</string>
<key>StandardOutPath</key>
<string>/usr/local/var/log/redis-2.log</string>
</dict>
</plist>
[/code]
5. Load redis with the plist file
[code language=”shell”]
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis2.plist
[/code]
6. Start redis with the config file.
[code language=”shell”]
redis-server /usr/local/etc/redis2.conf
[/code]
7. To have redis launch on start
[code language=”shell”]
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
[/code]
8. To enter the second redis instance interactive console.
[code language=”shell”]
redis-cli -p 6380
[/code]
Search within Codexpedia
Search the entire web