0% found this document useful (0 votes)
79 views

16 PDFsam Redis Cookbook

The document discusses different options for installing Redis, including compiling from source, using package managers on Linux, and ports available on Windows and Mac OS X. It recommends compiling from source for the latest features, but acknowledges that package managers provide easier updates. Key steps outlined are downloading the source, compiling, running tests, and installing the binaries. Considerations mentioned include using development versus stable versions, and limitations of Windows ports.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

16 PDFsam Redis Cookbook

The document discusses different options for installing Redis, including compiling from source, using package managers on Linux, and ports available on Windows and Mac OS X. It recommends compiling from source for the latest features, but acknowledges that package managers provide easier updates. Key steps outlined are downloading the source, compiling, running tests, and installing the binaries. Considerations mentioned include using development versus stable versions, and limitations of Windows ports.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Are your application and data a good fit for NoSQL?

When working on the web, chances are your data and data model keep changing with
added functionality and business updates. Evolving the schema to support these
changes in a relational database is a painful process, especially if you can’t really afford
downtime—which people most often can’t these days, because applications are
expected to run 24/7. As a case in point, in a recent presentation on MongoDB, Jeremy
Zawodny of Craigslist mentioned how changing the schema on their database typically
takes a two month-long toll on their post archival service.
Examples of data that are a particularly good fit for nonrelation storage are transactional
details, historical data, and server logs. These are normally highly dynamic, changing
quite often, and their storage tends to grow quite quickly, further compounding the
problem of adjusting the schema to store them. They also don’t typically feel “rela-
tional”—that is, the data in them doesn’t tend to fan out in relationships to other types
of data. That’s a good indication that they can use something other than a RDBMS.
Another way to gauge the fit for NoSQL is to look at whether you find yourself
denormalizing your data for performance reasons, and no longer benefit from some of
the advantages of a relational system, such as consistency and redundancy checks.
One thing to keep in mind is that NoSQL databases generally don’t provide ACID
(atomicity, consistency, isolation, durability), or do it only partially. This allows them
to make a few tradeoffs that wouldn’t be possible otherwise. Redis provides partial
ACID compliance by design due to the fact that it is single threaded (which guarantees
consistency and isolation), and full compliance if configured with appendfsync
always, providing durability as well.
Performance can also be a key factor. NoSQL databases are generally faster, particularly
for write operations, making them a good fit for applications that are write-heavy.
All this being said, and even though NoSQL feels more flexible, there are also great
arguments to be made for storing relational data in a RDBMS. If you have predictable
data that is a great fit for normalization, you can reap the benefits of using a relational
data storage engine. Always look at the data before making a decision.

Don’t believe the hype


NoSQL databases such as Redis are fast, scale easily, and are a great fit for many modern
problems. But as with everything else, it is important to always choose the right tool
for the job. Play to the strengths of your tools by looking at what you’re storing, how
often you’ll access it, and how data (and its schema) might change over time.
Once you’ve weighted all the options, picking between SQL (for stable, predictable,
relational data) and NoSQL (for temporary, highly dynamic data) should be an easy
task. Doing this kind of thinking in advance will save you many headaches in future
data migration efforts.

2 | Chapter 1: An Introduction to Redis

www.it-ebooks.info
There are also big differences between NoSQL databases that you should account for.
For example, MongoDB (a popular NoSQL database) is a feature-heavy document
database that allows you to perform range queries, regular expression searches, index-
ing, and MapReduce. You should weigh all the factors when choosing your database.
As we said earlier, the questions boil down to what your data looks like and what your
usage pattern is.
For example, Redis is extremely fast, making it perfectly suited for applications that
are write-heavy, data that changes often, and data that naturally fits one of Redis’s data
structures (for instance, analytics data). A scenario where you probably shouldn’t use
Redis is if you have a very large dataset of which only a small part is “hot” (accessed
often) or a case where your dataset doesn’t fit in memory.

Installing Redis
Problem
You want to install Redis on your computer.

Solution
There are several ways to install Redis on your computer or server, but the best and
most flexible option is to compile it yourself. Nevertheless, depending on your distri-
bution or operating system, there are other options.

Discussion
Compiling From Source
Redis evolves very quickly and package maintainers have a hard time keeping up with
the latest developments. Since Redis doesn’t have any external dependencies, compi-
lation and installation are very straightforward, so we recommend you do it yourself.
Redis should build cleanly in most Linux distributions, Mac OS X, Solaris, and Cygwin
on Windows.
1. Downloading the source
You can download Redis from the official site or directly from the Github
project, either using Git or your browser to fetch a snapshot of one the branches
or tags. This allows you get to get development versions, release candidates, etc.
2. Compiling
Redis compilation is straightforward. The only required tools should be a C com-
piler (normally GCC) and Make. If you want to run the test suite, you also need
Tcl 8.5.

Installing Redis | 3

www.it-ebooks.info
After unpacking the source and changing your terminal path to the source direc-
tory, just type:
make

This will compile Redis, which on a modern computer should take less than 10
seconds. If you’re using a x86_64 system but would like an x86 build (which uses
less memory but also has a much lower memory limit), you can do so by passing
along 32bit to Make:
make 32bit

After compiling Redis, particularly if you’re building a development version, you


should run the test suite to ensure that the server is behaving as expected.
make test
3. Installing
After compiling Redis, you can go ahead and run it:
cd src && ./redis-server

However, you might find it more convenient to install it to another location in your
system. The Makefile wlll also help you do that:
make install

This will install Redis binaries to /usr/local/bin. If you wish to install to another
location, you can pass it to make. For instance:
make install /opt/local

This will install the binaries in /opt/local/bin.


After installating the Redis server, you should also copy the configuration file
(redis.conf) to a path of your choice, the default being /etc/redis.conf. If your con-
figuration file is in a different path from the default, you can pass it along as a
parameter to redis-server:
/usr/local/bin/redis-server /alternate-location-for-redis-config.conf

Installing on Linux
Most modern Linux distributions have Redis packages available for installation, but
keep in mind that these are normally not up-to-date. However, if you prefer to use
these, the installation procedure is much simpler:
Debian/Ubuntu
sudo apt-get install redis-server

Fedora/Redhat/CentOS
sudo yum install redis

4 | Chapter 1: An Introduction to Redis

www.it-ebooks.info
Gentoo
sudo emerge redis

This approach has a few advantages: by using your package management system, you
can more easily keep software up-to-date, and you’ll most likely get at least security
and stability updates. Besides that, you’ll also get startup scripts and an environment
more suited to your distribution (user accounts, log files, database location, etc).

Installing on Windows
Although Redis is not officially supported on Windows for several reasons—notably
the lack of a copy-on-write fork()—the community provides a few ports. Due to Win-
dows’ limitations, Redis MinGW builds execute operations such as BGSAVE and
BGREWRITEAOF in the foreground (thus blocking the Redis process) and Cygwin builds
don’t use CoW, which makes background operations very slow, particularly for large
database sizes. Be sure to disable automatic saving in the config file (especially for
MinGW builds) and use SAVE only when needed.
Beware that for performance and stability reasons, the Windows versions of Redis are
not recommended for production use. Consider using a native or virtualized Linux/
UNIX environment instead. Despite that, you might find these versions useful for
development or testing.
Cygwin
Cygwin is a UNIX-like environment for Windows that implements most of the
POSIX API, thereby enabling you to build and run Redis on Windows. Cygwin is
the easiest way to compile Redis on Windows. From the Cygwin environment, you
can download the Redis source and build it following the steps described in
“Compiling From Source” on page 3. Some users might have licensing issues (due
to Cygwin’s use of the GPL).
ServiceStack maintains a page with a few builds (both x86 and x86_64) along with
their open source C# client.
MinGW
MinGW is a Windows port of the GNU CC compiler (GCC) and the GNU binutils.
Because it builds native Windows binaries, it doesn’t suffer from the same licensing
issues as Cygwin.
Since MinGW doesn’t provide a POSIX API, the Redis source code needs to be
modified in order to build. Dušan Majkić’s fork on Github is regularly updated
and also adds a Windows Service for easier management.

Installing Redis | 5

www.it-ebooks.info
Installing on Mac OS X
There are several ways to install Redis on Mac OS X. They all require you to have the
XCode developer tools installed, which includes libraries and compilers. If you are a
developer on a Mac, chances are you already have this package installed. If you don’t,
you can either download it from Apple’s developers website or run “Install Developer
Tools” on your Mac’s installation DVDs.
You can manually compile Redis from source by following the steps earlier in this
chapter. Most people, however, prefer the convenience of a package manager such as
Fink, MacPorts, or Homebrew. A Redis package isn’t available on Fink, so we’ll cover
the other two.
Installing through MacPorts. MacPorts defines itself as “an easy to use system for compiling,
installing, and managing open source software.” It is based on the FreeBSD Ports sys-
tem, and to a large extent can be used in the exact same way.
In order to install Redis through MacPorts, you need to first install the package man-
agement system. There’s an extensive guide on how to do that at guide.macports.org.
Once you’ve installed MacPorts, installing the Redis package is as simple as:
port install redis

Since Redis has no direct dependencies, the actual compilation and installation process
is quite speedy. You will then be ready to start using Redis.
Installing through Homebrew. Homebrew is the latest entrant in the Mac package manage-
ment scene. Being relatively new means that not every package you might be looking
for is available on it—even though they make contributions very easy—but if you’re
looking for a tool that developers use often, chances are that it’s going to be available
through a Homebrew recipe.
You can install Homebrew by following the detailed instructions available over at
Github, but it is usually as simple as running the following command:
ruby -e "$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)"

Once that’s done, you’ll be ready to install packages using the Homebrew recipes sys-
tem. Installing Redis is just a matter of typing:
brew install redis

You can then run redis-server manually or install it into the Mac’s own LaunchServices
so that it starts when you reboot your computer. You can edit the configuration
file /usr/local/etc/redis.conf to tweak it to your liking, and then start the server:
redis-server /usr/local/etc/redis.conf

6 | Chapter 1: An Introduction to Redis

www.it-ebooks.info

You might also like