If you haven't already, you'll need to configure a Redis instance and install a Redis client library for PHP. Most environments require the phpredis PHP extension. On Debian / Ubuntu, you can install the requirements via
apt-get install redis-server php-redis. If you're running MediaWiki on top of HHVM (unlikely unless you're a developer), you can use the Redis client library that comes with HHVM instead.
In your LocalSettings.php file, set:
/** @see RedisBagOStuff for a full explanation of these options. **/ $wgObjectCaches['redis'] = array( 'class' => 'RedisBagOStuff', 'servers' => array( '127.0.0.1:6379' ), // 'connectTimeout' => 1, // 'persistent' => false, // 'password' => 'secret', // 'automaticFailOver' => true, );
You'll now be able to acquire a Redis object cache object via
wfGetCache( 'redis' ). If you'd like to use Redis as the default cache for various data, you may set any of the following configuration options:
$wgMainCacheType = 'redis'; $wgSessionCacheType = 'redis'; // same as WMF prod // Not widely tested: $wgMessageCacheType = 'redis'; $wgParserCacheType = 'redis'; $wgLanguageConverterCacheType = 'redis';
$wgJobTypeConf['default'] = [ 'class' => 'JobQueueRedis', 'redisServer' => '127.0.0.1:6379', 'redisConfig' => , 'claimTTL' => 3600, 'daemonized' => true ];
From that moment, jobs will be delivered to the Redis instance run the specified server.
MediaWiki & Wikimedia use cases for Redis
- Session storage
- The Wikimedia Foundation has been using Redis as a memcached replacement for session storage since the eqiad switchover in January 2013, because it has a replication feature which can be used to synchronise data between the two data centres. It allowed us to switch from Tampa to Ashburn without logging everyone out.
- Job queue
- We previously stored the MW job queue in MySQL. This gave us lots of useful features, like replication and indexing for duplicate removal, but it has often been hard to manage the performance implications of the high insert rate. Among its many features, Redis embeds a Lua interpreter on the server side. The new Redis job queue class provides a rich feature set superior to the MySQL job queue, mainly through several server-side Lua scripts which provide high-level job queue functions. Redis is also used to keep a hash table that tracks which job queues actually have jobs, so runners know where to look. Updates to this table are push-based, so it is always up-to-date.
- Extension:GettingStarted's early implementation of a category-based recommender system has used Redis to store a list of tasks (actually page ids) served via a few interfaces.
- Official site (see esp. Introduction to Redis)
- The Redis article on the English Wikipedia.
- Redis Watch - an e-mail round-up of Redis news, articles, tools and libraries
- Getting to Know Redis
- Redis, from the Ground Up
- Redis and Relational Data
- Redis Cookbook (book; not great, but see ch. "Analytics and Time-Based Data")
- Interview with Salvatore Sanfilippo (code-oriented but still useful)
- Redis DB (Google Group)
- Redis at Disqus (their entire analytics platform runs on Redis)
- Effective Web App Analytics with Redis
- How YouPorn uses Redis (video)
- Realtime metrics using Redis bitmaps
- Redsmin a real-time, atomic, performant administration and monitoring interface for Redis
- redis-py is the library of choice for Python
- Getting Started: Redis and Python
- Redis and Python (presentation slides)
- Resque for jobs
- Redisco, a Python ORM for Redis
- py-analytics (I haven't used this)
- redis-bitops Ruby gem for sparse bitmap operations
- Storing hundreds of millions of simple key-value pairs (how Instagram uses Redis)
- Key performance metrics to monitor for Redis