Redis Cache : Incompatibility between NodeJs and .Net Core RRS feed

  • Question

  • Hi,

    I have a problem with implementation of Redis.

    When i send an object to Azure Redis Cache with NodeJs, i can't recover it by my .net core Api and vice versa. Is there any method in Node and .net core which can handle this incompatibility please? Which method can i use in Node and .net core to send data by the one and recover it by the other?

    Thanks for your help!

    Thursday, August 22, 2019 2:28 PM

All replies

  • Since you have not posted the code or error message, I believe that you are most probably running into the Object conversion error.

    You will need to serialize your Object before saving and de-serialize after retrieving.

    There are several node.js clients for Redis. Here is a sample using the node_redis client.

    async function demo() {
        // Connect to the Azure Cache for Redis over the SSL port using the key.
        var cacheConnection = redis.createClient(6380, process.env.REDISCACHEHOSTNAME, 
            {auth_pass: process.env.REDISCACHEKEY, tls: {servername: process.env.REDISCACHEHOSTNAME}});
        console.log("\nCache command: SET Message");
        console.log("Cache response : " + await cacheConnection.setAsync("Message",JSON.stringify(YOUROBJECT)));    

    Now using the StackExchange.Redis client for .NET Core

    static void Main(string[] args) { InitializeConfiguration(); // Connection refers to a property that returns a ConnectionMultiplexer // as shown in the previous example. IDatabase cache = lazyConnection.Value.GetDatabase(); cacheCommand = "GET Message"; Console.WriteLine("\nCache command : " + cacheCommand + " or StringGet()");

    // Get Object from Cache

                YOUROBJECTCLASS objectFromCache = JsonConvert.DeserializeObject<YOUROBJECTCLASS>(cache.StringGet("Message"));

    lazyConnection.Value.Dispose(); }

    There is a code sample here

    Please let me know if that works for you.


    If this answers your query, do click “Mark as Answer” and Up-Vote for the same which might be beneficial to other community members reading this thread .

    Thursday, August 22, 2019 3:17 PM