Mark As Completed Discussion

How Do We Actually Use Redis?

Every data point in the Redis database is a key followed by one of many data structures. We can store data naturally like we would in our favorite programming language instead of sticking it inside a bunch of tables or documents.

To interact with the database we can use a simple set of commands like SET to create a key with String value:

SNIPPET
1SET hello world

Here the key is 'hello' and the value is 'world'. To read a key we use GET followed by a key

SNIPPET
1GET hello
2> world

Redis has a key value store that supports storing multiple types of data as we have discussed. We can extend that with Redis Modules which are dynamic libraries designed to help us adapt our database to our data rather than the other way around.

How Do We Actually Use Redis?

If we are using ElasticSearch, for example, we can use the RediSearch module or the RedisGraph module for graph data storage and so on.

By running our database on our main system memory you may be asking yourself: "how does Redis protect data against data loss?"

One way is by replicating instances. This way if the master Redis instance goes down we still have a few instances left with all the data. But if all the instances go down we will lose all our data, so this is not an ideal solution.

When it comes to keeping data intact, Redis uses multiple mechanisms to persist data:

  1. Snapshots (RDB) produces a single-file point-in-time snapshot of our dataset that will be store on a disk
  2. Append Only File (AOF) logs every write operation continuously and when restarting Redis it replays the AOF to rebuild the state
  3. Combination of both combining both AOF and RDB which results in better data persistence

If we wish we can also disable data persistence completely, by doing this our data will exist as long as the server is running.