How can I get all prefabs from a Assets folder? Getting not valid cast exception in the editor.How to get all subobjects from a CustomObject with n Children/Subchildren and so on.How can I get all text nodes from XML file.How to get all files from a directory in Azure BLOB using ListBlobsSegmentedAsync.Get all values of a column from a DataSet.How can I get a username and password from my database in C#?.How to get all the user's details from Active Directory using LDAP.DEL and BACKSPACE keys get eaten from WebBrowser.How to get data from SQL database to store in to a combo box - C#.How to get the string array of all keys from the dictionary and modify every string in the same way.Get all keys (string type) with prefix from Redis in Stackexchange.Redis.If (!string.isnullorempty(responsecontent)) Var responsecontent = await distributedcache.getstringasync(key) This.distributedcache = distributedcache Īwait tstringasync(key, requestcontent) Public distributedcachecontroller(idistributedcache distributedcache) Private readonly idistributedcache distributedcache Method 2 public class distributedcachecontroller : controllerbase Meaning if your purpose is limited to set and/or get cache as a key-value pair, you would rather like to do it this way in method 2 below. the interface idistributedcache is been defined by the microsoft and supports basic/common functionalities by the different distributed cache solutions where redis is one of that. csproj above supports reids to be registered and injected in as a idistributedcache. ![]() ![]() Now the above is the use-case where you want access redis client and do more redis specific stuffs. could have more reids supported operations here Public iactionresult getlistcachekeys( string pattern) ![]() Public async task deletecachebykey( string key)Īwait multiplexer.getdatabase().keydeleteasync(key) Var requestcontent = data.json() // rializeobject(data)Īwait multiplexer.getdatabase().stringsetasync(key, requestcontent) Public async task postcachebykey( string key, object data) Var responsecontent = await multiplexer.getdatabase().stringgetasync(key) Ĭntenttypeheadervaluejson // "application/json" Public async task getcachebykey( string key) public class rediscachehelpercontroller : controllerbase Here are the helper apis to demonstrate how can you use the iconnectionmultiplexer. Public rediscachehelpercontroller(iconnectionmultiplexer multiplexer) Private readonly iconnectionmultiplexer multiplexer So, having the above stuffs in place, would be able to inject the redis iconnectionmultiplexer into your controllers or services. you can have your own way here for that or you can hard-code it here if you like to begin with. nfiguration = dbhelper.getredisconnectionhost(options.isdevdb())ĭbhelper.getredisconnectionhost(options.isdevdb()) :> is my way to resolve the connection information/string for my redis instance respective to my environment. Services.addstackexchangerediscache(options => used by : sample below : distributedcachecontroller (method 2 only) used by : sample below : rediscachehelpercontroller (method 1 only)Ĭnnect(dbhelper.getredisconnectionhost(options.isdevdb())) Public void configureservices(iservicecollection services) Next step would be to try a faster serializer ( Protobuf?).Īny thoughts? I am interested mostly in code design rather than performance aspects.In startup.cs this is how you would be able to register redis client ready to be injected in your workflow code. This seems to work fine (caching spares significant database processing time), although I have not performed any parallel testing (multiple threads accessing this functionality). GetQuestionFullInfo_Answers(questionInfo) GetQuestionFullInfo_QuestionComments(questionInfo) Public async Task GetInfoThroughCache(string key, int expirationSeconds, Func computeData) Redis = ConnectionMultiplexer.Connect("localhost") Public RedisCacheService(ILoggingService loggingService) Private static readonly object SyncLock = new object() Private ConnectionMultiplexer Redis = null RedisCacheService.cs - the generic service that allows other services to transparently use the Redis cache public class RedisCacheService : IRedisCacheService allow services to transparently get and set data through cache: just provide a key, a function to construct the data if not in cache and an expiration period.I have developed a small ASP.NET Core 3.1 Web API that provides information that is rarely changed (several times a day) but often read (~ 10 K / day).įor me, it is a good opportunity to toy with Redis Cache and the Stack Exchange client. This is an unanswered code review request of mine from Code Review Stack Exchange.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |