Skip to content

Commit fedf9c1

Browse files
committedMar 21, 2016
Initial
1 parent 778020f commit fedf9c1

10 files changed

+6384
-294
lines changed
 

‎.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ TestResult.xml
4141
dlldata.c
4242

4343
# DNX
44-
project.lock.json
4544
artifacts/
4645

4746
*_i.c

‎NuGet.config

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetcidev/api/v3/index.json" />
5+
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
6+
</packageSources>
7+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Text;
2+
using System.Threading.Tasks;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.Extensions.Caching.Distributed;
5+
6+
namespace AspNetRedisSample.Controllers
7+
{
8+
public class RedisCacheController : Controller
9+
{
10+
private readonly IDistributedCache _redisCache;
11+
12+
public RedisCacheController(IDistributedCache redisCache)
13+
{
14+
_redisCache = redisCache;
15+
}
16+
17+
[HttpGet("api/rediscache/set/{key}/{value}")]
18+
public async Task<IActionResult> SetValue(string key, string value)
19+
{
20+
await _redisCache.SetAsync(key, Encoding.UTF8.GetBytes(value));
21+
return Content($"Successfully set the value for key '{key}' in redis cache.");
22+
}
23+
24+
[HttpGet("api/rediscache/get/{key}")]
25+
public async Task<IActionResult> GetValue(string key)
26+
{
27+
var valueInBytes = await _redisCache.GetAsync(key);
28+
if (valueInBytes == null)
29+
{
30+
return NoContent();
31+
}
32+
33+
return Content(Encoding.UTF8.GetString(valueInBytes));
34+
}
35+
}
36+
}

‎src/AspNetRedisSample/Controllers/ValuesController.cs

-44
This file was deleted.

‎src/AspNetRedisSample/Program.cs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using Microsoft.AspNetCore.Hosting;
1+
using System.IO;
72
using Microsoft.AspNetCore.Builder;
3+
using Microsoft.AspNetCore.Hosting;
84

95
namespace AspNetRedisSample
106
{
117
public class Program
128
{
13-
// Entry point for the application.
149
public static void Main(string[] args)
1510
{
1611
var host = new WebHostBuilder()
1712
.UseServer("Microsoft.AspNetCore.Server.Kestrel")
18-
.UseApplicationBasePath(Directory.GetCurrentDirectory())
1913
.UseDefaultConfiguration()
2014
.UseIISPlatformHandlerUrl()
2115
.UseStartup<Startup>()

‎src/AspNetRedisSample/Project_Readme.html

-188
This file was deleted.

‎src/AspNetRedisSample/Startup.cs

+14-26
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,32 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Builder;
6-
using Microsoft.AspNetCore.Hosting;
1+
using Microsoft.AspNetCore.Builder;
72
using Microsoft.AspNetCore.HttpOverrides;
8-
using Microsoft.Extensions.Configuration;
3+
using Microsoft.Extensions.Caching.Redis;
94
using Microsoft.Extensions.DependencyInjection;
105
using Microsoft.Extensions.Logging;
11-
using Microsoft.Extensions.PlatformAbstractions;
126

137
namespace AspNetRedisSample
148
{
159
public class Startup
1610
{
17-
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
11+
public void ConfigureServices(IServiceCollection services)
1812
{
19-
// Set up configuration sources.
20-
var builder = new ConfigurationBuilder()
21-
.SetBasePath(appEnv.ApplicationBasePath)
22-
.AddJsonFile("appsettings.json")
23-
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
24-
.AddEnvironmentVariables();
25-
Configuration = builder.Build().ReloadOnChanged("appsettings.json");
26-
}
13+
services.Configure<RedisCacheOptions>(options =>
14+
{
15+
options.Configuration = "localhost";
16+
});
2717

28-
public IConfigurationRoot Configuration { get; set; }
18+
services.AddDistributedRedisCache(options =>
19+
{
20+
options.Configuration = "localhost";
21+
});
2922

30-
// This method gets called by the runtime. Use this method to add services to the container.
31-
public void ConfigureServices(IServiceCollection services)
32-
{
33-
// Add framework services.
3423
services.AddMvc();
3524
}
3625

37-
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
38-
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
26+
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
3927
{
40-
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
41-
loggerFactory.AddDebug();
28+
loggerFactory.AddConsole(LogLevel.Trace);
29+
loggerFactory.AddDebug(LogLevel.Trace);
4230
app.UseIISPlatformHandler();
4331

4432
app.UseForwardedHeaders(new ForwardedHeadersOptions

‎src/AspNetRedisSample/appsettings.json

-10
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.