public function submit($value)
 {
     require_once 'redis/RedisController.php';
     // $value='f**k'.time();
     $redis = new RedisController();
     $redis->setMessageSS($_SESSION['username'], $value);
     $arr = array('success' => '1', 'name' => 'zuston', 'text' => $value);
     echo json_encode($arr);
 }
 public function getMessageByTimestamp($username)
 {
     $timestamp = (double) $this->redisInstance->get($username . '-timestamp');
     // echo $timestamp;
     // return $this->redisInstance->zrangebyscore($username.'-content',$timestamp,2020202020);
     $userSorts = RedisController::getLoginHashMapAll();
     foreach ($userSorts as $key => $value) {
         # code...
         // $timestamp=(double)$this->redisInstance->get($key.'-timestamp');
         $userContent = $this->redisInstance->zrangebyscore($key . '-content', $timestamp, 2020202020);
         if (is_array($userContent)) {
             foreach ($userContent as $k => $v) {
                 # code...
                 $this->contents[] = $v;
                 // 将时间戳保存在数组,转换为正常时间
                 $creatTime = $this->redisInstance->zscore($key . '-content', $v);
                 $creatTime = date('Y-m-d H:i:s', $creatTime);
                 $this->contents[] = $creatTime;
             }
         }
     }
     /*排序数组*/
     // ksort($this->contents);
     return $this->contents;
 }
<?php

function __autoload($classname)
{
    if (file_exists($classname . '.php')) {
        require_once $classname . '.php';
    } else {
        echo 'can not find the ' . $classname . ' the php file';
    }
}
$redis = new RedisController();
// $redis->setHashMap();
var_dump($redis->getMessageByTimestamp('user1'));
// $redis->test();
Exemple #4
0
<?php

namespace Mauricext4fs\Redis;

// Static require, only testing the current module
require_once __DIR__ . "/../src/Mauricext4fs/Redis/RedisController.php";
$objRedis = new RedisController();
printf("Starting new Set Test" . PHP_EOL);
// Adding duplicate ascii element to a set
$strSetName = uniqid();
$arrSet = array("test1", "test2", "test3", "test3", "test4");
foreach ($arrSet as $strValue) {
    $objRedis->addValueToSet($strSetName, $strValue);
}
// getting the set back
$arrSetFromRedis = $objRedis->getSet($strSetName);
// Check that all value from the orginal value exist in Redis
printf("Check value from original set from Redis.......         ");
$boolFail = false;
foreach ($arrSet as $strKey => $strValue) {
    if (!in_array($strValue, $arrSetFromRedis)) {
        printf("Fail! %s", PHP_EOL);
        $boolFail = true;
        break;
    }
}
if ($boolFail === false) {
    printf("OK!%s", PHP_EOL);
}
// Check that all value from Redis set exist in the orginal value
printf("Check value from Redis set in original set.......      ");
<?php

require_once 'redis/RedisController.php';
if (empty($_POST['time'])) {
    exit;
}
set_time_limit(0);
//无限请求超时时间
// 设置用户名称
// $username=$_SESSION['username'];
$username = '******';
// 登录时保存全局变量
$redis = new RedisController();
$i = 0;
while (true) {
    # code...
    usleep(2000000);
    $i++;
    $value = $redis->getMessageByTimestamp($username);
    if (!$value == null) {
        $timestamp = (double) time();
        $redis->setUserTimestamp($username, $timestamp);
        $arr = array('success' => '1', 'name' => 'zuston', 'text' => $value);
        echo json_encode($arr);
        exit;
    } else {
        echo 'error';
        exit;
    }
    if ($i == $_POST['time']) {
        $arr = array('success' => '0', 'name' => 'zuston', 'text' => 'error');
<?php

require_once 'redis/RedisController.php';
$redis = new RedisController();
$num = time();
$v = $redis->getMessageByTimestamp('user1');
var_dump($v);
Exemple #7
0
<?php

namespace Mauricext4fs\Redis;

// Static require, only testing the current module
require_once __DIR__ . "/../src/Mauricext4fs/Redis/RedisController.php";
$objRedis = new RedisController();
printf("Starting standard test" . PHP_EOL);
// Adding duplicate ascii element to a set
$strKey = uniqid();
// Check that all value from the orginal value exist in Redis
printf("Set and Get test.......                               ");
$boolFail = false;
$objRedis->set($strKey, "test3");
$strResponse = $objRedis->get($strKey);
if ($strResponse !== "test3") {
    printf("Fail! %s", PHP_EOL);
    $boolFail = true;
} else {
    printf("OK!%s", PHP_EOL);
}
// Check that all value from Redis set exist in the orginal value
printf("delete test .......      ");
$boolFail = false;
$objRedis->delete($strKey);
$strResponse = $objRedis->get($strKey);
if (!empty($strResponse)) {
    printf("Fail! %s", PHP_EOL);
    $boolFail = true;
    break;
} else {
Exemple #8
0
 /**
  * Helper function to get number of entries in REDIS
  * Probably not needed, it's an indirect way of calling a static
  * method of a controller with a singleton reference to the connection
  * Anyway, it works..
  *
  * @return int
  */
 public static function getRedisCount()
 {
     //$num = Controller::call('\Redis@getNumKeys', array());
     $num = \RedisController::getNumKeys();
     return $num;
 }
Exemple #9
0
<?php

namespace Mauricext4fs\Redis;

// Static require, only testing the current module
require_once __DIR__ . "/../src/Mauricext4fs/Redis/RedisController.php";
$objRedis = new RedisController();
printf("Starting new List Test" . PHP_EOL);
// Adding duplicate ascii element to a set
$strListName = uniqid();
$arrList = array("test1", "test2", "test3", "test3", "test4");
foreach ($arrList as $strValue) {
    $objRedis->addValueToList($strListName, $strValue);
}
// getting the List back
$arrListFromRedis = $objRedis->getList($strListName);
// Check that all value from the orginal value exist in Redis
printf("Check value from original List from Redis.......         ");
$boolFail = false;
foreach ($arrList as $strKey => $strValue) {
    if (!in_array($strValue, $arrListFromRedis)) {
        printf("Fail! %s", PHP_EOL);
        $boolFail = true;
        break;
    }
}
if ($boolFail === false) {
    printf("OK!%s", PHP_EOL);
}
// Check that all value from Redis List exist in the orginal value
printf("Check value from Redis List in original List.......      ");