dmuka3.CS.Simple.RamDb 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package dmuka3.CS.Simple.RamDb --version 1.0.1                
NuGet\Install-Package dmuka3.CS.Simple.RamDb -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="dmuka3.CS.Simple.RamDb" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add dmuka3.CS.Simple.RamDb --version 1.0.1                
#r "nuget: dmuka3.CS.Simple.RamDb, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install dmuka3.CS.Simple.RamDb as a Cake Addin
#addin nuget:?package=dmuka3.CS.Simple.RamDb&version=1.0.1

// Install dmuka3.CS.Simple.RamDb as a Cake Tool
#tool nuget:?package=dmuka3.CS.Simple.RamDb&version=1.0.1                

dmuka3.CS.Simple.RamDb

This library provides you to store data on RAM. It will never save to disk just like Redis.

Nuget

Link : https://www.nuget.org/packages/dmuka3.CS.Simple.RamDb

Install-Package dmuka3.CS.Simple.RamDb

Example 1

We should create a server to connect and to get datas from it. After that, we will connect to this server.

// Creating a server.
RamDbServer server = new RamDbServer("muhammed", "123123", 2048, 4, 9090, timeOutAuth: 1);
// We have to start it on background.
new Thread(() =>
{
    server.Start();
}).Start();

// Wait for server.
Thread.Sleep(1000);

// Client to connect to the server.
RamDbClient client = new RamDbClient("127.0.0.1", 9090);
// Connected.
client.Start("muhammed", "123123", 2048);

// Create a key with value for 30 second.
client.SetValue("TEST_KEY", "MUHAMMET KANDEMİR", TimeSpan.FromSeconds(30), out _);
// Get a value by key.
var v = client.GetValue("TEST_KEY");

// Close client.
client.Dispose();
// Close server.
server.Dispose();

Assert.AreEqual(v, "MUHAMMET KANDEMİR");

You may wonder what is the "2048". It is key size of RSA. We always use RSA during communication on TCP. This is security to save your secret datas.

Also, we will show you how to lock a data on single thread.

Example 2

// Create a server.
RamDbServer server = new RamDbServer("muhammed", "123123", 2048, 4, 9090, timeOutAuth: 1);
// Run the server on background.
new Thread(() =>
{
    server.Start();
}).Start();

// Wait server.
Thread.Sleep(1000);

// Create client.
RamDbClient client = new RamDbClient("127.0.0.1", 9090);
// Connect to the server.
client.Start("muhammed", "123123", 2048);

// Our test variables.
List<bool> l = new List<bool>();
List<Thread> ts = new List<Thread>();
bool err = false;
for (int i = 0; i < 10; i++)
{
    ts.Add(new Thread(() =>
    {
        try
        {
            for (int j = 0; j < 5; j++)
            {
                // Here is fairly important.
                // Because we are checking the queue on a single thread.
                // When we come here with double thread, first thread will pass but second will stop here and wait previous thread to unlock the queue.
                client.Lock("TEST_LOCK_KEY", TimeSpan.FromSeconds(30));

                l.Add(true);
                foreach (var item in l)
                    Thread.Sleep(1);

                // We unlock the queue for next thread.
                client.UnLock("TEST_LOCK_KEY");
            }
        }
        catch (Exception ex)
        {
            err = true;
        }
    }));
}

foreach (var item in ts)
    item.Start();

Thread.Sleep(5000);
client.Dispose();
server.Dispose();

Assert.IsFalse(err);
Assert.AreEqual(l.Count, 50);
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 is compatible.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.5 580 10/29/2019
1.0.4 455 10/29/2019
1.0.3 476 10/28/2019
1.0.2 468 10/28/2019
1.0.1 471 10/27/2019
1.0.0 463 10/26/2019