Answer the question
In order to leave comments, you need to log in
How to cache mysql query in a variable?
Good afternoon, I'm trying to cache the result of a query in redis, but it doesn't work, the variable is empty and I don't understand why
function get60_v1($_60n) {
global $wpdb;
ob_start();
$s_1 = $wpdb->get_row(
"
SELECT *
FROM learn
WHERE s_name = '".$_60n->name."'
"
);
return ob_get_clean();
}
$key_60_sql = $pname.':'.get_field('user_version');
if ($redis->exists($key_60_sql)) {
$s_1 = $redis->get($key_60_sql);
} else {
$sql_60 = get60_v1($_60n);
// вычисляете свой кусок, затем
$redis->set($key_60_sql, $sql_60);
$redis->expire($key_60_sql, 604800); // 1 неделя
$s_1 = $redis->get($key_60_sql);
}
function get60_v1($_60n) {
global $wpdb;
$s_1 = $wpdb->get_row(
"
SELECT *
FROM learn
WHERE s_name = '".$_60n->name."'
"
);
return $s_1;
}
Answer the question
In order to leave comments, you need to log in
Solved the problem like this
$key_60_sql = $pname.':'.get_field('user_version');
if ($redis->exists($key_60_sql)) {
$_s_3 = $redis->hgetall($key_60_sql);
$s_3 = (object)$_s_3;
} else {
$sql_60 = $wpdb->get_row (
"
SELECT *
FROM learn
WHERE s_name = '".$_60n->name."'
"
);
$array = (array)$sql_60;
// вычисляете свой кусок, затем
$redis->hMSet($key_60_sql, $array);
$redis->expire($key_60_sql, 604800); // 1 неделя
$_s_3 = $redis->hgetall($key_60_sql);
$s_3 = (object)$_s_3;
}
$60n
- How is that? How about:
A valid variable name must begin with a letter or underscore and consist of any number of letters, numbers, and underscores.
https://www.php.net/manual/en/language.variables.b...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question