Master Memcached, Redis, and RabbitMQ: Install, Configure, and Use with Python

This guide walks through the fundamentals, installation steps, configuration details, and Python integration for three essential backend services—Memcached for high‑performance caching, Redis for persistent key‑value storage, and RabbitMQ for reliable messaging—complete with command‑line examples, code snippets, and best‑practice tips.

dbaplus Community
dbaplus Community
dbaplus Community
Master Memcached, Redis, and RabbitMQ: Install, Configure, and Use with Python

Memcached

Memcached is a high‑performance distributed memory object cache that reduces database load by storing key/value pairs in RAM. It runs as a C daemon and can be accessed from any language via the memcached protocol.

Memory management : Memcached pre‑allocates a fixed memory pool and uses a slab allocation strategy to divide memory into fixed‑size chunks. When the cache fills, an LRU algorithm evicts the least‑recently used items. Data is volatile; a restart clears the cache unless a persistent layer such as Memcachedb is used.

Default listening port: 11211 Installation & startup (example command):

memcached -d -m 10 -u root -l 192.168.0.1 -p 12000 -c 256 -P /tmp/memcached.pid

Parameters: -d: run as daemon -m: memory size in MB -u: user -l: bind IP -p: port (usually >1024) -c: max concurrent connections -P: pid file location

Core commands :

Store: set, add, replace, append, prepend Retrieve: get, gets Delete: delete Increment/Decrement: incr, decr Python integration using python‑memcached:

import memcache
mc = memcache.Client(['192.168.1.5:12000'], debug=True)
mc.set("foo", "bar")
print(mc.get('foo'))

Cluster support is built‑in; hosts are weighted in a list. The client hashes a key, takes the modulo of the host list length, and selects the corresponding server.

Redis

Redis (Remote Dictionary Server) is a persistent key‑value store that supports richer data types than Memcached, including strings, lists, sets, sorted sets, and hashes. It keeps data in memory for speed and periodically writes snapshots (RDB) or an append‑only log (AOF) to disk.

Persistence options :

RDB : point‑in‑time snapshots, generated via SAVE (blocking) or BGSAVE (forks a child process).

AOF : logs every write command; can be flushed always, everysec (default), or no.

When both are enabled, AOF takes precedence on startup.

Installation example (binary or source) and start with: redis-server /path/to/redis.conf Python client (redis‑py) :

import redis
r = redis.Redis(host='192.168.1.5', port=6379)
r.set('foo', 'Bar')
print(r.get('foo'))

Connection pooling reduces overhead:

pool = redis.ConnectionPool(host='192.168.1.5', port=6379)
r = redis.Redis(connection_pool=pool)

Common operations are grouped by data type (String, Hash, List, Set, Sorted Set). Pipelines allow atomic batch execution:

pipe = r.pipeline()
pipe.set('name', 'nick')
pipe.set('age', '18')
pipe.execute()

Pub/Sub example:

pub = r.publish('channel', 'message')
sub = r.subscribe('channel')

RabbitMQ

RabbitMQ is an AMQP‑based enterprise message broker. It mediates producers, exchanges, queues, and consumers, supporting reliable delivery, acknowledgments, durability, and routing patterns.

Key concepts :

Producer – sends messages.

Exchange – routes messages to queues (types: direct, fanout, topic, headers).

Queue – stores messages until consumed.

Consumer – receives messages.

Installation (binary packages or Docker) and start the broker.

Message reliability :

Acknowledgments (ack): consumers must ack after processing; un‑acked messages are re‑queued on consumer failure.

Durable queues/exchanges : survive broker restarts.

Routing examples : direct – exact routing key match. topic – pattern matching with * (single word) and # (zero or more words).

Sample Python usage with pika (not shown in source) follows the same patterns: declare exchange, bind queue, publish, and consume with manual acks.

Overall, the article provides a practical reference for setting up, configuring, and programmatically interacting with Memcached, Redis, and RabbitMQ, covering essential commands, Python APIs, clustering behavior, persistence strategies, and messaging guarantees.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonBackend DevelopmentrediscachingMessage QueueRabbitMQMemcached
dbaplus Community
Written by

dbaplus Community

Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.