PHP에서 redis 데이터베이스를 덤프하고 복원하려면 어떻게합니까? 클라이언트에서 predis을 사용하고 있습니다.PHP에서 덤프 및 복원 (프레디)
redis 데이터베이스를 .rdb 형식으로 덤프 할 수 있습니까?
업데이트 :
내가 다음 명령을 사용하여/백업 데이터베이스를 덤프,
$redis->bgSave();
어떻게 내 데이터베이스로 다시 복원?
PHP에서 redis 데이터베이스를 덤프하고 복원하려면 어떻게합니까? 클라이언트에서 predis을 사용하고 있습니다.PHP에서 덤프 및 복원 (프레디)
redis 데이터베이스를 .rdb 형식으로 덤프 할 수 있습니까?
업데이트 :
내가 다음 명령을 사용하여/백업 데이터베이스를 덤프,
$redis->bgSave();
어떻게 내 데이터베이스로 다시 복원?
Malinga로 복원하는 것은 redis 서버를 다시 시작할 때 발생합니다. 그래서 당신은 appendonly 아니오를 설정해야합니다. 그래서 그것은 .rdb 파일을 사용할 것입니다.
$i = 0;
$json = array();
foreach($redis->keys('*') as $key) {
$data = array();
$data['key'] = $key;
$data['ttl'] = $redis->ttl($key);
$data['value'] = bin2hex($redis->dump($key));
$json[$i] = $data;
$i++;
}
header('Content-disposition: attachment; filename=database.json');
header('Content-type: application/json');
echo json_encode($json);
가져 오기 :
그래서, 백업 샘플 프로그램을 작성 레디 스 데이터베이스를 복원, 여기 code 할 수 있습니다 check
수출이다
if (isset($_POST['submit']) && $_POST['submit'] == 'Import') {
$types = array(
'application/json',
'application/octet-stream'
);
if (in_array($_FILES['upload']['type'], $types)) {
var_dump($_FILES);
if (move_uploaded_file($_FILES['upload']['tmp_name'], 'uploads/' . $_FILES['upload']['name']))
{
$file = file_get_contents('uploads/' . $_FILES['upload']['name'], "r");
$database = json_decode($file, true);
foreach($database as $data)
{
if ($data['ttl'] >= 0)
{
$data['ttl'] = $data['ttl'];
}
else
{
$data['ttl'] = 0;
}
if ($data['key'] && $data['value'] && !$redis->exists($data['key']))
{
$redis->restore($data['key'], $data['ttl'], hex2bin($data['value']));
}
}
}
}
}
전체 코드는를 통해 다운로드 할 수 있습니다.
redis에서는 SAVE 또는 BGSAVE를 사용하여 스냅 샷을 만들 수 있습니다. SAVE가 다른 모든 클라이언트를 차단하므로 BGSAVE를 사용하는 것이 좋습니다.
는 predis에, 그것은 predis으로 이것을 시도$client->executeRaw(['BGSAVE']);
미안 피난처를 통해 가능해야한다 그렇게하십시오. 그래서 먼저 확인 클라이언트는
$client->bgsave();
같은 것을가 레디 스 서버의 재시작 일어날 복원
이상 시도하지 않을 경우 허용하는 경우. 그래서 당신은 appendonly 아니오를 설정해야합니다. .rdb 파일을 사용할 수 있도록
예, 백업이 있습니다. 복원하려면 어떻게해야합니까? –
수정 된 답변 @ ŞivāSankĂr – Malinga
감사합니다. 덤프 및 복원 코드를 작성하려고합니다. 지금은 아이디어가 있기를 바랍니다. –