Auth redis test

This commit is contained in:
2020-05-09 23:40:35 -04:00
parent da26a320b4
commit 4d551a3bfc
5 changed files with 98 additions and 3 deletions

View File

@ -1,6 +1,6 @@
FROM mcr.microsoft.com/dotnet/core/runtime:3.1
COPY bin/Release/netcoreapp3.1/publish/ App/
COPY bin/Release/netcoreapp3.1/ App/
WORKDIR /App
ENTRYPOINT ["dotnet", "authorizer.dll"]

View File

@ -1,13 +1,24 @@
using System;
using System.Threading;
namespace authorizer
{
class Program
{
static AuthServer server;
static Redis redis;
static void Main(string[] args)
{
server = new AuthServer();
redis = new Redis(Environment.GetEnvironmentVariable("REDIS_HOSTNAME"));
redis.SetTest();
Thread.Sleep(100);
redis.GetTest();
/* server = new AuthServer();
server.Start();
@ -17,7 +28,7 @@ namespace authorizer
input = Console.ReadLine();
}
while(input != "stop");
server.Stop();
server.Stop(); */
}
}
}

44
authorizer/Redis.cs Normal file
View File

@ -0,0 +1,44 @@
using System;
using StackExchange.Redis;
class Redis
{
private ConnectionMultiplexer muxer;
private IDatabase conn;
private string hostname;
private int port;
public Redis(string host = "127.0.0.1", int p = 6379)
{
if(host == "")
{
throw new Exception("Must provide a redis hostname!");
}
//Set private variables
hostname = host;
port = p;
//Connect to redis cluster
Console.WriteLine("Attempting to connect to: " + host + ":" + p.ToString());
muxer = ConnectionMultiplexer.Connect(hostname + ":" + port.ToString());
conn = muxer.GetDatabase();
Console.WriteLine("Connected to redis server!");
}
public void SetTest()
{
string test_val = "Potato";
conn.StringSet("test_val", test_val);
Console.WriteLine("Set value to: " + test_val);
}
public void GetTest()
{
Console.WriteLine("Value is: " + conn.StringGet("test_val"));
}
~Redis()
{
muxer.Close();
}
}

View File

@ -5,4 +5,8 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="StackExchange.Redis" Version="2.1.39" />
</ItemGroup>
</Project>