c# - Update Dictionary object in redis cache using StackExchange.Redis client -


i using azure redis cache , stackexchange.redis client access it. trying figure out best way update dictionary values in redis.

public async task<t> fetchandcacheasync<t>(string key, func<task<t>> retrievedata, timespan absoluteexpiry)         {             t value;              var output = await _cache.stringgetasync(key);             if (output.hasvalue)             {                 value = _serializer.deserialize<t>(output);             }             else             {                 value = await retrievedata();                 await _cache.stringsetasync(key, _serializer.serialize(value), absoluteexpiry);             }              return value;         } 

_cache in above code snippet of type stackexchange.redis.idatabase.

on initialization store dictionary object as

fetchandcacheasync("diagnostics", () => new dictionary());

i have function called update datetime given key in dictionary object.

question: basic knowledge of redis cache can think of following way update particular key value of dictionary stored in redis cache.

var diagnostics = fetchandcacheasync("diagnostics", () => new dictionary<guid, datetime>());  diagnostics[key] = value; _cache.keydeleteasync("diagnostics");  fetchandcacheasync("diagnostics", () => diagnostics); 

but doesn't seem right me. sure there must better way this. suggestion?

have looked @ hash data structure supported redis?

http://redis.io/topics/data-types-intro#hashes

idatabase.hashget("diagnostics", "mykey");

idatabase.hashset("diagnostics", "mykey", "my value");


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -