-
-
Notifications
You must be signed in to change notification settings - Fork 456
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
ClearRegion not working for redis implementation #64
Comments
I can confirm that clearing a region works for the redis implementation. I use it on daily basis, so I would assume you are doing something wrong. The configuration part seems fine although a little cumbersome. Can you put the result of the command KEYS * before and after the ClearRegion operation |
I do not see any code actually adding items to the cache. Are you doing that somewhere else? |
I again tested the clear region code and the unit tests actually testing also the redis layer. All works fine it seems. So in the end, I'm sorry, I cannot really reproduce any error. If you can provide us with a small program to really reproduce the behavior, that would be great |
ok - i have something for you. you will need to create your own (free) azure redis db and put the url:port and password in the web.config. you might not even need to get that far and might notice something i'm doing wrong in the setup. thanks! here's the web project: |
I have to debug it further but the initial problem is that in the local redis instance when it saves a key with a region it actually writes two keys, one for the name of the region and another for the actual key in the format {region}:{key}. The problem is that when it writes to Azure it just writes the actual key and not the name of the region. BTW I would recommend the use of an IoC instead of the static class that you have there, if you want to go with the static class I would recommend implementing the Singleton in a class and the logic in another class |
ok. i'm not sure if you had a chance to set up the azure redis, but it looks like all it does is prefix the region name on the key. for example, 'mykey', with 'someregion' becomes 'someregion:mykey' as the key. |
All the keys in CacheManager are hashes. The name of the actual key can be whatever you like, in this case it appends : to the name to create the key in the format {region}:{key}. What ClearRegion does is retrieve all the keys that are contained in the hash with the name of the region and then it proceeds to delete all those keys. As you can imagine if in Azure it doesn't write the hash with the name of the region it cannot delete the actual keys cuz it doesn't know where they are. The debug process will be then on the write operation and why it's failing to write the hash with the region name to Azure (local works) |
OK to further narrow the problem. In your insert operation you are using Put, if you change that to an Add operation it actually works, writing the hash key with the region name to Azure. So.. I would say that the problem is in the Put operation. Another thing that I detected is that if you have key in the format {region}:{key} and you use an Add operation to add another key with the same region, the hash key with the region name is not added |
guys, you are totally correct. Put has a bug not setting the region lookup key. To clarify, that was introduced during the change to use lua scritps for put and add... I changed the logic slightly. And ofc I used So as a work around, try use Add instead of Put if you can. Sorry for that Will be fixed soonish |
@TMiNus
So, you add If you add another key like |
thanks all. nothing to be sorry for. it's a great product. look forward to the updates. thanks again! also, i noticed the same thing happening on Remove() for a given object. not only on the ClearRegion() |
Oh the Lua scripts, I totally missed that one. I disabled the Lua scripts on my version, that is why it was working all the time for me 😁 @MichaCo what I saw in one testing was that if you have a key in the form |
Looks like this bug is back in v1.2.0.
|
@Andrei- I'm not so sure about how that could have happened, but if you have a reproduceable code example, feel free to post it here Thanks |
Hi @MichaCo - I found the problem. We have at some point upgraded the reference of StackExchange.Redis package to version="2.6.104" because of some warnings with older versions. |
Thanks for the details @Andrei- I'll try to figure out why that happens |
can reproduce the error - reopening |
* removed a bunch of nugets * unified new .NET targets - not final yet * get it compile and stuff... * fixed #64 again by moving the region key update into the lua script.
Although it "shouldn't" matter, First, I am using Redis in Azure. My configuration is as follows. It's two cache handles, Memory and Redis, with a Redis backplane.
When I try to clear the region, the following code gives a zero index result, meaning no hashKeys are found and therefore doesn't continue on to clear the region.
code location: CacheManager.StackExchange.Redis\RedisCacheHandle.cs >
ClearRegion(string region){}
> line 166 in the code i have...var hashKeys = this.connection.Database.HashKeys(region);
An example of one of the keys I'm trying to clear in Redis:
"data:_cache.data.counts.dcsnav.316914602"
My code to clear the region is as follows:
var cache = CreateInMemoryCacheWithRedisBackplane(); // gets the CacheFactory.Build object
from above
cache.ClearRegion(region.ToLower()); //value of 'region' is 'data'
The text was updated successfully, but these errors were encountered: