可以使用redis 有序集合sort sets有序集合中保存ip段的endIp

   $rows列表中包含ip段的startIp与endIp ip都以转换为int型

 $rows = [];

   $redis = new \Redis();

$pipeAdd = $redis->multi(Redis::PIPELINE);
foreach ($rows as $value) {
$key = 'ip'. $value['id'];
echo $key . PHP_EOL;
$pipeAdd->hmset($key, ['content' => json_encode($value)]); //此处多用一个hash结构是为了 与mysql数据库中地区同步
$pipeAdd->zadd($zKey, $value['endIp'], $key);
$value = null;
unset($value);
}
$pipeAdd->exec();

#获取
$resKey = $redis->zrangebyscore($zKey, (int)$ip, '+inf', 'LIMIT', 0, 1);
$res = $redis->hget($resKey[0], 'content');

相关文章:

  • 2022-12-23
  • 2022-02-21
  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案