Join us for RedisConf and Hackathon, April 20-21
If you’re familiar with relational databases, you’ll no doubt have written SQL queries to relate data between tables. Redis is a type of database that’s commonly referred to as No SQL or non-relational. In Redis, there are no tables, and there’s no database-defined or -enforced way of relating data in Redis with other data in Redis.
It’s not uncommon to hear Redis compared to memcached, which is a very high-performance, key-value cache server. Like memcached, Redis can also store a mapping of keys to values and can even achieve similar performance levels as memcached. But the similarities end quickly — Redis supports the writing of its data to disk automatically in two different ways, and can store data in four structures in addition to plain string keys as memcached does. These and other differences allow Redis to solve a wider range of problems, and allow Redis to be used either as a primary database or as an auxiliary database with other storage systems.
In later chapters, we’ll cover examples that show Redis being used for both a primary and a secondary storage medium for data, supporting a variety of use cases and query patterns. Generally speaking, many Redis users will choose to store data in Redis only when the performance or functionality of Redis is necessary, using other relational or non-relational data storage for data where slower performance is acceptable, or where data is too large to fit in memory economically. In practice, you’ll use your judgment as to where you want your data to be stored (primarily in Redis, or primarily somewhere else with a copy in Redis), how to ensure data integrity (replication, durability, and transactions), and whether Redis will fit your needs.
To get an idea of how Redis fits among the variety of database and cache software available, you can see an incomplete listing of a few different types of cache or database servers that Redis’s functionality overlaps in table 1.1.
|Name||Type||Data storage options||Query types||Additional features|
|Strings, lists, sets, hashes, sorted sets||Commands for each data type for common access patterns, with bulk operations, and partial transaction support||Publish/Subscribe, master/slave replication, disk persistence, scripting (stored procedures)|
|memcached||In-memory key-value cache||Mapping of keys to
|Commands for create, read, update, delete, and a few others||Multithreaded server for additional performance|
|MySQL||Relational database||Databases of tables of rows, views over tables, spatial and third-party extensions||SELECT, INSERT, UPDATE, DELETE, functions, stored
|ACID compliant (with InnoDB), master/slave and master/master replication|
|PostgreSQL||Relational database||Databases of tables
of rows, views over tables, spatial and third-party extensions, customizable types
|SELECT, INSERT, UPDATE, DELETE, built-in functions, custom stored procedures||ACID compliant, master/slave replication, multi-master replication (third party)|
non-relational document store
|Databases of tables of schema-less BSON documents||Commands for create, read, update, delete, conditional queries,
|Supports map-reduce operations, master/slave replication, sharding, spatial indexes|