I have few key's stored in the MemCached server. Like...
KEY-2312sdasd78
KEY-5lk65klk343
KEY-klk34k3lkl3
TEST-34k3l4k3l4
TEST-kl3k2lk3l2
Now, I want to remove the key's from MemCached server which are start with "KEY".
I have tried to find google but there is no RegEX based support in MemCached.
Does anybody faced this kind of issues, and what is the optimum work around for this.
Any help will be appreciated. Thanks.
Possible duplicate: Regex on memcached key?
Also See http://code.google.com/p/memcached-tag/
I think something like this is much easier with something like Redis because it:
Supports Transactions
Supports atomic data structures like Lists
So in Redis when you add a key,value you will add the key to some giant global list in the same transaction.
There's no way to do this without knowing that the keys are.
The only way that you could do something like this is by prefixing each set of keys with something common, e.g. KEY-KEYSET1-. You could then invalidate them all by internally bumping 1 to 2 in your code, which means that the existing values will not be accessed and eventually expire.
Related
I want to search keys with the string pattern. I don't see SCAN is straight forward as Keys do.
redistemplate.opsForSet().getOperations().keys(pattern);
This is so straight forward, so if I have my value as my key, I can do search and also sorting to an extent. But my only problem is that there is a warning stating not to use KEYS command. Not sure if Spring has handled it, please provide your thoughts.
You should consider KEYS (http://redis.io/commands/keys) a debug command. Running it in redis-cli on your development instance is perfectly fine, but don't use it in code that will eventually end up on your production instance.
Depending on the size of your redis database and the pattern used with KEYS, the command can potentially take a long time to execute. During that time the redis server will not be able to service any other commands.
SCAN may not be as straight-forward, but it is the right way to enumerate keys without slowing the server down. And you'll find plenty of samples for Spring, like this one: https://stackoverflow.com/a/30260108/3677188
I'm trying to understand how rack-attack uses memcached to throttle connections.
As far as I can tell there's no easy way to manage lists in memcached, and no way to search keys by prefix. Yet rack-attack is somehow keeping a list count within cache, but I'm staring at the source code and can't figure out how it works?
https://github.com/kickstarter/rack-attack/blob/master/lib/rack/attack/throttle.rb
https://github.com/kickstarter/rack-attack/blob/master/lib/rack/attack/cache.rb
It's possible to emulate namespacing, tagging and indexing with memcached, which allows you to work around many limitations (in your case you could maintain prefixes as tags). This article has some good ideas, and the memcached docs have some neat tricks too.
Is it possible to change all the key/value pairs in memcache instances with a command line?
Say, I have 10 memcache servers and they have key value pairs, and they all have the objects with 30 days expiration. But they don't expire at the same time, and I don't want all of them to expire at the same time. I want to change the objects to expire in 10 days. How can I make this change?
Is this even possible?
Can this be done via a commandline? Do I have to write a program for this?
You can accomplish this by touching values periodically. The FAQ describes a way to do this.
However, memcache isn't designed for this. What you're doing seems to be more like a persistent cache scenario. If you love memcache semantics, Membase and MemcacheDB provide solutions that may better fit your needs. There are many different persistent cache systems that do this just as well.
Depending on your specs, sometimes speeding up your data source may deliver better performance than memcache. Modern DMBSs cache heavily with sensible access protocols. This is entirely dependent on what your data sources look like and how much flexibility you have in your system design.
Memcache has a telnet interface. Then you can use FLUSH_ALL or FLUSH_ALL <seconds_to_wait>, if that's what you mean...
Does there exist some sort of persistent key-value like store that allows for quick and easy incrementing, decrementing, and retrieval of integers (and nothing else). I know that I could implement something with a SQL database, but I see two drawbacks to that:
It's heavyweight for the task at hand. All I need is the ability to say "server[key].inc()" or "server[key].dec()"
I need the ability to handle potentially thousands of writes to a single key simultaneously. I don't want to deal with excessive resource contention. Change the value and get out - that's all I need.
I know memcached supports inc/dec, but it's not persistent. My strategy at this point is going to be to use a SQL server behind a queueing system of some sort such that there's only one process updating the database. It just seems... harder than it should be.
Is there something someone can recommend?
Redis is a key-value store that supports several data types. Integer is present, along with incr and decr commands.
Im trying to find a good way to handle memcache keys for storing, retrieving and updating data to/from the cache layer in a more civilized way.
Found this pattern, which looks great, but how do I turn it into a functional part of a PHP application?
The Identity Map pattern: http://martinfowler.com/eaaCatalog/identityMap.html
Thanks!
Update: I have been told about the modified memcache (memcache-tag) that apparently does do a lot of this, but I can't install linux software on my windows development box...
Well, memcache use IS an identity map pattern. You check your cache, then you hit your database (or whatever else you're using). You can go about finding information about the source by storing objects instead of just values, but you'll take a performance hit for that.
You effectively cannot ask the cache what it contains as a list. To mass invalidate, you'll have to keep a list of what you put in and iterate it, or you'll have to iterate every possible key that could fit the pattern of concern. The resource you point out, memcache-tag can simplify this, but it doesn't appear to be maintained inline with the memcache project.
So your options now are iterative deletes, or totally flushing everything that is cached. Thus, I propose a design consideration is the question that you should be asking. In order to get a useful answer for you, I query thus: why do you want to do this?