Ben
Ben

Reputation: 16710

Testing Memcached connection

I want to run a basic service which shows the status of various other services on the system (i.e. Mongo, Redis, Memcached, etc).

For Memcached, I thought that I might do something like this:

from django.core.cache import cache 

host, name = cache._cache._get_server('test')

This seems to return a host and an arbitrary string. Does the host object confirm that I'm connecting to Memcached successfully?

I know that the returned host object has a connect() method. I'm slightly scared to open a new connection in production environment and I don't have an easy Dev setup to test that method. I assume that it's in one of the Python Memcached libraries, but I'm not sure which one is relevant here.

Can I just use the _get_server method to test Memecached connection success, or should I use the connect method?

Upvotes: 1

Views: 1561

Answers (1)

Heikki Toivonen
Heikki Toivonen

Reputation: 31150

There are various things you could monitor, like memcache process up, memcache logs moving etc. that don't require network connectivity. Next level of test would be to see that you can open a socket at the memcache port. But the real test is of course to set and get a value from memcache. For that kind of testing I would probably just use the python-memcached package directly to make the connection and set and get values.

Upvotes: 1

Related Questions