Redis Tutorial Part 2 – Redis Sentinel and master/slave usage with Node.js ioredis

Redis Sentinel  System designed to help manage Redis instances. As we discussed earlier, one Redis instance can be master and other instances can be slaves. The slaves can have exact data copies of the master server. The master will have replication ID. The biggest advantage of this architecture is that the slave can act as a master if the master fails. Redis Sentinel is the system that helps to make Redis instances with High Availability (HA) by managing failovers. Redis Sentinel Does the following jobs Monitoring – Checking if your master and slave instances are working as expected. Notification – Notifying something went wrong. May be via an API. Automatic failover – If a master is not working as expected, Sentinel can start a failover process where a slave is promoted to master     The configuration file for sentinel is sentinel.conf  redis-server /path/to/sentinel.conf –sentinel   In the sentinel.conf file, there is a line like sentinel monitor mymaster 6379 2 quorum – 2 This line determines which master the sentinel is going to monitor. The number 2 is called quorum. The number determines how many sentinels need to agree that the master is having a Failover so that the slave…

Redis Tutorial Part 4– Redis Data structures setting expiration time for key with Node.js ioredis
linux , databases , redis / April 24, 2019

Setting  expiration time for a data in Redis Consider an object which contains name and type. We store this data in Redis using the Redis hashes data structure.

We store this data into a key called listdb using the following code

hset is used to set a key and corresponding value in the hash.   Now we set the expiration time for  key listdb using expire

In this code 60 represent the expiration time in seconds. You can change this value as you want On running this code to get the value after the 60s will give empty data

hgetall will get all the values  for key listdb Running this code before 60 s will give a result like this


Share this page in social media platforms
Download Formatting took