使用MYsql 5.6 Memcache [英] Using MYsql 5.6 Memcache

查看:91
本文介绍了使用MYsql 5.6 Memcache的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我肯定在这里确实缺少一些明显的东西,但是我想做的是使用MySQL 5.6并通过memcache返回值

I must be missing something really obvious here I think, but what I am trying to do is use MySQL 5.6 and return values through memcache

因此,我已将MYSQL设置为使用memcache插件,并在innodb_memcache.containers表中设置了详细信息

So I have set up MYSQL to use the memcache plugin, set up the details in the innodb_memcache.containers table

我现在在该表中有两个项目,MySQL输入的默认项目和我自己的设置,它们都有表名.

I now have two items in that table, the default ones entered by MySQL and my own settings, both of them have table names.

要通过php获取数据,请使用:

To get the data via php I use:

  $memcache->get($key);

$ key是db列中的数据

Where $key is the data in the db column

但是这什么都不返回,我怀疑原因是,根据MySQL Docs,如果未指定表名,它将选择列表中的第一个,而不是我想要的,我不明白的这就是我在键中指定正确的表名的方式,因此它知道要在哪个表中查找键.

However this returns nothing, I suspect the reason is that, according to the MySQL Docs if no table name is specified, it choose the first one in the list, which is not the one I want, what I don't understand is how I specify the correct table name in the key, so it knows which table to look for the key in.

其他信息:

table design:
    table: codes
    id INT PK
    code VARCHAR UNIQUE
    codeval VARCHAR


innodb_memcache.containers :
name: mycode
db_schema: databaseName
db_table: codes
key_columns: code
value_columns: codeval
flags: id
cas_column: null
expire_time_column: null
unique_idx_name_on_key: code

代码:

$table = "mycode";
$key = "123456";
 $memcache = new Memcache;
 $memcache->connect($this->CONNECTURL, $this->CONNECTPORT) or die ("Could not connect");
 $version = $memcache->getVersion();
  echo "Server's version: ".$version."<br/>\n";

 $key = "@@" . $table . "." . $key . "." . $table;
 $get_result = $memcache->get($key);

  print_r($get_result);

上面的代码返回服务器版本没有问题,因此连接正常. 当应该返回值时,print_r($ get_result)返回空白

The above code returns the server version without issue, so the connection is working. print_r($get_result) returns blank, when it should be returning a value

它确实发出了一个通知:试图获取非对象的属性

It does throw a notice: Trying to get property of non-object

因此,如果有人可以让我知道如何使用$ key指定要用于通过memcache查询的表,我将不胜感激!

So if someone could let me know how I specify with the $key which table I am using to query through memcache, I would be much appreciated!

推荐答案

表名(@@table_id中的table_id)必须是映射中的值(innodb_memcache.containers),而不是实际的表名(如果有)变化.

The table name (table_id in @@table_id) must be the value from your mappings (innodb_memcache.containers), not the actual table name, if that varies.

如果您在映射中的表名是mycode,则通过 memcache 生成的查询应如下所示:

And if you table name in mappings is mycode, then the resulting query through memcache should look like this:

$table = 'mycode';
$key   = '123456';
$memcache->get( '@@' . $table . '.' . $key );

最后没有多余的'.' . $table.

一些详细信息可从 InnoDB内存缓存插件文档页面.

Some details are available from InnoDB memcached Plugin documentation page.

在这里仅举几例重要的事情:

To name a few of importance here:

  1. 使用select * from innodb_memcache.containers;获取已定义的映射;
  2. 注意查询组织:
  1. Use select * from innodb_memcache.containers; to get defined mappings;
  2. Note the queries organization:

例如,@@ t1.some_key和@@ t2.some_key具有相同的键值, 但它们存储在不同的表中,因此不会发生冲突.

For example, @@t1.some_key and @@t2.some_key have the same key value, but are stored in different tables and so do not conflict.

这篇关于使用MYsql 5.6 Memcache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆