Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Instant Redis Optimization How-to

You're reading from  Instant Redis Optimization How-to

Product type Book
Published in May 2013
Publisher Packt
ISBN-13 9781782164807
Pages 56 pages
Edition 1st Edition
Languages
Author (1):
Arun Chinnachamy Arun Chinnachamy
Profile icon Arun Chinnachamy

Choosing your data store (Simple)


Every database software is written to solve a specific problem and is best suited to that. It takes a lot of hard work to select a data store that fits your application requirements. It is always important to pick the right tool for the right job. In this recipe, we will see which data store to select from top names like Cassandra, MongoDB, Riak, CouchBase, MemCached, and others, based on your application requirements.

Getting ready

First, we will learn about Redis and why it was created, before we look into other data stores available. Redis is an advanced open source key-value store that is capable of storing data structures like strings, lists, hashes, and sets. Redis, which means REmote DIctionary Server, is an in-memory database in which the whole data set needs to be available in the memory during runtime. It supports persistence by dumping the dataset as a file on the disk or by appending every command as a log. This single-threaded application is written in ANSI-C and the server leaves very little memory footprint. Another plus point is that Redis provides a very simple client protocol, which is similar to Telnet.

It is important we know the reason why Redis was created and how it scales when compared to other similar offerings.

Why was Redis created?

Redis was started by Salvatore Sanfilippo to improve and extend LLOOGG, which is a real-time website-analytics system. Once Redis became stable enough for production environments and grew in popularity, it turned into a standalone open source project under BSD license, completely sponsored by VMware.

Who is using Redis?

If you are a social or a technology person, you have undoubtedly experienced the fast performance of Redis. For example, Quora uses Redis to provide the front-page feeds and Twitter implements Redis for its deep-structured awareness. The list goes on with high-profile online applications such as GitHub, Stack OverFlow, YouPorn, and Craigslist,.

How to do it...

  • If your data is structured, predictable, and relational, it is best to use relational databases like Oracle, MySQL, or MSSQL

  • In the case of document-oriented records with the functionality to perform range queries, indexing, and MapReduce, check out MongoDB or a similar document database

  • If you are dealing with occasional data changes and want to run predefined queries on it, CouchBase fits in nicely

  • If you need single-site fault tolerance, scalability, and dynamo-like data storage, Riak is your option

  • If you are looking for a simple cache with less support of data types and better expiry algorithms, MemCached is the better choice

  • Redis was built to work with highly dynamic and nonstructured data with support for complex data types

There's more...

Redis is not an alternative to relational databases like MSSQL, Oracle, or MySQL. If your data is highly dynamic and updated often, managing the relational database tends to be a difficult task. Redis fits into this perfectly.

  • Redis serves as an excellent cache server—commonly referred to as "MemCached on steroids".

  • Redis is well suited in situations where performance is critical and the data set changes very often. This makes it perfect for leader boards and a statistics tracker.

  • Due to its Pub/Sub support, Redis can be effectively used as a multiprocess communication queue.

  • Redis can be used as reliable queues by taking advantage of atomic operations on lists.

If you are looking to use Redis as your primary database, you can check out moot.it, which is using Redis as its primary database and has attained incredible results (https://moot.it/blog/technology/redis-as-primary-datastore-wtf.html).

How does Redis compare with the competition?

It is important to know what we can do with Redis and it is equally important to know how it compares with other similar offerings in the market. So, in this section, we will learn how it varies in general and compare it with a few important NoSQL data stores.

Major differences

In general, let's see how Redis compares with other NoSQL databases and what it provides that makes it stand out from the group.

  • It supports more complex data structures when compared to other stores. It natively supports many fundamental data types, providing a rich set of primitives for manipulation of data.

  • Redis supports atomic operations on its data types through low-level APIs.

  • Being an in-memory database, Redis provides atomic operations with little internal complexity.

  • It has a low memory footprint of about 1 MB for an instance. The memory required by Redis to store overhead information such as type information and reference count, becomes trivial when compared to the stored data.

  • Redis is ACID-compliant (Atomicity, Consistency, Isolation, and Durability). Other NoSQL databases are not or are partially ACID-compliant.

Comparison with other data stores

Redis is one of the very few databases in which you can predict the time complexity for any operation. The server is being developed with performance in its DNA. So let us have a look at how it compares with other similar offerings in the NoSQL space.

  • MongoDB (http://www.mongodb.org/): Both MongoDB and Redis are built to serve different purposes and to solve different problems in traditional relational database systems. They are both popular and work well together. MongoDB is used to store persistent data whereas Redis can be used for temporary data for faster access.

  • Cassandra (https://cassandra.apache.org/): Cassandra is more optimized for write operations than read operation. An application that does more writes, such as logging systems, can take full advantage of Cassandra. It was built to manage data which cannot be held in a single server, whereas Redis is built to keep all the data in the memory of a single server.

  • Riak (http://basho.com/riak/): If you want to store dynamo-like data and are looking for no downtime, Riak is the best option. It is a very good fault-tolerant and scalable single-site data storage engine with MapReduce support.

  • MemCached (http://www.memcached.org/): While MongoDB is trying to replace relational databases, Redis is trying to do the same to the other end of the spectrum, MemCached. Redis performs better than MemCached in many benchmarks and can be easily validated using the redis-benchmark application, which comes along with the installation. The important and critical differences between MemCached and Redis are:

    • Support for replication in Redis.

    • Missing persistence support in MemCached. Even though there is a chance of losing some data in Redis, losing a small chunk of data is better than losing everything on server failure or restart.

    • Support for a rich set of data types in Redis.

arrow left Previous Chapter
You have been reading a chapter from
Instant Redis Optimization How-to
Published in: May 2013 Publisher: Packt ISBN-13: 9781782164807
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}