예제 #1
0
<?php

require_once dirname(__FILE__) . '/TinyRedisClient.class.php';
$client = new TinyRedisClient($argv[1]);
/* start */
$client->del('test:key');
/* strings */
assert($client->set('test:key', 'value') === 'OK');
assert($client->get('test:key') === 'value');
assert($client->del('test:key') === '1');
assert($client->get('test:key') === null);
/* exceptions */
try {
    $client->sadd('test:key', 'item1', 'item2');
    assert(false);
} catch (Exception $ex) {
}
/* sets */
assert($client->sadd('test:key', 'item1') === '1');
assert($client->sadd('test:key', 'item2') === '1');
assert($client->smembers('test:key') === array('item1', 'item2'));
assert($client->scard('test:key') === '2');
assert($client->del('test:key') === '1');
assert($client->scard('test:key') === '0');
assert($client->smembers('test:key') === array());
/* multi */
assert($client->sadd('test:key', 'item1') === '1');
assert($client->sadd('test:key', 'item2') === '1');
assert($client->multi() === 'OK');
assert($client->smembers('test:key') === 'QUEUED');
assert($client->smembers('test:key') === 'QUEUED');
 //Get the different sizes of the image
 $photo_sizes = $flickrObject->photos_getSizes($photo['id']);
 //We look the optimal size
 foreach ($photo_sizes as $size) {
     //Only get Medium Images for file sizes proposes
     if ($size['label'] == 'Medium 640') {
         $url = $size['source'];
     }
 }
 $line = $url . ":";
 //Uncomment this to see in the browser the image in thumbnail size
 //echo '<img alt="'.$photo['title'].'" src="'.$flickrObject->buildPhotoURL($photo, "square").'" />';
 //Uncomment this line to see in the browser the link of the URL
 //echo '<a rel="nofollow" target="_blank" href="'.$url.'">Link : </a>';
 //Add Image to Redis
 $redisClient->set($photo['id'], $url);
 $redisClient->expire($photo['id'], 50400);
 //Create the line with all the good tags
 //Initialize the clean line
 $tags_line = '';
 $wordsCounter = 1;
 //We process each tag to see if its work
 foreach ($array_tags as $tags) {
     //We only consider less than 10 tags
     if ($wordsCounter < 10) {
         $tag = $tags['_content'];
         //Clean the tags that has special characters
         if (!preg_match('/[^a-zA-Z]+/', $tag)) {
             if (strlen($tag) < 15) {
                 $tags_line .= $tag . ",";
             }