Last updated

Redis Client

Redis Client is a NoSQL key-value cache that stores information in a hash table format. It provides the possibilities to store different type of structured data like strings, hashes, lists, sets, sorted sets, bitmaps and hyperloglogs.

With Edge SDK 2.0 RedisClient functionality, developers can easily use Redis Server available on the gateway.

Using Redis Client

Namespace: Agora.Edge

The RedisClient is implemented as a singleton. The purpose of the RedisClient is to store, retrieve values from Redis Server.

Example

AEA.json configuration file:
{
    "Name": "Sender",
    "AEA2": {
       "LogLevel": "Trace", 
        "RedisClient": {
            "Server": "localhost",
            "Port": 6379,
        }
    }
}
Connect to the Redis Server

Use the following command to connect to the Redis Server.

using System.Text.Json;
using static Agora.SDK;

internal class Program
{
   private static void Main(string[] args)
    {
        "Starting".LogHeading();
        Redis.Connect(2000);
    }
}
from agoraiot import *

redisclient = redisClientSingleton.connect(2)

Storing and Retrieving Value using Redis Client

Use the following command to store and retrieve value.

using System.Text.Json;
using static Agora.SDK;

internal class Program
{
   private static void Main(string[] args)
    {
        "Starting".LogHeading();
        Redis.Connect(2000);
        if (Redis.IsConnected)
        {
            //This one is used to store value
            Redis.Client.StringSet("key", "value");
            //This one is used to Get value
            var value = Redis.Client.StringGet("key");
            $"Value {value}".LogInfo();
        }
    }
}
redisclient = redisClientSingleton.connect(2)
if redisclient.ping():
    redisclient.set('my_key', 'my_value')
    result = redisclient.get('my_key')
    print(result)