In: Computer Science
redis cache has a gridview How can the gridview display only certain rows eg, when user inputs in textbox and clicks the button, the gridview will only display the rows which has data equal to the textbox data Language C#
no sql is used
how to display data from grid view using condition without sql
Redis is a NoSQL key-value cache that stores the information in a hash table format, providing the possibilities to store different types of structured data like strings, hashes, lists, sets, sorted sets, bitmaps and hyper loglogs.
Installing REDIS on Windows-
Officially Redis doesn't have an official version for windows, but being an open-source project,
Requirements to install Redis:
In order to install Redis on Windows using Chocolatey,
we need to run a simple command with the command prompt (as
administrator)
C:\> choco install redis-64
Once the installation is complete, we can run the Redis server instance using the command redis-server.exe. If you have problems running the command and get the error "redis-server is not recognized as an internal...etc" is because chocolatey failed registering the system path variable indicating where Redis is. You can fix it with the following command:
SET PATH=%PATH%;"c:\Program Files\Redis"
Now we can run the redis-server.exe to start our Redis instance.
Once this package is installed, we are going to create a new class named RedisConnectorHelper.cs. In order to have an easy way to manage our connection to redis,
we type the following:
public class RedisConnectorHelper
{
static RedisConnectorHelper()
{
RedisConnectorHelper.lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
{
return ConnectionMultiplexer.Connect("localhost");
});
}
private static Lazy<ConnectionMultiplexer> lazyConnection;
public static ConnectionMultiplexer Connection
{
get
{
return lazyConnection.Value;
}
}
}
Setting and Getting data from the cache :-
class Program
{
static void Main(string[] args)
{
var program = new Program();
Console.WriteLine("Saving random data in cache");
program.SaveBigData();
Console.WriteLine("Reading data from cache");
program.ReadData();
Console.ReadLine();
}
public void ReadData()
{
var cache = RedisConnectorHelper.Connection.GetDatabase();
var devicesCount = 10000;
for (int i = 0; i < devicesCount; i++)
{
var value = cache.StringGet($"Device_Status:{i}");
Console.WriteLine($"Valor={value}");
}
}
public void SaveBigData()
{
var devicesCount = 10000;
var rnd = new Random();
var cache = RedisConnectorHelper.Connection.GetDatabase();
for (int i = 1; i < devicesCount; i++)
{
var value = rnd.Next(0, 10000);
cache.StringSet($"Device_Status:{i}", value);
}
}
}