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
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.confand make it working on TCP/IP. If you were using the commandsudo apt-get install memcachedto install memcached, thememcached.conffile should be at the path/etc/memcached.conf. Then you can change it by usingsudo vim /etc/memcached.condto set the values of port-p& listen ip-l, as below.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>.