0

I have installed Memcached on an Azure VM server (Ubuntu). I now need to connect to this from my Python program that runs elsewhere.

When they were installed on the same server, this worked:

import memcache
MEMCACHE_SOCKET_PATH = 'unix:<path_to>/memcached.sock'  
memcache_client = memcache.Client([MEMCACHE_SOCKET_PATH], debug=0)

Now I'm not sure what to use for MEMCACHE_SOCKET_PATH. The VM running Memcached has a static IP address and I have created an endpoint (opened a port) to 11211. memcached.sock sits in the home directory.

This is how I am running Memcached on the VM:

memcached -d -m 500 -s $HOME/memcached.sock -P $HOME/memcached.pid
Charles Xu
  • 29,862
  • 2
  • 22
  • 39
user984003
  • 28,050
  • 64
  • 189
  • 285

1 Answers1

1

According to your description about the command to run memcached on Azure VM, I see your memcached was running with Unix domain socket, not TCP/IP. Unix domain socket is a IPC (Inter-process communication)solution of data communications for exchanging data between processes executing on the same host operating system, it can not be used in a RPC (Remote procedure call) scenario.

So to fix it, you just need to start up memcached using memcached.conf and make it working on TCP/IP. If you were using the command sudo apt-get install memcached to install memcached, the memcached.conf file should be at the path /etc/memcached.conf. Then you can change it by using sudo vim /etc/memcached.cond to set the values of port -p & listen ip -l, as below.

-p 11211
-l 0.0.0.0

When you have added an inbound rule of your VM NSG network interface at the tab Networking, then you could connect the memcached service in Python via the tcp address <your vm host ip>:<port like 11211>.

Peter Pan
  • 23,476
  • 4
  • 25
  • 43