Benefits of Redis over the C # Dictionary

I am wondering what are the benefits of Redis with its C # client over Dictionary / ConcurrentDictionary and otherwise.

I'm not sure if using redis is considered redundant to store dictionaries.

Thanks.

+6
source share
2 answers

Redis is probably redundant for a single-machine local application. Especially if the data is small.

It is mainly used as the L2 cache level. Say you have several machines serving your application, each machine can store its own local cache, but Redis can serve as a global cache for everyone. Say your application user is browsing a page or function that requires some data from your database. Then your application will check the local L1 cache (e.g. dictionary). This would be the fastest method since it is not connected to any other network trip. If there is no data, he will look for it in Redis as a global application cache. If it is there - fine - extract the data and paste it into the local L1 cache. If not, go to the database, extract the data, put it in Redis (L2) and in your local cache (L1).

You can read more here.

At the same time, there are more applications for Redis than a simple cache - Pub / Sub, SET s, SORTED SET functionality and functionality on them (for example, intersections, joins, etc.) and even smart functions on STRING type, such as bitwise operations.

+7
source

As you already know, using Redis to cache on the server can lead to overflow.

But using Redis with C # in a distributed application definitely gives some advantages (all of the operations below are thread safe):

  • You can create a normal ORM wrapper for your C # project so that your .NET objects from one server can be easily retrieved from another. You can cache Dictionary objects in Redis hashes, your List objects in Redis lists, your HashSet objects in Redis set, etc. If your values ​​are strings / ints / floats, there is no need to even serialize
  • Publish / Subscribe to / from multiple servers / streams.
  • C # help services / schedulers can take advantage of the support for tasks or objects in Redis lists and get event triggers using the Redis blPop API.
  • Save the elements "top 10", "bottom 10", etc. using Redis sorted set s.

But at the end of the day, it all depends on your use case.

+2
source

All Articles