Getting started with Redis
I had used Redis in the past for my personal portfolio which is encapsulated by the ORM layer provided by Ruby on Rails, therefore I decided to spend a bit of time to learn on the CLI command. For me personally, Redis is just like MongoDB as there is a key value store pair, but the advantage of using Redis over MongoDB is the Read and Write performance.
Video on learning Redis
Traversy Media provided a really great video tutorial on how to get started with Redis! This is just my notes on learning Redis.
Installation
Redis support cross-platform, check https://redis.io/download for more details.
For mac user, simply just run brew install redis
. For linux user, apt-get install redis
. For windows, you need to download the .msi
file on the official github repo.
Start redis server
Start the server with just the command redis-server
Start CLI
To start the CLI, simply just run redis-cli
, where in this Command Line Interface (CLI), the command (the key value being set are case-sensitive) are not case sensitive as shown in the image below.
Useful command
clear
flushall
- clear the database
Redis Setting up data and getting data.
In redis, to set data, we use SET <variable_name> <value>
, and you can get the data with GET <variable_name>
simple as that.
Set data to be expired
One cool feature of Redis database is that it can set a data to be expired in a certain amount of time.
Set a key to be expire
Initialize a key to expire in some time
TTL is a command to check how long the time left for the value to expire.
PERSIST
By using PERSIST command, you can make a value that is set to be expired to be persist data.
MSET
Set multiple key-value pairs
APPEND
Append operation will append the new value after the old value.
RENAME
change name of a key
RENAME test test1
LIST
Push from the LHS
Push from the RHS
POP
POP operation can be chosen from LHS or RHS with LPOP
or RPOP
, where it will remove the leftmost or the rightmost value in the list.
e.g.
> LPOP people
lai
> RPOP people
test
EXISTS
exist command works in both string and list.
> SET a 1
> LPUSH b 2
> EXISTS a
> EXISTS b
Conclusion
This is enough for me to work on Redis server already, the command seems to be much more simpler and cleaner than MongoDB.
你好!才子,才女,你参加月旦评了吗?有才的人都去参加了呢。倘若你想让我隐形,请回复“取消”。
You’ve been upvoted by TeamMalaysia community. Do checkout other posts made by other TeamMalaysia authors at http://steemit.com/created/teammalaysia
To support the growth of TeamMalaysia Follow our upvotes by using steemauto.com and follow trail of @myach
Vote TeamMalaysia witness bitrocker2020 using this link vote for witness