예제 #1
1
 function getUser($uid)
 {
     $key = self::$prefix . 'user_' . $uid;
     $ret = $this->redis->get($key);
     $info = unserialize($ret);
     return $info;
 }
예제 #2
0
 /**
  * 检查是否超过了频率限制,如果超过返回false,未超过返回true
  * @param $key
  * @param $limit
  * @return bool
  */
 function exceed($key, $limit)
 {
     $key = self::PREFIX . $key;
     $count = $this->redis->get($key);
     if (!empty($count) and $count > $limit) {
         return true;
     } else {
         return false;
     }
 }
예제 #3
0
 function onTimer()
 {
     $newVersion = $this->redis->get(self::KEY_NODE_VERSION);
     if ($newVersion) {
         $ver = json_decode($newVersion, true);
         if (!$ver) {
             $this->log("json_decode failed. error Version Config: {$newVersion}");
         }
         //有最新的版本
         if (String::versionCompare($ver['version'], $this->nodeCurrentVersion['version']) > 0) {
             $this->nodeCurrentVersion = $ver;
             $this->log("found new node-agent version [{$ver['version']}]");
         }
     } else {
         $this->log("redis->get(" . self::KEY_NODE_VERSION . ") failed.");
     }
 }
예제 #4
0
 /**
  * Retrieve item from the server
  *
  * CacheRedis::get() returns previously stored data if an item with such $key exists on the server at this moment.
  *
  * @param string $key The key to fetch
  * @param int $modified_time 	Unix time of data modified.
  * 								If stored time is older then modified time, return false.
  * @return false|mixed Return false on failure or older then modified time. Return the string associated with the $key on success.
  */
 function get($key, $modified_time = 0)
 {
     $_key = $this->getKey($key);
     $obj = $this->redis->get($_key);
     $obj = $obj ? unserialize($obj) : false;
     if (!$obj || !is_array($obj)) {
         return false;
     }
     if ($modified_time > 0 && $modified_time > $obj[0]) {
         $this->redis->del($_key);
         return false;
     }
     return $obj[1];
 }
예제 #5
0
 public function __construct()
 {
     $redis = new \redis();
     $redis->pconnect('127.0.0.1', '6379', '0.0');
     $this->redis = $redis;
     $this->access_token = $redis->get('access_token');
     if (!$this->access_token) {
         $appId = Config::get('wechat.app_id');
         $appSecret = Config::get('wechat.secret');
         $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appId . '&secret=' . $appSecret . '';
         $res = Curl::get($url);
         $arr = json_decode($res);
         $access_token = $arr->access_token;
         $time_out = $arr->expires_in;
         $this->redis->set('access_token', $access_token);
         $this->redis->expire('access_token', $time_out);
         $this->access_token = $access_token;
     }
 }
예제 #6
0
$Redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY);
/* retry when we get no keys back */
while ($keys = $Redis->scan($it)) {
    $out = '';
    foreach ($keys as $key) {
        //echo $Redis->type($key),"\n";
        $arr = array();
        $type = $Redis->type($key);
        $expire = $Redis->ttl($key);
        switch ($type) {
            case $Redis::REDIS_STRING:
                //echo "string\n";
                $arr['expire'] = $expire;
                $arr['type'] = $type;
                $arr['key'] = $key;
                $arr['val'] = $Redis->get($key);
                break;
            case $Redis::REDIS_HASH:
                //echo "hash\n";
                $arr['expire'] = $expire;
                $arr['type'] = $type;
                $arr['key'] = $key;
                $arr['val'] = $Redis->hGetAll($key);
                break;
            case $Redis::REDIS_LIST:
                //echo "list\n";
                $arr['expire'] = $expire;
                $arr['type'] = $type;
                $arr['key'] = $key;
                $arr['val'] = $Redis->lRange($key, 0, -1);
                break;
예제 #7
0
파일: Redis.php 프로젝트: pan269/php-webim
 function getUser($userid)
 {
     $ret = $this->redis->get($userid);
     $info = unserialize($ret);
     return $info;
 }
예제 #8
0
파일: Home.php 프로젝트: sinfey69/enyphp
 public function redis()
 {
     var_dump(redis::set('name', 'enychen'));
     var_dump(redis::get('name'));
 }
예제 #9
0
파일: redis2.php 프로젝트: myersguo/phpio
    {
    }
    function get($key)
    {
    }
}
class myredis
{
    function __construct($redis)
    {
        $this->_redis = $redis;
    }
    public function __call($name, $args)
    {
        return call_user_func_array(array($this->_redis, $name), $args);
    }
}
$redis = new redis();
$redis->connect('127.0.0.1');
$redis->set('key1', rand());
$redis->get('key1');
$myredis = new myredis($redis);
$myredis->set('key2', rand());
$myredis->get('key2');
$redis2 = new redis2();
$redis2->connect('127.0.0.1');
$redis2->set('key3', rand());
$redis2->get('key3');
$myredis2 = new myredis($redis2);
$myredis2->set('key4', rand());
$myredis2->get('key4');
예제 #10
0
파일: Abstract.php 프로젝트: vzina/yaf-api
 public function find($key)
 {
     return $this->_redis->get($key);
 }
예제 #11
0
<?php

$con = mysql_connect('localhost', 'root', '123');
mysql_select_db('qxy_istrone');
$sql = 'select ID, post_title, post_content from wp_posts where post_status= "publish" and post_title != "" order by post_date desc limit 30';
$query = mysql_query($sql);
mysql_close($con);
$redis = new redis();
$redis->pconnect('127.0.0.1');
$real_data = array();
$i = 0;
while ($data = mysql_fetch_assoc($query)) {
    $real_data['{{link_' . $i . '}}'] = 'http://7magic.istrone.com/f/' . $data['ID'];
    $real_data['{{text_' . $i . '}}'] = $data['post_title'];
    $redis->set($data['ID'], json_encode(array('{{title}}' => $data['post_title'], '{{content}}' => $data['post_content'], '{{src_url}}' => 'http://istrone.com/?p=' . $data['ID'])));
    $i++;
}
$redis->set('home', json_encode($real_data));
$redis_get_binary = $redis->get('home');
echo $redis_get_binary . "\n";
$redis->close();
예제 #12
0
 function getUser($client_id)
 {
     $ret = $this->redis->get(self::$prefix . 'client_' . $client_id);
     $info = unserialize($ret);
     return $info;
 }
예제 #13
0
파일: get.php 프로젝트: biglazy/gist
#!/usr/bin/php

<?php 
$redis = new redis();
$result = $redis->connect('127.0.0.1', 6379);
if (!$result) {
    die("Redis连接失败;\n");
}
$get_result = $redis->get('test1');
var_dump($get_result);
if ($get_result === false) {
    die("Redis get 操作失败;\n");
} else {
    echo "Value : " . $get_result . "\n";
    die("Redis get 操作成功;\n");
}
예제 #14
0
#!/usr/bin/php

<?php 
// 10s redis get 测试
$redis = new redis();
$result = $redis->connect('127.0.0.1', 6379);
if (!$result) {
    die("Redis连接失败;\n");
}
$time_limit = 10;
$time_start = time();
$time_length = 0;
$i = 0;
$error_num = 0;
while ($time_length <= $time_limit) {
    $i++;
    //$get_result = $redis->get('test:'.rand(1,100000));
    $get_result = $redis->get('test:88888');
    if ($get_result === false) {
        $error_num++;
    }
    $time_length = time() - $time_start;
}
echo "Total time : " . $time_limit . " s .\n";
echo "All : " . $i . "\n";
echo "Error : " . $error_num . "\n";
예제 #15
0
<?php

header("Content-type:text/html;charset=utf-8");
session_start();
//这个很重要
// $_SESSION['test_session']= @array('name' =>'fanqie' , 'ccc'=>'hello redis ');
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
echo 'sessionid>>>>>>> PHPREDIS_SESSION:' . session_id();
echo '<br/>';
echo '<br/>';
//redis用session_id作为key并且是以string的形式存储
echo '通过php用redis获取>>>>>>>' . $redis->get('PHPREDIS_SESSION:' . session_id());
echo '<br/>';
echo '<br/>';
echo '通过php用session获取>>>>>>><br/>';
echo '<pre>';
// var_dump($_SESSION['test_session']);
echo '</pre>';
예제 #16
0
<?php

header("content-type:text/html;charset=utf-8");
$redis = new redis();
$result = $redis->connect('127.0.0.1', 6379);
$mywatchkey = $redis->get("mywatchkey");
$rob_total = 10;
//抢购数量
if ($mywatchkey < $rob_total) {
    $redis->watch("mywatchkey");
    $redis->multi();
    //设置延迟,方便测试效果。
    sleep(5);
    //插入抢购数据
    $redis->hSet("mywatchlist", "user_id_" . mt_rand(1, 9999), time());
    $redis->set("mywatchkey", $mywatchkey + 1);
    $rob_result = $redis->exec();
    if ($rob_result) {
        $mywatchlist = $redis->hGetAll("mywatchlist");
        echo "抢购成功!<br/>";
        echo "剩余数量:" . ($rob_total - $mywatchkey - 1) . "<br/>";
        echo "用户列表:<pre>";
    } else {
        echo "手气不好,再抢购!";
        exit;
    }
}
?>
  
예제 #17
0
파일: ssdb.php 프로젝트: tianyunchong/php
<?php

/**
 * 查询下关键词信息的ssdb的存储
 */
$type = "pd";
$keyword = "冰岛鲨鱼肝油软胶囊";
$key = 'wd:' . $type . ':' . $keyword;
$redis = new redis();
$redis->pconnect('172.17.16.47', 6380, 1);
$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE);
$rs = $redis->get($key);
var_dump($rs);