Redis Tutorial Part 3 – Redis Data structures and working with Node.js ioredis

Redis Data structures Key-value stores mostly support string keys and string data but Redis does a lot more than that. Redis is not just a simple key-value string store It supports complex kinds of data structures, not just string. We will look more into this property of Redis in this tutorial and see how to utilize this using Node.js and ioredis module. Get the ioredis module installed on your app from https://www.npmjs.com/package/@types/ioredis   1 String – Basic kind of string. Lets us say the name of a person. We will see how we can store this value using ioredis We set value bar into key foo using set and get the value using get.

2 Binary Safe String – Can contain any type of data represented as a string: PNG images or serialized objects, for example. Here we have a base64 encoded data of an image.We store this data in redis.Remember a value can’t be bigger than 512 MB. base64 of png – iVBORw0KGgoAAAANSUhEUgAAACMAAAAjCAYAAAAe2bNZAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4gUfFBM7nAl7igAAAPVJREFUWMNj1G/R/88wSAATwyACLMgcYzljojXefHmT4cvPLwzU1A93TJRpFEOZWxnRhj37+IzBa4oXA7n6b7y8wRAxJwK7Y3g5eBkYGBgYNl7ayPD843O8BmXYZjBI8UuhiMH0Ews0xDXwRxMDAwPDpoubGM4+OkvQMcM+AY86ZtQxo46hSXXAwMDA4Kfvx2AibzKwjvn84zMDAwMDg7+eP9HVATKA6SelOkEHjMhNCFJC5NmHZxgGUqqfcbQ9M9qeobQ9QyzA1Z4htj1EVHuGUkBJe2i0Ohh1zKhjRkZ7hlJASXuIhVrtEUrbQ6PtmdHcRA4AAAq6hb9r4YF9AAAAAElFTkSuQmCC

We can store buffer data as well in redis..

3 Lists – Collections of elements ordered according to the order of insertion

    4 Sets – Sets of data. Here we have a…

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 127.0.0.1 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…

Share this page in social media platforms