I'm very much new to Redis Cache. The following is my Json string which contains the data.
Code
[
{
"ResourceKey": "Members",
"Language": 1,
"ClientId": 1,
"ResourceValue": "Members"
},
{
"ResourceKey": "Members",
"Language": 2,
"ClientId": 1,
"ResourceValue": "会员"
}
]
What I am trying to achieve is that using ResourceKey, LanguageId, ClientId should form a kind of composite key in Redis to retrieve the ResourceValue field.
I have tried to store Json string as it is but it's very difficult to retrieve 1 particular data as I need to deserialize the whole string then get the single value.
Code
resKeyValue = JsonConvert.DeserializeObject<List<ResourceViewModel>>(readTask.Result);
resKeyValue = resKeyValue.Where(x => x.language == iLanguageId && x.clientid == iClientId).ToList();
Code
var db = _redis.GetDatabase();
var addedItems = new List<KeyValuePair<RedisKey, RedisValue>>();
if (!await db.KeyExistsAsync("resourceList"))
{
addedItems.Add(new KeyValuePair<RedisKey, RedisValue>("resourceList", JsonConvert.SerializeObject(resItem)));
await db.StringSetAsync(addedItems.ToArray());
return Ok("Resources Added Successfully.");
}
I was looking into Hash but NOT able to visualize how to store composite key into Redis. Please help to suggest.