1
0
mirror of https://github.com/gamaio/lobli.git synced 2025-01-22 15:23:15 +00:00
lobli/Database/redis.php
alopexc0de fe5e5f1854
Mysql to Redis migration helper.
Pretty hacky way of doing this, fetches needed data from table and adds them to the redis db.
Run it from the command line: $ php redis.php
set your password as needed
2014-08-15 18:31:20 -04:00

39 lines
1.0 KiB
PHP

<?php
$ids = 461;
echo "mysql to redis migrator\nThis is very specific for the link shortener, and assumes 460 entries in table.\n";
echo "Connecting to databases...\n";
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$mysql = new mysqli('localhost', 'short', 'password', 'short');
if($mysql->connect_errno > 0) die('Unable to connect to database ['.$mysql->connect_error.']');
echo "Starting the migration (This can take a while).\n";
for($id=1; $id<=$ids; $id++){
echo "Starting id:$id of $ids... ";
$sql = "SELECT * FROM `links` WHERE `id`='$id'";
if($result = $mysql->query($sql)){
if($row = $result->fetch_assoc()){
$link = $row['link'];
$short = $row['shortlink'];
$title = "Empty Title"; // Titles aren't in the mysql db
$date = $row['date'];
$redis->set("llinks:$link", $short);
$redis->rpush("links:$short", $link);
$redis->rpush("links:$short", $title);
$redis->rpush("links:$short", $date);
echo "Done!\n";
}
}
}
echo "\n";
?>