Thursday, July 09, 2015

Install Redis and set multiple Redis instances on Mac OS | Codexpedia

Install Redis and set multiple Redis instances on Mac OS | Codexpedia



Install Redis with brew, if you don’t have brew installed yet, google how to install brew on Mac.
1
brew install redis
To have redis started on login.
1
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
Start redis with launchctl.
1
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
Start redis with redis-server command.
1
redis-server /usr/local/etc/redis.conf
To enter redis interactive console.
1
redis-cli
To list all keys in redis.
1
keys *
To clear all redis keys.
1
flushall
To exit redis interactive console.
1
exit
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.
1
cp /usr/local/etc/redis.conf /usr/local/etc/redis2.conf
2. Open the redis2.conf and change the configuration for deamonize, pidfile, port, unixsocket, logfile and dbfilename to the below
1
2
3
4
5
6
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
3. Create launch on login config file.
1
cp ~/Library/LaunchAgents/homebrew.mxcl.redis.plist ~/Library/LaunchAgents/homebrew.mxcl.redis2.plist
4. Open ~/Library/LaunchAgents/homebrew.mxcl.redis2.plist and change the configuration as need so it will look like the below
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?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>
5. Load redis with the plist file
1
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis2.plist
6. Start redis with the config file.
1
redis-server /usr/local/etc/redis2.conf
7. To have redis launch on start
1
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
8. To enter the second redis instance interactive console.
1
redis-cli -p 6380

No comments: