Skip to content

Instantly share code, notes, and snippets.

@romanitalian
Last active April 29, 2021 20:18
Show Gist options
  • Save romanitalian/5eca63e7e30e6e92029a11a546db6c0e to your computer and use it in GitHub Desktop.
Save romanitalian/5eca63e7e30e6e92029a11a546db6c0e to your computer and use it in GitHub Desktop.

How change memcached PORT on Mac OS + brew

https://asciinema.org/a/HBlnwgdiOytT9lmOjSGS5d9GH

To connect to memcached from the console: $ telnet localhost 11211

And now, to exit telnet, execute:

$ quit

That is, let's check that we have connected to memcached on port 11211:

$ telnet localhost 11211

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
quit
Connection closed by foreign host.

~/Library/LaunchAgents/homebrew.mxcl.memcached.plist

We look at the config BEFORE changes:

$ cat ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist

<?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>Label</key>
  <string>homebrew.mxcl.memcached</string>
  <key>KeepAlive</key>
  <true/>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/opt/memcached/bin/memcached</string>
    <string>-l</string>
    <string>localhost</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>WorkingDirectory</key>
  <string>/usr/local</string>
</dict>
</plist>

We make a link to the memcached configs so that they are not overwritten when restarting memcached

$ ln -sfv /usr/local/opt/memcached/*.plist ~/Library/LaunchAgents

Editing the configuration:

$ vim /usr/local/opt/memcached/homebrew.mxcl.memcached.plist

add:

    <string>-p</string>
    <string>11213</string>

We look at the config AFTER changes:

$ cat ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist

<?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>Label</key>
  <string>homebrew.mxcl.memcached</string>
  <key>KeepAlive</key>
  <true/>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/opt/memcached/bin/memcached</string>
    <string>-l</string>
    <string>localhost</string>
    <string>-p</string>
    <string>11213</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>WorkingDirectory</key>
  <string>/usr/local</string>
</dict>
</plist>

Now we restart memcached:

$ brew services restart memcached

Check if the port has changed:

$ telnet localhost 11213

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
quit
Connection closed by foreign host.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment