Redis: The Basics
Redis is an open source NoSQL database. It was first released in 2009. Redis is not similar to MongoDB and is different from postgres and MySQL. It does not have tables and documents. Data is stored inside key value pair. It is not helpful for storing structured data.
Unlike a normal database, Redis runs inside the working memory or RAM and is incredibly fast. It is volatile and you can lose the data if your system crashes unless it is backed up. Redis is mostly used for caching and used for things that are accessed a lot and takes a lot of time to calculate. It is a lot faster than traditional databases. Redis is 100/1000 times faster than traditional database querying.
It is very easy to install Redis on your machine.
On a Linux machine:
sudo apt-get install redis
On MacOS, you can simply use Homebrew to install Redis:
brew install redis
After the installation, you can initiate Redis with redis-server
By default, redis-server runs on port 6379. You can use redis-cli to access the redis terminal on your machine.
Frequently used Redis Commands (inside CLI)
Redis stores data in string i.e., inside quotes. The SET command is used to set the string value of a key. The GET command pulls the value of the key.
The DEL command deletes the key. The EXISTS command is used to check if a key exists or not.
The KEYS * gets all the keys present. It is a great way to see what is present in the database. flushall deletes all the keys, clears the entire cache.
For a list of the commands, you can visit the official page of the redis.
To check if the redis server is running (you will get PONG as response if the server is running)
You can uninstall redis using:
brew uninstall redis