1

predis2 つの Redis インスタンス (マスター サーバーとスレーブ サーバー) と対話するために使用しています。マスターは主に書き込み専用、スレーブは読み取り専用です。

selectの機能を使用して接続を切り替える必要がRedisありますが、パフォーマンスが心配です。シングルトン クラスを作成し、それをインスタンス化に使用した方がよいでしょうか。$this->redisまた、select永続性を維持するにはどうすればよいでしょうか。

以下は、これまでの私のコードの一部です。パフォーマンスを向上させるためにこれを行うことができるかどうか疑問に思っていましたか?

$redis = $this->redis;

$tipperKey = str_pad($tipperId, 10, '0', STR_PAD_LEFT);
if ($this->debug) {
  $this->logger->addDebug('tipperKey=' . $tipperKey);
  $this->logger->addDebug("Adding groupId:$groupId to \"groups:$tipperKey\" in db:0");
}

// add groupId to tipper groups set
try {
  $redis->select(0);
  $redis->sadd('groups:' . $tipperKey, $groupId);
} catch (Exception $e) {
  $this->logger->addError("Error adding groupId:$groupId to \"groups:$tipperKey\" in db:0 : " . $e->getMessage());
  return false;
}

$result = $this->getRoundsPlayed($competitionId); // cached (600)
if (!$result) {
  return false;
}

$tk = 'tipper:' . $tipperKey;
try {
  foreach ($result as $row) {
    $i = (int)$row['round_number'];
    if ($this->debug) {
      $this->logger->addDebug('select db:' . $i);
    }
    $redis->select($i);

    $sportId = (int)$row['sport_id'];

ところで、これはギアマンジョブ用です

4

0 に答える 0