Intro To Redis using a simple C# Application

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone today we're going to talk about redis we're going to see a console application written in c-sharp and you're going to see how important red is is for nowadays applications and how easy it is to integrate with the redis using c-sharp okay but before you guys start coding let's understand what's redis where is open source in memory key value data store that stores the information usually in a hash table format writers offers the possibility to store different types of data structure such as lists strings hashes sets sorted sets video maps and others if you guys go to the redis website we're going to see all the data tabs that redis can work with and listed over there okay so the most common use case is for redis is basically as a data caching message service and a session store there's another scenario where redis can be used and I'm going to let you all search a little bit about it but now I'm going to show you a little diagram that I'm going to clarify basically how red is this important and how the cache mechanism is important and right this is a good way to go to it okay right here you have your computer okay I have a user using a computer then requesting information for application for example Google okay then the applications are going to database to get this information okay but when you hit a lot in the database you can you know slow the performance of your application then a good mechanism as a caching could be a good implementation for replication rely on okay so instead of go to the database all the time you should consider using a caching mechanisms for informations that are basically assessed all the time okay then we are going to preserve our database we're going to save some resources and hitting the cache the cache is the mechanism that basically the information that you want is the in-memory basis so it's quite easy and fast to be accessed okay so grab the information from the cache then you give it back to the client that requested it okay basically that's the mechanism of caching and I'm going to show you in terms of code how easy it is to integrate with redis okay let's go to the code okay right now I'm going to get a up and running instance of red is in my machine okay basically I'm going to use a Docker to have things easily okay so right here I'm going to use the document comment in a detached way okay and I'm going to name my instances my local instances local radius okay and I'm going to run it in a 63 1790 Port okay and right here that's the image's name okay they're going to be grabbed from the docker hub in the cases that you don't have it locally okay so let's type this comment in press enter then locally I already have the radius image okay so in your machine in the case that it doesn't have it it's going to be downloaded from the docker Hub okay and now you already have a wrapper running instance of radius okay so easy like that okay now I'm going to connect to it just make sure that it's running and right here I'm using the radius desktop manager okay so let's connect okay it's okay it's already here up and running let's go to the C sharp chord right now okay now one of the first things that we need to do is to download the redis library from the management of each packages okay we have to right click and the project then click and manage nugget packages okay then I'm going to search for radius okay that's the first Library enlisted and we can see that it has been downloaded more than 243. million times okay it's a quite popular library right here okay now we are going to create a class a helper class actually they're going to facilitated towards the communication with the local instance of redis okay red is helper let's call it okay and in this class we're going to use a static Constructor okay because we need it to be called just once okay and right here we are going to called a method from the class named multiplexer right here connection multiplexer okay it's got a method of the name of the connect these methods are going to be responsible for our connection to the local redis okay now we're going to place a connection string localhost and the port number is 63 79 okay then we're going to have our connection okay we're going to create a private static property right here right or hold the database we're going to use an interface from the library named idatabase that are going to be called this I'm going to call this field database write this database ready database okay this field I'm going to receive an instance of the database red is database okay so I'm going to call it get database right here assign it to this field okay and I'm also going to create a property right here a publicly property actually that are going to be used outside of this class okay it's going to be a a get accessor okay and I'm going to return field redis database okay now it should be all okay basically we are using right here a static Constructor okay and inside the desired Constructor we're going to connect to the Reds and then we are returning a database a redis database okay to this we're assigning it to this property okay and then using this property we are going to return it okay it must be a public because our code are going to use this static property okay database we're going to refer to it right now okay so outside the class we're going to call this class and static property named database okay I'm going to call I'm going to create a variable named cache okay and this variable are going to have a method named string get sync okay this guy right here are going to be responsible for get a specific key that's already existed in our radius instance okay that's already stored in the radius we haven't set anything so we cannot get anything yet okay let's first um call [Music] set string set is a c okay we are going to pass a key let's call it I don't know um our key okay and the value of it are going to be my name for example Jordan okay and right now what we're doing right here basically is setting a key inside the radius okay so basically restoring it with the name r key and its value are going to be Jordan okay and right now I'm going to get this value so you should pass through this method this string get async the name of the key then its name is R key in our case okay then I'm going to grab it the value okay I'm going to await for this because this is a sync operation okay so now right here we have setting and right here we're getting the information okay and I'm going to put it put it out in a console right now okay it should be all let's execute this code and now we should see in the output the valley Jordan okay so let's run the code and see if it works okay it works properly what's happening right now it's setting our key with a value Jordan and it was got from this called right here and put out an account so okay so that's basically how the radius works how you should use using a c-sharp application it's a simple example so let's make it a little bit more complex so I'm going to create a for Loop starting with zero okay I'm going to let this Loop run until it hit its limit it's going to be 100 for example okay and now we are going to set a hundred keys [Music] okay I'm going to place the name of the key right here our key um underscore the number of the key okay it's quite simple implementation just for testing purposes okay R key and then number at the end of the name of the key I'm going to replace the number of the loop okay the counting of the number of the loop okay and the value I'm going to B Jordan underscore the number of the loop okay now we are setting [Music] and we should get all the keys as well and place right here [Music] develop that should be placed in our Auto output let's just get right here okay now it's just getting it should be all let's see in our console if everything works fine and everything works fine and we are going to see in our red is desktop manager [Music] right here all the keys is right here in its value is the right side right here okay so we can see that everything is working and you can see how easy it was to integrate with redis and you work it works pretty fine okay I want to let you all know that there's a lot of possibilities in this Library okay because we could have deleted Keys it could have um passed as a parameter for this string set at sync a timeout for the keys then red is deleted automatically after the past and the time of the timeout so it's a lot of possibilities a lot of flexibility in this Library you really need to get some reading about it okay I really recommend that okay that should be all for today and I hope you guys understand how important redis is and how easy it is to implement using C sharp and for now these applications it's quite common to be used red as a caching mechanism and you guys really need to understand how right this works it's a simple implementation that we made today but I really recommend that you y'all have some books and other tutorials or videos about reddits you know because these backgrounds is really important nowadays big companies really usually used radish and it's a top-notch tool to understand and to Master Okay so I really recommend more reading about it okay that's all for today I hope you guys like the video make sure that you subscribe this Channel and see you guys in the next video
Info
Channel: Jordan Code
Views: 797
Rating: undefined out of 5
Keywords: .NET Applications, redis, cache, caching, redis database, database, key pair, .net, docker, performance, software, DB, c#, application, data, data store, redis tutorial, banco de dados, .net core, redis wordpress, redis db, redis labs, development, software engineering, cloud computing, data structures, sql nosql, sql, nosql databas
Id: REy3OqWu80U
Channel Id: undefined
Length: 13min 49sec (829 seconds)
Published: Fri Apr 07 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.