Redis and Redis Sentinel Crash Course - Redis Commands and High Availability tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I am El Camino sequel series in this tutorial we will talk about Redis and with this santino there is plenty of different traders articles and YouTube videos out there but I wanted to share my experience as a developer by creating an own in one proper video covering the most essential and important stuff that is needed and helpful for developer or leave ups engineers to build highly available Redis cluster with Santino in the first part of this tutorial we will talk about radius and its use cases who is using radius in production and with the Sun you know in the second part we will install Redis using docker and docker compose we will see the most important commands and also the slave master and reduce Sentinel configuration some what is read is with this according to the official website is an open source in memory data structure use it as a database cache and message broker that offers high-performance replication and then a unique data model which was like replications processors and client-side Chardon allow readers to scale from a convenient way to prototype a system all the way up to hundreds of gigabytes of Terra and millions of reads and writes per second where this is a type of database that is commonly referred as no sequel or simply non rational and register is no tables and there is no database defined or enforce it way to relating data with other data in Redis radix can be used for a variety of things including application configurations session store items sold in Japan called HTML fragments or Jason fragments queues or tasks Scotland metroid billing social networking gaming and geo hashing etc etc it could be a really good question to ask you is using Redis in production well many tech giant's and when known companies are using with the center production twitter for example I was in more than 10,000 instances in one of the most important service which is which is the time line we have also in the list github Pinterest snapchat Craiglist and Stack Overflow and many many many others you can check the full list and tech stocks vijaya you Redis Santino is the solution offered by Redis in case of a failure in your Redis cluster Santino will automatically detects the point of failure and bring back the cluster to stable mode without any human interaction in a nutshell Santino always checks the master and slave instances in the Redis cluster checking whether they are working as expected or not f17 all detects a failure in the master node Santillan will starve a level process as a result Santa will pick a slave instance and promote it as a master and the other remaining slave instances will be automatically configured to use the new master instance one more important thing and for the sake of clarity the quorum is the number of Santino that needs to agree about the fact that the master is not reachable in order to really mark the master as failing and eventually star available process if possible however the quorum is only used to detect the failure in order to actually perform a failover one of the sentinel needs to be elected leader for the failover and be authorized to proceed this only happens with the vote of the majority of social processes in this example two nodes out of tree must vote that there is an issue with the master node to perform a failover process you after installing the current docker compose please open the terminal I will go inside my public folder and create your array this folder inside the Redis folder I creates a docker compose file sorry compose file dot yml I will create a directory called data inside that style put another folder called master and thoughtful forgets the - P I will create also a master of iteration come rights and they will open that in my text editor Perfect's I will get back to Google and look for a default configuration for radius here it is I will copy past it in my master that configuration and here three Street three important things the first one is the boiling by default Reedus is local but I will to to expose it to the public one more important thing is the append-only yes that should be yes and the append a sink right I will get back now to the docker compose and create my first cells I will use the version number three and I will create my first service the first service I would call it master server this master and the container name will be really smart already this master alright the image is the latest version I will use the latest version of Redis you can use any version you want for the ports I will expose the default one no need to charge us that three six nine seven nine yep we'll use the default one command I will leave it empty for the moment I will get back to it in in seconds and for the volumes I need to sync with a local with my local folder in here I will simply hold the data all the ready Stella I wanted to be here inside theta and master so by default the release data are stored in / there and I want something else I want this config master to override the directory this configuration I will try master that calm I want a PGCE sorry OTC reduce that conf effects okay now I will give back to the command and they will ask three the server to use this particular configuration and now we are all set let's get back to the terminal and type compose up oops seems like I forgot unless in services yep we type to compose up and now it's good and now I will open a new terminal and type Locker PS I can see a lot my container is created I will try now to access it docker compose exact reduce master and bash good now I am inside the container I will try pre this cell I and I am in for the comments info gives you all details about readers you can you can see about the replication CPU classroom memory and so on what interests us the most is info replication it's very application I can see clearly that my that's my read this is a master and there is no slave connected keys it's a command that we will use a lot in this tutorial it simply display a list of the keys or the available case depends on a rejects for now we use a star we can use any type of projects that we like and we will see that in few seconds set set is a key that will allow you to keep to create a new record for example I can type first name and I will give it my first name to get the value of my first name simply type get and then the key name and here it is if I want to update the same record simply type retype it again and write the new name if you have a value that contains spaces or other characters but it's better to use codes or double quotes nice let's get the same key and here it is it's it's update I will create another one using sets command I will call its last name and I will put my last name I will use keys with the rejects of star to get all my at all to get on my keys I can use like that to get all the keys that answer with the name I can use something else like blah blah it's a thing that I don't have right now so the reader said that there is the list is mg how display everything using us using a star and use a command called exists I will use email as an example with this now we will change the zero that means the email doesn't exist I will try with last name and exists returns one expire so expire is a command that will help you to delete a variable after a number of seconds for example first name after 10 seconds I will display the lists of the variables I can see clearly that the first name exists after 10 seconds this variable will disappear there you go I will see that again first name offset my name I will set another one called email and they will give it an example and test.com and I want I will just expire again for this email to expire after 300 seconds the TTL is a command that will help you to keep track of the seconds left for a variable now it's 293 now it's only 281 if you try to update it like soufiane odds test touch one you will see that the timing is set to minus 1 and minus ones mean that it won't expire simply because sets its erase everything and starts from from scratch set X is a command that combine the two command sets and expire for example I can use a new rival called H I will set a expiration to 400 and the value of 31 okay the same let's display the keys nice here is the age let's type now the TTL of age so it will expire after 389 right set in X or simply set if not exists have two functionalities first if the key doesn't exists it will create it and if this variable exists it won't be able to update for example the first name exists already so I won't be able to update it to blah blah blah I would get the value of value of first name you see it's still sofyan and it's not blah blah I will create a new variable using the exact same command it's called year of birth and I will set it to you this number and if we get the list of the variables we will see that this variable has been created if I get the year of birth you will see that is set to 1989 if we try now to react data it uses in a set and X won't be able to change this value birth let's say mm I would get its value so it's not updated so it's in sets in eggs so sit if not a exists it's a good command if you want if you don't want to update your your your keys [Music] Ian's CR or sense for increments 8 increments a numbers for example we have the age I will try to increment the age it was 13 tomb and now it's 33 if you convert it again it will be 34 if you use increment by for example I will put a hundred you see now that the age is incremented by a hundred if I told again now it's two hundred and three hundred you can use - - numbers and they will see that it decremented documents is a command that's helped you to decrement a variable or a number and the equipment by is a command also that you can use to decrement by a different number than one age document by two hundred right so the age is 30 I will create a new variable I will call its full name and then we give it only my first name happened is a command that will help you to append a string to another string I will use the same variable for name to append soufiane or my first name with my last name if I get the phone name value we will see that it's happened right so we saw that gets can help us to get any key that or the value of any key that we want but we can't combine multiple electrical keys multiple gets or M gets help you to do this you can use first name and last name all in the same query and the order is respected if you can get multiple values you can also set multiple values I can say key 1 and the value is 4 for 1 and T 2 and the value is valve 2 let's display the lists and there you go here's key 1 and it is key the key to let's get them both get to the letter variable or a key type del and del you can use one or multiple variables hashes so hashes are a bit different from strings for me there are more importance I use them really a lot in my in my projects in my company and to use the hashes simply simply type page four for hashes and then has sets the key I will use user one as a key and the field I will use first name and the value is my name I will read the word I once again I would has to use the last name and here is my last name email and then test.com I will create another hash for user number two first name is Bob first name joy its first name like this first name is Bob last name is I don't know and age I suppose it's 20 okay let's browse the list of the variables I have user 1 and user 0 to get won't help us because it gets it's for Strings and now we are using hashes to get a hash simply use H get and the name of the field I will display only the first name okay to display multiple to display multiple fields simply type H and get on multiple gets and now you can grab the last name also and the email right I will do that what user number 2 sorry and get user number 2 and they will ask for last name and email there you go the the email doesn't exist in the user chip I used only the H if I remember correctly H get alt will get will help you to get all the fields of a key for example user 2 and there to give you and that will give you the the field name and its value just like that I will get now the user number 1 and there you go HM said we'll help you to create multiple fields instead of doing it multiple times you can try with user number three so first number first name will be let's say Alice last name will be I don't know and the age I don't know she didn't kill me okay let's get everything from user three and there you go first name is others last name as I don't know and the H is she didn't tell me each set you can use it again to update any value I will update the age of user three I will use eight updated to 25 you know it's good it's updated now I can increment a other's age its user 3 and the H is the field that I want to increment and I want to increment it by 1 each increment by user number three its Alice and they were recommended by one so which was 25 now it's 26 documents by 10 and now she's older now she is 36 now you can increment it by a minus 2 and now she is 26 [Music] you sets Assad is our command that will help you to add a member to a list it's in order to erase but a bit difference I will say the last name is color and I will add the blue okay and now I will add blue red and green and yellow right s members I commented that will help you to get all the elements from all members from this set now we can see that the blue yellow and green even though I've set it twice so we can see only one s God give you the count of this set it's 4 and s is member help you are to find if a if a member exists or not for example colors let's check the black if exists or not it's zero now we'll try with red red exists over this returns 1 if you want to delete a member simply type s s room or remove s remove I will remove the yellow and I will display everything using s members and the key is colors we can see now that yellow did is his disappeared you sets are best are a bit different from from normal sets offsets this are with desi so it says it add name my volleyball teams and the the the number one is let's say the team's okay it's for example if Barcelona and my second one is Real Madrid okay and number three for me is PSG or person Gemma okay to browse the list of my older it sets I will try Z range the key is team and I will browse from the zero to one I can see that FC Barcelona and Real Madrid if you type zero zero you will give me the first value and then the second tourney of value and then the third value you can type zero minus one to get all the values and there is a good command also it's called with scores it will help you to display the number and it's and it's score also right right to remove a member simply write the drum and from team I would remove PSG to display everything now with the score so still have Barcelona and Real Madrid pub/sub up so subscribe I tell it will help me to subscribe to a channel the channel that I will subscribe for I would call it a chat and I will keep it listening I will give back to my previous to my previous terminal and I will publish a something on the channel I will use the exact same channel that called chat and they will the rights hi and I am here okay get back to the previous all to the subscriber I can see my my my message okay I was published something else so in the shot also I wonder I you there right let's get back to the subscriber I can see clearly that my message is received now I will close the connection and I would push the exact same message now with this told me that the message didn't didn't receive ok so what's kind of display is zero here so if the message successes then radius returns 1 if not it returns zero we can try with for example let's say another channel called notifications ok so if there is no subscriber so we this would return zero so there is a pub sub or publish subscribe it's a really good good feature that can help you do the queuing it's really is really fast and many companies use this I personally don't use it I use RabbitMQ and cafe how it depends on the project that well I'm working on but some companies like very much reduce queuing and I think it's it's gonna be I hope for you to know it's when this also support actions it starts with multi it's two methods to multiple comments to start a transaction now I can set a new variable okay user one email okay I will use Q 1 value is valve 1 it's something that it doesn't exist in here so it's Q it I will create another one 12 - lets get you to commit simply type exact and todayit's let's this let's display only the list of the keys I can see that key 1 & 2 are are inserted I will start a transaction again with multi and now I will delete k1 and k2 and this time I will type this card okay I hope display the list of the variables I can see clearly that's my keys hours of it just because just because I wrote back my changes now if I delete them and commit k1 k2 and commit using exec I will see that the k1 and k2 and k2 then no longer exists in my database for the connection we need to update the configuration I will get back to the you master that conf and I will look for required bass here it is it's commanded I will remove the command and I will use a password simple one and I will reboot my my wrists nice take it back to reduce align good so now I will try now to browse all the keys and tada there is a identification process before I get anything from the database I will try to get the key one for example and I will get the exact same message to authenticate you should a use of and here you can type your password I will sit at home and here is the message for wrong passwords if I use the word the right password and you can see there is ok and now if I type key star now I can see everything I will remove the password and reboot again good let's start from scratch and there is this samurai and now the password is removed there is also a good command that you need to know in it's a good command to see if releases happened running or not there's also a selects comment normally or by default read this so all the all your keys in a database called zero let's check that we are in database called zero if we change that to the database number one and type keys star you won't find anything by default you this have 16 database you can pick any one you like so this is all you need to know about reduce comments if you know about strings hashes list sets or older sets then you are ready to go to start a project and now we will see how to to create a slave I will duplicate this block we will reuse it and I would call it user slave the same for the name okay I will create a new config file I will call it slave dot-com and the data will be I needed to be synced inside a slave a slave folder ok let me create that to create anyone ok inside Tara and let's creates the slave folder good so the slave now is using there are slash slave and let's duplicate that and normally the configuration should be the same except for one thing it's the replica of a here it is and line 286 I will remove the comments and the IP address I would use the container name instead it's reduce moisture and the poor is the by default one it's 63 79 and that's all we need I will double check the configuration the name is correct of the host is correct the name is correct poor is correct with this config volumes its slave and the configuration is a slave rights okay I will relaunch it again okay what's wrong with that right open slave build on this mmm-hmm yes this is correct I forgot about that I will use the port number 18 instead I will redo it again and yeah it worked okay I will remove that and the other also and so from scratch now I will connect to the master three this semi and display the info replication remember that okay let's say is that this is the master and there is a slave connected I will now enter the slave one and use the Saba and for replication and it says that this one is a slave and the master is the matter with this master okay if you are using an IP address then the IP address B you will see it in here there is one thing which is really good if you type Keys star will find the exact same database that you have in master and they are in a complete sync let's demonstrate that even more I will delete the year of birth birth it's written like this and the full name good let's display the list again and you will see that it's instantly disappeared see they are in complete sync one thing about the slave is that you cannot set anything let's say because it's my first and my last name the the slaves in readers are are read only you can only read from Rodriguez and you cannot write on your because you know you can only write on the master you can also read from the master and from the slave you can only read I would set a new variable for you let's browse the keys here it is here it is Sophia now let's get it and here it says there are in the complete of sorry so and we are good about their replication so now we'll had you know our grades I will cover through this Sancho contain our name it's gonna be the same I like to call it the same Santino search for the image image I will use also with this I remember correctly that there is an image only for that which is much lighter but I will keep using radius it's not it's not a blocker you for the command I will live at ng usual and start with the volumes for the volumes I need a config file that's a we'll call a Santino that conf and I want it dots and I wanted to be an ET ce sont you know that comes this configuration is not yet available I will add it right now here it is and I will do great to get the default the default Sentinel configuration here it is I will copypasta - and here it is now I can past it and to adjust the variables okay so the most important thing is the its line monitor something yeah it's mantener monitor my master and I will give it now the master master IP or name here it is this is the corium I don't know how to promise you that what's its volume yeah the corium since we are building only once and you know the vote should be only by by one machine or radius recommends using three sentinels in parallel or at the same time but for this tutorial we will use only one since Sentinel instance and of course the the number of votes I need only one machine to vote for me so for the down after milliseconds for this tutorial I will use only three seconds one thing brother sing I will keep only one I why because I have only one one slave the failover only three seconds that's all I need in this in this configuration and photo command use radius server and they will ask it to use HTC Sentinel that Cove and flag Santino and ever had depends on first from the radius master andry this slave good [Music] good and success the master wait a semi and check the replication yes who is a master and there is one slave let's access the slave now through this cell I type in for replication the occasion sorry and there is a slave and the master is this woman okay what I will do now so this is the master and this is the slave I will create another hole open another time you know and I will kill the master intentionally so since you know master is the second one we copy that I would've type docker stop and I will kill that intentionally so let's check that I have only the Sentinel and slave and we'll all three type in for replication and now it's jump from slave to a master and there is no slave connected just because like it swapped the roles these slaves become the master and I have no access to the slave right what I will check what I will do I will track the database I still have everything okay I will add couple couple values value sorry Volume one and two and three okay let's check the list okay here is number two is number one and okay what I will do now I will star my machine poor master machine and let's see what's gonna happen I will sign out there release master oh the old master let's check that using docker PS I have now my master and slave this is only names that are we give to to the machines if now I access team master and display the sorry SMI and display the m4 applications of the replications info this master of the old master become a slave right if I type keys I find that the hero's key to key 3 + k1 so use your business still keep up and running without any issue so Sentinel did the job it's true that it's not recommended to use one we should use three but yeah it's working and that's thanks to the Sentinel that handles this failover for us so that was it that's all you need to know about Redis we sell together the most important commands like strengths ones hashes transactions and publish and subscribe we sell how to configure master slave and Sentinel we experiment at the high availability and failover together and please don't forget to Like and subscribe if you like my videos thank you
Info
Channel: Code Academia
Views: 17,913
Rating: undefined out of 5
Keywords: redis, redis tutorial, redis database, redis cache, redis crash course, redis sentinel, redis high availability, redis sentinel high availability, sentinel crash course, sentinel tutorial, sentinel failover, redis replication, redis slave master, redis slave master tutorial, redis master slave tutorial, redis docker, redis docker compose, sentinel docker, sentinel docker compose, redis hashes, redis strings, redis pub sub, redis queues, redis transactions, redis sets
Id: -a07Ief51H4
Channel Id: undefined
Length: 47min 29sec (2849 seconds)
Published: Mon Feb 03 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.