public static function test_redisserver() { global $configs; //-- if (SMART_FRAMEWORK_TESTUNIT_ALLOW_REDIS_TESTS !== true) { return SmartComponents::operation_notice('Test Unit for Redis Server is DISABLED ...'); } //end if //-- //-- if (SmartPersistentCache::isActive()) { //-- $redis_big_content = self::pack_test_archive(); // CREATE THE Test Archive (time not counted) //-- $redis_test_key = 'redis-test-key_' . Smart::uuid_10_num() . '-' . Smart::uuid_36() . '-' . Smart::uuid_45(); $redis_test_value = array('unicode-test' => '"Unicode78źź:ăĂîÎâÂșȘțȚşŞţŢグッド', 'big-key-test' => (string) $redis_big_content, 'random-key' => Smart::uuid_10_str() . '.' . Smart::random_number(1000, 9999)); $redis_test_checkum = sha1(implode("\n", (array) $redis_test_value)); $redis_test_arch_content = SmartUtils::cache_variable_archive($redis_test_value); $redis_test_arch_checksum = sha1($redis_test_arch_content); //-- $tests = array(); $tests[] = '##### Redis / TESTS (Persistent Cache) with a Variable Key-Size of ' . SmartUtils::pretty_print_bytes(strlen($redis_test_arch_content), 2) . ' : #####'; //-- $err = ''; //-- if ((string) $err == '') { $tests[] = 'Building a Test Archive file for Redis Tests (time not counted)'; // archive was previous created, only test here if ((string) $redis_big_content == '') { $err = 'Failed to build the Test Archive file for the Redis Test (see the error log for more details) ...'; } //end if } //end if //-- $time = microtime(true); $tests[] = '++ START Counter ...'; //-- if ((string) $err == '') { $tests[] = 'Building the Cache Archive'; if ((string) $redis_test_arch_content == '') { $err = 'Failed to build the Cache Variable(s) Archive file for the Redis Test (see the error log for more details) ...'; } //end if } //end if //-- if ((string) $err == '') { $tests[] = 'Set a short Redis Key (auto-expire in 3 seconds)'; $redis_set_key = SmartPersistentCache::setKey('redis-server-tests', $redis_test_key, (string) $redis_test_value['unicode-test'], 3); if ($redis_set_key !== true) { $err = 'Redis SetKey (short) returned a non-true result: ' . "\n" . $redis_test_key; } //end if if ((string) $err == '') { $tests[] = 'Wait 5 seconds for Redis Key to expire, then check again if exists (time not counted)'; sleep(5); // wait the Redis Key to Expire $time = (double) $time + 5; // ignore those 5 seconds (waiting time) to fix counter $tests[] = '-- FIX Counter (substract the 5 seconds, waiting time) ...'; if (SmartPersistentCache::keyExists('redis-server-tests', $redis_test_key)) { $err = 'Redis (short) Key does still exists (but should be expired after 5 seconds) and is not: ' . "\n" . $redis_test_key; } //end if } //end if } //end if //-- if ((string) $err == '') { $tests[] = 'Set a long Redis Key (will not expire)'; $redis_set_key = SmartPersistentCache::setKey('redis-server-tests', $redis_test_key, $redis_test_arch_content); if ($redis_set_key !== true) { $err = 'Redis SetKey (long) returned a non-true result: ' . "\n" . $redis_test_key; } //end if } //end if //-- if ((string) $err == '') { $tests[] = 'Check if Redis Key exists (after set)'; if (!SmartPersistentCache::keyExists('redis-server-tests', $redis_test_key)) { $err = 'Redis Key does not exists: ' . "\n" . $redis_test_key; } //end if } //end if //-- if ((string) $err == '') { $tests[] = 'Get Redis Key'; $redis_cached_value = SmartUtils::cache_variable_unarchive(SmartPersistentCache::getKey('redis-server-tests', $redis_test_key)); if (Smart::array_size($redis_cached_value) > 0) { $tests[] = 'Check if Redis Key is valid (array-keys)'; if ((string) $redis_cached_value['unicode-test'] != '' and (string) $redis_cached_value['big-key-test'] != '') { $tests[] = 'Check if Redis Key is valid (checksum)'; if ((string) sha1(implode("\n", (array) $redis_cached_value)) == (string) $redis_test_checkum) { if ($redis_test_value === $redis_cached_value) { $tests[] = 'Unset Redis Key'; $redis_unset_key = SmartPersistentCache::unsetKey('redis-server-tests', $redis_test_key); if ($redis_unset_key === true) { $tests[] = 'Check if Redis Key exists (after unset)'; if (SmartPersistentCache::keyExists('redis-server-tests', $redis_test_key)) { $err = 'Redis Key does exists (after unset) and should not: ' . "\n" . $redis_test_key; } else { // OK } //end if } else { $err = 'Redis UnSetKey returned a non-true result: ' . "\n" . $redis_test_key; } //end if else } else { $err = 'Redis Cached Value is broken: comparing stored value with original value failed on key: ' . "\n" . $redis_test_key; } //end if else } else { $err = 'Redis Cached Value is broken: checksum failed on key: ' . "\n" . $redis_test_key; } //end if else } else { $err = 'Redis Cached Value is broken: array-key is missing after Cache-Variable-Unarchive on key: ' . "\n" . $redis_test_key; } //end if } else { $err = 'Redis Cached Value is broken: non-array value was returned after Cache-Variable-Unarchive on key: ' . "\n" . $redis_test_key; } //end if } //end if //-- $title = 'SmartFramework Redis Server Tests: DONE ...'; //-- $time = 'TOTAL TIME (Except building the test archive) was: ' . (microtime(true) - $time); // substract the 3 seconds waiting time for Redis Key to expire //-- $end_tests = '##### END TESTS ... ' . $time . ' sec. #####'; //-- if ((string) $err == '') { $img_sign = 'lib/core/img/sign_info.png'; $img_check = 'lib/core/img/q_completed.png'; $text_main = Smart::escape_js('<span style="color:#83B953;">Good ... Perfect :: グッド ... パーフェクト</span>'); $text_info = Smart::escape_js('<h2><span style="color:#83B953;">All</span> the SmartFramework Redis Server Operations <span style="color:#83B953;">Tests PASSED on PHP</span><hr></h2><span style="font-size:14px;">' . Smart::nl_2_br(Smart::escape_html(implode("\n" . '* ', $tests) . "\n" . $end_tests)) . '</span>'); } else { $img_sign = 'lib/core/img/sign_error.png'; $img_check = 'lib/core/img/q_warning.png'; $text_main = Smart::escape_js('<span style="color:#FF5500;">An ERROR occured ... :: エラーが発生しました ...</span>'); $text_info = Smart::escape_js('<h2><span style="color:#FF5500;">A test FAILED</span> when testing Redis Server Operations.<span style="color:#FF5500;"><hr>FAILED Test Details</span>:</h2><br><span style="font-size:14px;"><pre>' . Smart::escape_html($err) . '</pre></span>'); } //end if else //-- } else { //-- $title = 'SmartFramework Redis Server Tests - Redis Server was NOT SET ...'; //-- $img_sign = 'lib/core/img/sign_info.png'; $img_check = 'lib/core/img/q_warning.png'; $text_main = Smart::escape_js('<span style="color:#778899;">No Redis Server Tests performed ...</span>'); $text_info = '<h2>The current configuration have not set the Redis Server ...</h2>'; //-- } //end if //-- //-- $html = <<<HTML <h1>{$title}</h1> <script type="text/javascript"> \tSmartJS_BrowserUtils.alert_Dialog( \t\t'<img src="{$img_sign}" align="right"><h1>{$text_main}</h1><hr><span style="color:#333333;"><img src="{$img_check}" align="right">{$text_info}<br>', \t\t'', \t\t'Redis Server Test Suite for SmartFramework: PHP', \t\t'725', \t\t'480' \t); </script> HTML; //-- //-- return $html; //-- }
/** * Get a Page from the (Persistent) Cache. * * @param STRING $storage_namespace :: the cache storage namespace, used to group keys * @param STRING $unique_key :: the unique cache key * * @return MIXED :: If the PersistentCache is active and value was set will return a single (STRING) or multiple (ARRAY) Page Settings / Page Values ; otherwise will return a NULL value. */ public final function PageGetFromCache($storage_namespace, $unique_key) { //-- if (!SmartPersistentCache::isActive()) { return null; } //end if //-- if (!SmartPersistentCache::keyExists((string) $storage_namespace, (string) $unique_key)) { return null; } //end if //-- $cache = SmartPersistentCache::getKey((string) $storage_namespace, (string) $unique_key); //-- if ($cache === null or (string) $cache == '') { return null; } //end if //-- return SmartUtils::cache_variable_unarchive($cache); // mixed (number / string / array) //-- }