-
Notifications
You must be signed in to change notification settings - Fork 0
Fixed GetOrSet redis read. #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -219,7 +219,20 @@ public void Set<T>(string key, T value, TimeSpan ttl) | |
|
|
||
| public T GetOrSet<T>(string key, Func<string, T> valueFactory, TimeSpan ttl, long maxMsToWaitForFactory = 10000) | ||
| { | ||
| return hzCache.GetOrSet(key, valueFactory, ttl, maxMsToWaitForFactory); | ||
| var redisBackedValueFactory = new Func<string, T>(k => | ||
| { | ||
| var redisValue = GetRedisValue(k); | ||
| if (!redisValue.IsNull) | ||
| { | ||
| var ttlValue = TTLValue.FromRedisValue<T>(Encoding.ASCII.GetBytes(redisValue.ToString())); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a HzActivities.Source.StartActivityWithCommonTags so we can see the time here |
||
| hzCache.SetRaw(k, ttlValue); | ||
| return (T)ttlValue.value; | ||
| } | ||
|
|
||
| return valueFactory.Invoke(k); | ||
| }); | ||
|
|
||
| return hzCache.GetOrSet(key, redisBackedValueFactory, ttl, maxMsToWaitForFactory); | ||
| } | ||
|
|
||
| public IList<T> GetOrSetBatch<T>(IList<string> keys, Func<IList<string>, List<KeyValuePair<string, T>>> valueFactory) | ||
|
|
@@ -229,7 +242,8 @@ public IList<T> GetOrSetBatch<T>(IList<string> keys, Func<IList<string>, List<Ke | |
|
|
||
| public IList<T> GetOrSetBatch<T>(IList<string> keys, Func<IList<string>, List<KeyValuePair<string, T>>> valueFactory, TimeSpan ttl) | ||
| { | ||
| using var activity = HzActivities.Source.StartActivityWithCommonTags(HzActivities.Names.GetOrSetBatch, HzActivities.Area.RedisBackedHzCache, key: string.Join(",", keys ?? new List<string>())); | ||
| using var activity = HzActivities.Source.StartActivityWithCommonTags(HzActivities.Names.GetOrSetBatch, HzActivities.Area.RedisBackedHzCache, | ||
| key: string.Join(",", keys ?? new List<string>())); | ||
| Func<IList<string>, List<KeyValuePair<string, T>>> redisFactory = idList => | ||
| { | ||
| // Create a list of redis keys from the list of cache keys | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,7 +57,20 @@ public Task SetAsync<T>(string key, T value, TimeSpan ttl) | |
|
|
||
| public Task<T> GetOrSetAsync<T>(string key, Func<string, Task<T>> valueFactory, TimeSpan ttl, long maxMsToWaitForFactory = 10000) | ||
| { | ||
| return hzCache.GetOrSetAsync(key, valueFactory, ttl, maxMsToWaitForFactory); | ||
| var redisBackedValueFactory = new Func<string, Task<T>>(async k => | ||
| { | ||
| var redisValue = await GetRedisValueAsync(k).ConfigureAwait(false); | ||
aheintz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (!redisValue.IsNull) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a HzActivities.Source.StartActivityWithCommonTags so we can see the time here |
||
| { | ||
| var ttlValue = await TTLValue.FromRedisValueAsync<T>(Encoding.ASCII.GetBytes(redisValue.ToString())).ConfigureAwait(false); | ||
| hzCache.SetRaw(k, ttlValue); | ||
| return (T)ttlValue.value; | ||
aheintz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return await valueFactory.Invoke(k).ConfigureAwait(false); | ||
| }); | ||
|
|
||
| return hzCache.GetOrSetAsync(key, redisBackedValueFactory, ttl, maxMsToWaitForFactory); | ||
| } | ||
|
|
||
| public Task<IList<T>> GetOrSetBatchAsync<T>(IList<string> keys, Func<IList<string>, Task<List<KeyValuePair<string, T>>>> valueFactory) | ||
|
|
@@ -67,7 +80,8 @@ public Task<IList<T>> GetOrSetBatchAsync<T>(IList<string> keys, Func<IList<strin | |
|
|
||
| public async Task<IList<T>> GetOrSetBatchAsync<T>(IList<string> keys, Func<IList<string>, Task<List<KeyValuePair<string, T>>>> valueFactory, TimeSpan ttl) | ||
| { | ||
| using var activity = HzActivities.Source.StartActivityWithCommonTags(HzActivities.Names.GetOrSetBatch, HzActivities.Area.RedisBackedHzCache, async: true, key: string.Join(",", keys ?? new List<string>())); | ||
| using var activity = HzActivities.Source.StartActivityWithCommonTags(HzActivities.Names.GetOrSetBatch, HzActivities.Area.RedisBackedHzCache, async: true, | ||
| key: string.Join(",", keys ?? new List<string>())); | ||
| Func<IList<string>, Task<List<KeyValuePair<string, T>>>> redisFactory = async idList => | ||
| { | ||
| // Create a list of redis keys from the list of cache keys | ||
|
|
@@ -127,4 +141,4 @@ public Task<bool> RemoveAsync(string key) | |
| return hzCache.RemoveAsync(key); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.