I have a memcached bucket that I want to flush with a query.
DELETE FROM my_memcached_bucket;
Running the query above returns an error This bucket type is not supported memcached.
How can I clean everything from my_memcached_bucket inside of the query?
Related
I'm building a background service which boils down to a very complicated queue system. The idea is to use Redis as non-persistent storage, and have a sub/pub scheme which runs on an interval.
All of the subscribers will be behind a load balancer. This removes the complicated problem of maintaining state between all the servers behind the load balancer.
But, this introduces a new problem...how can I ensure that the non-persistent (Redis) and persistent (MySQL) databases are both updated by my application(s)?
It seems like I'm forced to prioritize one, and if I HAVE to prioritize one, I will prioritize persistence. But, in that scenario, what happens if MySQL is updated, Redis is not, and for some reason I have lost the connection to MySQL and cannot undo my last write?
There are two possible solutions to your problem:
Following these steps:
a. Start MySQL transaction with START TRANSACTION
b. Run your MySQL query INSERT INTO ...
c. Run your Redis command
d. Finish your MySQL transaction with COMMIT statement in case if Redis command succeeded or ROLLBACK if command failed
Using transctions ensures that data is consistent in both storages.
Write LUA script for Redis using LuaSQL library (https://realtimelogic.com/ba/doc/en/lua/luasql.html), where you will connect to MySQL, insert your data and then send commands to Redis as well. Then this LUA script can be called from client side with just one command EVAL or EVALSHA
You can try the mysql udf plugin (https://github.com/Ideonella-sakaiensis/lib_mysqludf_redis)
See the post: how to move data from mysql to redis
I'm currently using Redis in my webProject (predis).
I'm using Redis as Cache server and when I get empty results from redis I would like to look into my MySQL database and store that result into redis.
Also, how would I dump the redis into MySQL to make sure MySQL has the up-to-date content? My plan is to dump redis into MySQL so if the redis is empty it will look in MySQL for the details.
How would I proceed to do this?
Should I do one or two?
After editing/inserting into Redis, do the same to MySQL
Redis -> dump to MySQL -> get from MySQL if empty.
I am assuming you mean to say these things as things are not clear from your question.
You are using Redis as Cache server and when you get empty results from redis you are going to look into your MySQL database and store that result into redis.
Well if your web application is in Java you can try few things as:
create a Jedis Connection.
try to get the value from redis corresponding to that key.
if nothing is returned. You can query the same from your database.
Set the (key value) to redis.
I have a MySQL 5.6 DB running in AWS RDS. I'm in the process of refining a few of my indexes. I use FLUSH QUERY CACHE on my local instance to clear the query cache when doing this kind of development.
I've got a query that takes 10 seconds the first time I call it and 0.2 seconds every time thereafter. I was expecting a post FLUSH QUERY CACHE call of the query would take 10 seconds but it still only takes 0.2 seconds.
This stackoverflow question points out that on Ubuntu I need to clear the memory disc caching prior to clearing the query cache. AWS RDS unfortunately does not allow terminal access to RDS instances.
How do I clear the query cache on a MySQL 5.6 DB running in AWS RDS?
FLUSH QUERY CACHE doesn't clear the query cache in MySQL.
You can defragment the query cache to better utilize its memory with the FLUSH QUERY CACHE statement. The statement does not remove any queries from the cache.
The RESET QUERY CACHE statement removes all query results from the query cache. The FLUSH TABLES statement also does this.
— http://dev.mysql.com/doc/refman/5.6/en/query-cache-status-and-maintenance.html
Also, the linked question is not related to the query cache in any way. The memory used by the query cache is allocated at startup and never returned to the system. The query cache is not backed by a file, and so isn't impacted by flushing to OS filesystem cache.
Finally, I'm not sure why, in the process of index maintenance, clearing the query cache would typically be needed. When benchmarking queries, using SELECT SQL_NO_CACHE ... will cause the query not to be serviced by the query cache.
I plan to use couchbase bucket for caching results from database calls. If one of the couchbase server in cluster goes down and starts back, I want to force expiration of any persisted documents on that server. How can I do that? How is the performance of memcached bucket compared to couchbase bucket?
Couchbase persists the expiration if an item has one so if you item expires while the server is down and you restart the server the item will be deleted during the warmup process.
There's no support to flush just a single nodes' vbuckets, but you can flush the whole Bucket (across all nodes) by simply deleting and re-creating the Bucket.
This can be done using the REST API - see Deleting a Bucket and Creating and Editing a Bucket. You may also have this wrapped up in an SDK call, depending on which SDK you're using.
I'm trying to test the performance of using memcached on a MySQL server to improve performance.
I want to be able to use the normal MySQL command line, but I can't seem to get it to connect to memcached, even when I specify the right port.
I'm running the MySQL command on the same machine as both the memcached process and the MySQL server.
I've looked around online, but I can't seem to find anything about using memcached other than with program APIs. Any ideas?
Memcached has its own protocol. The MySQL client cannot connect directly to a memcached server.
You may be thinking of the MySQL 5.6 feature that allows MySQL server to respond to connections using a memcached-compatible protocol, and read and write directly to InnoDB tables. See http://dev.mysql.com/doc/refman/5.6/en/innodb-memcached.html
But this does not allow MySQL clients to connect to memcached -- it's the opposite, allowing memcached clients to connect to mysqld.
Re your comment:
The InnoDB memcached interface is not really a caching solution per se, it's a solution for using a familiar key/value API for persistent data in InnoDB tables. InnoDB does do transparent caching of data pages in its buffer pool, but this is no different from conventional data reads with SQL. InnoDB also commits all changes to its transaction log synchronously on commit.
Here's a blog from my colleague at Percona. He tested whether the MySQL 5.6 memcached API could be used as a caching layer, and found that actually using memcached is still superior.
http://www.mysqlperformanceblog.com/2013/03/29/mysql-5-6-innodb-memcached-plugin-as-a-caching-layer/
Here's one conclusion from that blog:
As expected, there is a slowdown for write operations when using the InnoDB version. But there is also a slight increase in the average fetch time.