Connecting
Python
On each connection, the first command sent to the server must authenticate
by issuing a set with username password as the
value. The proxy responds STORED on success or
CLIENT_ERROR invalid credentials on failure. The key name (shown
here as _auth) is ignored by the proxy — any value works. This is
the default Memcached authentication
mechanism and does not require SASL support, which not every client or
hosting environment has properly compiled in.
Use mc1.public.gra1.ovh.velstash.io to connect to your instance. We
recommend using TLS (port 11212) for connections over the public Internet,
since traffic between you and this region (cached values as well as
credentials) may be easier to intercept if travelling unencrypted. We reserve
the right to introduce usage-based pricing for disproportionate external
traffic in the future, with advance notice.
mc1.public.gra1.ovh.velstash.io,
username your-username, password your-password.
Installing a client
pymemcache is used in the examples below.
pip install pymemcache
Plain TCP
# pymemcache uses text protocol by default — no extra configuration needed.
from pymemcache.client.base import Client
client = Client(('mc1.public.gra1.ovh.velstash.io', 11211))
client.set('_auth', 'your-username your-password')
TLS
import ssl
from pymemcache.client.base import Client
context = ssl.create_default_context()
client = Client(
('mc1.public.gra1.ovh.velstash.io', 11212),
tls_context=context,
)
client.set('_auth', 'your-username your-password')
client.set('mykey', 'bar')
print(client.get('mykey'))
Reading and writing
client.set('user:123:profile', data, expire=3600) # 3600s TTL
value = client.get('user:123:profile')
if value is None:
# cache miss — if you ever intentionally cache a `None`-like value
# yourself, use a sentinel so you can tell the two cases apart
Common pitfalls
-
Items over 1MB (the default max item size) fail silently on
set— check the result code or error your client returns if a value doesn't seem to be sticking. -
Prefixing keys with
:(e.g.user:123:profile) is what makes the dashboard's top-keys/prefixes view group things meaningfully — worth doing from day one. -
The auth
setauthenticates the underlying TCP connection, not the client object — it only needs to run once per connection (that's why each example above issues it right after connecting, not before every request). If your client library pools connections or silently reopens them, make sure new connections authenticate too before you rely on them.