|
//读取数据通过管道方式写入到redis $lines = file_get_contents($filePath);//获取文件内容
ini_set('memory_limit', '-1');//不要限制Mem大小,否则会报错
$arr = explode(PHP_EOL, $lines);//转换成数组
//echo $arr['1000000'] ?? 'null';
try {
$redis = new \Redis();
$redis->connect('192.168.1.9', 6379);
$redis->auth('*****');//密码验证
$redis->select(0);//选择库
$redis->pipeline();//开启管道
foreach ($arr as $key => $value) {
$redis->hsetNx('helloworld', (string)$key, $value);
}
$redis->exec();
echo $redis->hGet('helloworld', '1000000') . PHP_EOL;
echo $redis->hGet('helloworld', '1000001') . PHP_EOL;
} catch (\Exception $e) {
echo $e->getMessage();
}
|
|
|