Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

Redis cache is now in built in web api

$
0
0

eventually i got a link https://docs.microsoft.com/en-us/azure/architecture/best-practices/caching#using-redis-caching

which using redis to cache data. so tell me Redis cache is now in built in web api ?

see the below code i have few question on this

ConnectionMultiplexer redisHostConnection = ...;
IDatabase cache = redisHostConnection.GetDatabase();
...
// Tags are easily represented as Redis Sets
foreach (BlogPost post in posts)
{
    string redisKey = string.Format(CultureInfo.InvariantCulture,"blog:posts:{0}:tags", post.Id);
    // Add tags to the blog post in Redis
    await cache.SetAddAsync(
        redisKey, post.Tags.Select(s => (RedisValue)s).ToArray());

    // Now do the inverse so we can figure how which blog posts have a given tag
    foreach (var tag in post.Tags)
    {
        await cache.SetAddAsync(string.Format(CultureInfo.InvariantCulture,
            "tag:{0}:blog:posts", tag), post.Id);
    }
}

1) these are the inbuilt classes

ConnectionMultiplexer redisHostConnection = ...;
IDatabase cache = redisHostConnection.GetDatabase();

2) how data would look like for the below code

    string redisKey = string.Format(CultureInfo.InvariantCulture,"blog:posts:{0}:tags", post.Id);

does it look like blog:posts:1:tags or blog:posts:2:tags ?

if i am right then why we would create the key like this one ?

2) what the below line is doing

    foreach (var tag in post.Tags)
    {
        await cache.SetAddAsync(string.Format(CultureInfo.InvariantCulture,"tag:{0}:blog:posts", tag), post.Id);
    }

thanks


Viewing all articles
Browse latest Browse all 4850

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>