e-Book - Redis in Action

This book covers the use of Redis, an in-memory database/data structure server.
  • Foreword
  • Preface
  • Acknowledgments
  • About this Book
  • About the Cover Illustration
  • Part 1: Getting Started
  • Part 2: Core concepts
  • Part 3: Next steps
  • Appendix A
  • Appendix B
  • 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
    , 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
    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
    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
    [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/...
    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
    Finished processing dependencies for redis

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

    Searching for hiredis
    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