# Redis 101: A super fast in-memory database

Redis is one of the fasted in-memory databases out there and very much different from the traditional SQL/no-SQL databases. Initially, it was developed for caching, but the simplicity and speed take it to a completed in-memory database.

### Why Redis

When we compare this Redis database with a traditional database, it is similar in a way,

- Persist data for applications
- We run queries and fetch data

But it does the job super fast of storing and retrieving data on the database by using the computer memory.

> Redis is a super-fast temporary database, that uses computer memory, not the HDD or any other permanent storage hardware

Redis is fast, because,

- All data is stored in memory
- Use a very simple and straightforward data structure
- Provides limited features for querying data

Redis narrowed down the data structures in it into LinkedList, hashMap, or set type structures.

So **Redis is fast because it is simple**.

### Design Methodology

This simplicity brings a couple of challenges during we design a database,

- Fitting data in a limited amount of memory
- Make use of simple data structures to persist data
- Utilize the database with its limited feature set

Redis has the following data sets,

- String: Plain string or number
- List: List of strings
- Hash: Collections of key values
- Set: Set of unique strings
- Sorted Set: Set if sorted unique strings
- Bitmap: Kind of collection of booleans
- HyperLog: Kind of collection of booleans
- JSON: Nested JSON structure
- Index: Internal data, used for searching

It does also support concurrency with the `watch` and `lock` method.

For traditional databases, we design the database as follows,

- First, we persist data in tables or collections
- Determine what query we execute depending on what data we required

With Redis, we took the reverse approach,

- First, figure out what queries we will perform
- Design data according to that query

A couple of additional concerns with Redis are,

- Types of data we are storing
- Should we concern with data size (for example, static page/dynamic page)
- When do we expire the data
- How do we name the key
- Any consideration of business logic

### Final Thoughts

When it comes to a super fast in-memory database solution, Redis can be a no-brainer. Apart from [Redis](https://redis.com/) itself, all the major cloud service providers have managed Redis service.




