Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core Distributed Redis Cache with Password

I’m using the distributed Redis Cache to cache temporally some User-Data. Currently I’m testing the Application locally in my Development Environment. The Redis-Server on my local Machine has no Password but in Production I’m using a random generated Password.

How can I connect to the Redis-Server with a Password?

My Startup.cs:

   //Add Redis
    services.AddDistributedRedisCache(options =>
    {
        options.Configuration = "127.0.0.1:6379";
        options.InstanceName = "Portal";
    });
like image 978
Yannik Avatar asked May 01 '17 08:05

Yannik


People also ask

How do I password protect a Redis server?

If you want to secure your server permanently, you can set a password in the Redis configuration file. Locate the entry #requirepass. Uncomment the line above and set your secure password. Save and close the file.

Is Redis distributed cache?

Redis is an open source in-memory data store, which is often used as a distributed cache. You can configure an Azure Redis Cache for an Azure-hosted ASP.NET Core app, and use an Azure Redis Cache for local development.


1 Answers

Microsoft.Extensions.Caching.Redis client is built on top of StackExchange.Redis. It means the StackExchange Redis Connection String is used to specify a password and any other options, for example:

services.AddDistributedRedisCache(options =>
{
    options.Configuration = "localhost:6380,password=...";
    options.InstanceName = "SampleInstance";
});
like image 93
Ilya Chumakov Avatar answered Sep 26 '22 03:09

Ilya Chumakov