A.1 Installation on Debian or Ubuntu Linux

  • Redis in Action – Home
  • Foreword
  • Preface
  • Part 1: Getting Started
  • Part 2: Core concepts
  • 1.3.1 Voting on articles
  • 1.3.2 Posting and fetching articles
  • 1.3.3 Grouping articles
  • 4.2.1 Configuring Redis for replication
  • 4.2.2 Redis replication startup process
  • 4.2.3 Master/slave chains
  • 4.2.4 Verifying disk writes
  • 5.1 Logging to Redis
  • 5.2 Counters and statistics
  • 5.3 IP-to-city and -country lookup
  • 5.4 Service discovery and configuration
  • 5.1.1 Recent logs
  • 5.1.2 Common logs
  • 5.2.2 Storing statistics in Redis
  • 5.3.1 Loading the location tables
  • 5.3.2 Looking up cities
  • 5.4.1 Using Redis to store configuration information
  • 5.4.2 One Redis server per application component
  • 5.4.3 Automatic Redis connection management
  • 8.1.1 User information
  • 8.1.2 Status messages
  • 9.1.1 The ziplist representation
  • 9.1.2 The intset encoding for SETs
  • Chapter 10: Scaling Redis
  • Chapter 11: Scripting Redis with Lua
  • 10.1 Scaling reads
  • 10.2 Scaling writes and memory capacity
  • 10.3 Scaling complex queries
  • 10.2.2 Creating a server-sharded connection decorator
  • 10.3.1 Scaling search query volume
  • 10.3.2 Scaling search index size
  • 10.3.3 Scaling a social network
  • 11.1.1 Loading Lua scripts into Redis
  • 11.1.2 Creating a new status message
  • 11.2 Rewriting locks and semaphores with Lua
  • 11.3 Doing away with WATCH/MULTI/EXEC
  • 11.4 Sharding LISTs with Lua
  • 11.5 Summary
  • 11.2.1 Why locks in Lua?
  • 11.2.2 Rewriting our lock
  • 11.2.3 Counting semaphores in Lua
  • 11.4.1 Structuring a sharded LIST
  • 11.4.2 Pushing items onto the sharded LIST
  • 11.4.4 Performing blocking pops from the sharded LIST
  • A.1 Installation on Debian or Ubuntu Linux
  • A.2 Installing on OS X
  • B.1 Forums for help
  • B.4 Data visualization and recording
  • Buy the paperback
  • Redis in Action – Home
  • Foreword
  • Preface
  • Part 1: Getting Started
  • Part 2: Core concepts
  • 1.3.1 Voting on articles
  • 1.3.2 Posting and fetching articles
  • 1.3.3 Grouping articles
  • 4.2.1 Configuring Redis for replication
  • 4.2.2 Redis replication startup process
  • 4.2.3 Master/slave chains
  • 4.2.4 Verifying disk writes
  • 5.1 Logging to Redis
  • 5.2 Counters and statistics
  • 5.3 IP-to-city and -country lookup
  • 5.4 Service discovery and configuration
  • 5.1.1 Recent logs
  • 5.1.2 Common logs
  • 5.2.2 Storing statistics in Redis
  • 5.3.1 Loading the location tables
  • 5.3.2 Looking up cities
  • 5.4.1 Using Redis to store configuration information
  • 5.4.2 One Redis server per application component
  • 5.4.3 Automatic Redis connection management
  • 8.1.1 User information
  • 8.1.2 Status messages
  • 9.1.1 The ziplist representation
  • 9.1.2 The intset encoding for SETs
  • Chapter 10: Scaling Redis
  • Chapter 11: Scripting Redis with Lua
  • 10.1 Scaling reads
  • 10.2 Scaling writes and memory capacity
  • 10.3 Scaling complex queries
  • 10.2.2 Creating a server-sharded connection decorator
  • 10.3.1 Scaling search query volume
  • 10.3.2 Scaling search index size
  • 10.3.3 Scaling a social network
  • 11.1.1 Loading Lua scripts into Redis
  • 11.1.2 Creating a new status message
  • 11.2 Rewriting locks and semaphores with Lua
  • 11.3 Doing away with WATCH/MULTI/EXEC
  • 11.4 Sharding LISTs with Lua
  • 11.5 Summary
  • 11.2.1 Why locks in Lua?
  • 11.2.2 Rewriting our lock
  • 11.2.3 Counting semaphores in Lua
  • 11.4.1 Structuring a sharded LIST
  • 11.4.2 Pushing items onto the sharded LIST
  • 11.4.4 Performing blocking pops from the sharded LIST
  • A.1 Installation on Debian or Ubuntu Linux
  • A.2 Installing on OS X
  • B.1 Forums for help
  • B.4 Data visualization and recording
  • Buy the paperback

    A.1 Installation on Debian or Ubuntu Linux

    If you’re using a Debian-derived Linux, your first instinct will be to apt-get install
    redis-server
    , but this is probably the wrong thing to do. Depending on your version
    of Debian or Ubuntu, you could be installing an old version of Redis. As an example,
    if you’re using Ubuntu 10.4, you’d be downloading Redis 1.2.6, which was released
    in March 2010 and doesn’t support many of the commands that we use.

    In this section, you’ll first install the build tools because you’ll compile Redis
    from scratch. Then you’ll download, compile, and install Redis. After Redis is running,
    you’ll download the Redis client libraries for Python.

    To get started, make sure that you have all of the standard required build tools
    installed by fetching and downloading make, as can be seen in the following listing.

    Listing A.1Installing build tools on Debian Linux
    ~$ sudo apt-get update
    ~$ sudo apt-get install make gcc python-dev
    

    When your build tools are installed (they were probably installed before; this was a
    verification step), you’ll take these steps:

    1. Download the most recent stable Redis source code from http://redis.io/download.
    2. Extract, compile, install, and start Redis.
    3. Download and install the necessary Redis client libraries for Python.

    The first two steps in this process are shown next.

    Listing A.2Installing Redis on Linux
    ~:$ wget -q http://redis.googlecode.com/files/redis-2.6.9.tar.gz
    

    Download the most recent version of Redis 2.6 (or later): http://redis.io/download).

    ~:$ tar -xzf redis-2.6.9.tar.gz
    

    Extract the source code.

    ~:$ cd redis-2.6.9/
    
    ~/redis-2.6.9:$ make
    

    Compile Redis.

    cd src && make all
    [trimmed]
    make[1]: Leaving directory `~/redis-2.6.9/src'
    

    Watch compilation messages go by; you shouldn’t see any errors.

    ~/redis-2.6.9:$ sudo make install
    

    Install Redis.

    cd src && make install
    [trimmed]
    make[1]: Leaving directory `~/redis-2.6.9/src'
    

    Watch installation messages go by; you shouldn’t see any errors.

    ~/redis-2.6.9:$ redis-server redis.conf
    

    Start Redis server.

    [13792] 2 Feb 17:53:16.523 * Max number of open files set to 10032
    [trimmed]
    [13792] 2 Feb 17:53:16.529 * The server is now ready to accept
    connections on port 6379
    

    See the confirmation that Redis has started.

    After you have Redis installed and running, you need to install the Redis client libraries
    for Python. You won’t bother to install Python, because Python 2.6 or 2.7 should
    already be installed by default on Ubuntu or Debian releases in the last few years. But
    you’ll download and install a simple helper package called setuptools, which will
    help you download and install the Redis client libraries.1 This last step of installing the
    Redis client libraries for Python is shown next.

    Listing A.3Installing the Redis client libraries for Python on Linux
    ~:$ wget -q http://peak.telecommunity.com/dist/ez_setup.py
    

    Download the setuptools ez_setup module.

    ~:$ sudo python ez_setup.py
    
    Downloading http://pypi.python.org/packages/2.7/s/setuptools/...
    [trimmed]
    Finished processing dependencies for setuptools==0.6c11
    

    Run the ez_setup module to download and install setuptools.

    ~:$ sudo python -m easy_install redis hiredis
    

    Run setuptools’ easy_install package to install the redis and hiredis packages.

    Searching for redis
    [trimmed]
    Finished processing dependencies for redis
    

    The redis package offers a somewhat standard interface to Redis from Python.

    Searching for hiredis
    [trimmed]
    Finished processing dependencies for hiredis
    

    The hiredis package is a C accelerator library for the Python Redis library.

    ~:$
    

    Now that you have the Python libraries installed, you can skip ahead to section A.4 to
    test Redis from Python, which should prepare you for all of the other chapters.

    1 Experienced Python users will ask “Why not pip?” which is another package for installing Python libraries.
    This is because virtualenv, which is necessary for the easy download of pip, is out of the scope of these
    instructions.