R
R
River00512019-05-15 15:20:13
Redis
River0051, 2019-05-15 15:20:13

How can I specify the content version in redis and then compare it with the new number?

Good afternoon, help me figure it out, you need to implement the removal of old keys from redis if the version has been updated, there is such a script that caches the desired piece on the page
. block

if ($current_user->user_login == 'admin'){
    $key = $pname.'_first_admin_'.get_field('admin_version');
    if ($redis->exists($key)) {
      echo $redis->get($key);
    } else {
    $content20 = get20($bild_20,$pname);
      // вычисляете свой кусок, затем
      $redis->set($key, $content20);
      //$redis->expire($key, 2592000); // 1 месяц
      echo $redis->get($key);
  } 
  } 
  else 
  {
    $key = $pname.'_first_user_'.get_field('user_version');
    if ($redis->exists($key)) {
      echo $redis->get($key);
    } else {
    $content20 = get20($bild_20,$pname);
      // вычисляете свой кусок, затем
      $redis->set($key, $content20);
      //$redis->expire($key, 2592000); // 1 месяц
      echo $redis->get($key);
    }
  }

in redis the keys are written
test_first_admin_1
test_first_user_1

The whole code works fine, but when we increase the version in get_field('admin_version'), we will write a new key, and the old one needs to be deleted somehow, but as I can't think of,
I thought to make a request $redis->get('test_first_admin_*' ) and if there is something to delete, but immediately the thought came that this is not correct, because we will overwrite each time, but we need to get and compare, for example, the record test_first_admin_1 with the new test_first_admin_2, and if the value is greater, then update, but this is a string and I don’t understand how to compare only the last numbers.
Maybe there is some better way, help solve the problem.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question