Fix check to see if link exists in db or not.

This seemed like the most friendly way to do this since my other option is checking all links:id for the string of the url
This commit is contained in:
alopexc0de 2014-08-10 20:37:34 -04:00
parent 9e1035fde3
commit 39baade2e4
No known key found for this signature in database
GPG Key ID: 48E847F18074C953
1 changed files with 10 additions and 5 deletions

View File

@ -17,19 +17,22 @@
*/
function shorten($redis, $link, $linkage, $seperator){
$short = $redis->get("links:id:$link");
$short = $redis->get("llinks:$link");
if($short){
$title = $redis->get("links:title:$link");
return "1$seperator$link$seperator$title";
$sId = $short;
$short = $redis->lrange("links:$short", 0, 1);
$title = $short[1];
return "1$seperator$sId$seperator$title";
}else{
do {
if(checkRemoteFile($link) !== true) return "2$seperator$link";
$title = getRemoteTitle($url);
//if(($title = getRemoteTitle($url)) !== true) return "2$seperator$link";
$title = "google";
$short = substr(number_format(time() * mt_rand(),0,'',''),0,5);
$short = base_convert($short, 10, 36);
if(!$redis->exists("links:id:$short")) {
if(!$redis->exists("links:$short")) {
break;
}
} while (1);
@ -42,10 +45,12 @@
if($linkage == '1') $xTime = 604800;
if($linkage == '2') $xTime = 2628000;
$redis->set("llinks:$link", $short);
$redis->rpush("links:$short", $link);
$redis->rpush("links:$short", $title);
$redis->rpush("links:$short", date("d/m/Y", strtotime($str)));
$redis->expireAt("links:$short", $now+$xTime);
$redis->expireAt("llinks:$link", $now+$xTime);
$redis->zAdd("tracking:clicks", 1, $link);