/**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     if (\Auth::check() == false) {
         return redirect('/auth/login');
     }
     // 一页多少文章
     $pageNum = 8;
     $userInfo = \Auth::user();
     $data = array();
     $data['articles'] = \App\Article::latest()->get();
     $data['userInfo'] = $userInfo;
     $dataArticles = array();
     $cacheKey = 'laravel:articles:index';
     $redis = new \Predis\Client(array('host' => '127.0.0.1', 'port' => 6379));
     $dataArticles = $redis->get($cacheKey);
     if (!$dataArticles || true) {
         //$dataArticles = \App\Article::latest()->take($pageNum)->with('content')->get()->toArray();
         $dataArticles = \App\Article::latest()->with('content')->paginate($pageNum)->toArray();
         //             var_dump($dataArticles);exit();
         $redis->setex($cacheKey, 3600 * 12, serialize($dataArticles));
     } else {
         $dataArticles = unserialize($dataArticles);
     }
     $data['articles'] = $dataArticles;
     //var_dump($data);exit();
     // $articleArr[0]['relations']['content']['content']
     return view('articles.admin.articleList')->with('data', $data);
 }
示例#2
0
 /**
  * @param $query string
  * @param $value array
  *
  * @return void|null
  */
 protected function _setInCache($query, $value)
 {
     if ($this->cacheTTL == 0) {
         return null;
     }
     if (isset($this->cache_con) && !empty($this->cache_con)) {
         $this->cache_con->setex(md5($query), $this->cacheTTL, serialize($value));
     }
 }
 public function QRcode()
 {
     \Predis\Autoloader::register();
     $redis = new \Predis\Client();
     //生成二维码
     $numberid = M('randnumber')->add(array('openid' => ''));
     $token = base64_encode(authcode($numberid, "ENCODE", SESSION_AUTH));
     //设置标志有效时间
     $redis->setex('__WX_NUMBERID_' . $numberid, 300, 'true');
     $rs = json_decode(Http::CurlRequst("http://api.wwei.cn/wwei", array("data" => $token, 'apikey' => 20150828111302), "GET"), true);
     $this->assign('erweima', $rs['data']['qr_filepath']);
     $this->assign('token', $token);
     $this->display();
 }
 /**
  * Sets a value in cache.
  *
  * The value is set whether or not this key already exists in Redis.
  *
  * @param   string $key        The key under which to store the value.
  * @param   mixed  $value      The value to store.
  * @param   string $group      The group value appended to the $key.
  * @param   int    $expiration The expiration time, defaults to 0.
  * @return  bool               Returns TRUE on success or FALSE on failure.
  */
 public function set($key, $value, $group = 'default', $expiration = 0)
 {
     $derived_key = $this->build_key($key, $group);
     $result = true;
     // save if group not excluded from redis and redis is up
     if (!in_array($group, $this->no_redis_groups) && $this->redis_status()) {
         $expiration = $this->validate_expiration($expiration);
         if ($expiration) {
             $result = $this->parse_predis_response($this->redis->setex($derived_key, $expiration, maybe_serialize($value)));
         } else {
             $result = $this->parse_predis_response($this->redis->set($derived_key, maybe_serialize($value)));
         }
     }
     // if the set was successful, or we didn't go to redis
     if ($result) {
         $this->add_to_internal_cache($derived_key, $value);
     }
     return $result;
 }
示例#5
0
     } else {
         //$card_message = explode("|",$card_message);
     }
     $card_message_arr = explode("|", $card_message);
     for ($i = 0; $i < count($card_message_arr); $i++) {
         //var_dump(iconv_strlen($card_message,'utf-8'));
         ANTI_SPAM($card_message_arr[$i], array('minLength' => 0, 'maxLength' => 10));
     }
     //每次结算要记录一个ip防止被刷
     $current_ip = GET_IP();
     $_key = 'checkout_times_' . $current_ip;
     $_value;
     if ($REDIS_CLIENT->exists($_key)) {
         $_value = intval($REDIS_CLIENT->get($_key));
         $_value += 1;
         $REDIS_CLIENT->setex($_key, 24 * 3600, $_value);
     } else {
         $REDIS_CLIENT->setex($_key, 24 * 3600, 1);
     }
     echo MES_Order::checkout($card_message);
 } else {
     if ($action == 'done') {
         $token = $_POST['token'];
         $pay_id = $_POST['pay_id'];
         echo MES_Order::done($token, $pay_id);
     } else {
         if ($action == 'add_to_cart') {
             //add an cake or fork to your cart
             $_POST['goods'] = strip_tags(urldecode($_POST['goods']));
             $_POST['goods'] = json_str_iconv($_POST['goods']);
             $goods = $_POST['goods'];
示例#6
0
function S($name, $value = '', $time = '')
{
    $client = new Predis\Client($GLOBALS['redisConfig']);
    if ('' === $value) {
        // 获取缓存
        return json_decode($client->get($name), true);
    } elseif (is_null($value)) {
        // 删除缓存
        return $client->set($name, null);
    } else {
        // 缓存数据
        $value = json_encode($value);
        if (empty($time)) {
            return $client->set($name, $value);
        } else {
            return $client->setex($name, $time, $value);
        }
    }
}
 /**
  * Sets a value in cache.
  *
  * The value is set whether or not this key already exists in Redis.
  *
  * @param   string $key        The key under which to store the value.
  * @param   mixed  $value      The value to store.
  * @param   string $group      The group value appended to the $key.
  * @param   int    $expiration The expiration time, defaults to 0.
  * @return  bool               Returns TRUE on success or FALSE on failure.
  */
 public function set($key, $value, $group = 'default', $expiration = 0)
 {
     $derived_key = $this->build_key($key, $group);
     // If group is a non-Redis group, save to internal cache, not Redis
     if (in_array($group, $this->no_redis_groups) || !$this->can_redis()) {
         $this->add_to_internal_cache($derived_key, $value);
         return true;
     }
     // Save to Redis
     $expiration = abs(intval($expiration));
     if ($expiration) {
         $result = $this->parse_predis_response($this->redis->setex($derived_key, $expiration, $value));
     } else {
         $result = $this->parse_predis_response($this->redis->set($derived_key, $value));
     }
     return $result;
 }
示例#8
0
 /**
  * 设置缓存,按需重载
  * @param string $cachename
  * @param mixed $value
  * @param int $expired
  * @return boolean
  */
 protected function setCache($cachename, $value, $expired = 7000)
 {
     //TODO: set cache implementation
     \Predis\Autoloader::register();
     $redis = new \Predis\Client();
     $redis->setex($cachename, $expired, $value);
     if ($redis) {
         return true;
     }
     return false;
 }
示例#9
0
<?php

// $redis = new Redis();
// $redis->connect('192.168.40.129',6379);
// $redis->set('key','wower',10);
// echo $redis->get('key');
// print_r($redis);
require_once "./predis/Autoloader.php";
Predis\Autoloader::register();
$config = ["scheme" => "tcp", "host" => "localhost", "port" => 6379];
$redis = new Predis\Client($config);
// print_r($redis);
$redis->setex('key', 10, 'cer&phper');
echo $value = $redis->get('key') . "\n";
$redis->setex('key1', 10, 'pythoner&goer');
echo $value1 = $redis->get('key1') . "\n";
sleep(5);
echo $redis->ttl("key1");
// $redis->del('key');
// $redis->flush();
示例#10
0
        } else {
            if ($width < 350) {
                //too small
                coninue;
            } else {
                $tmp['url'] = $img;
                $tmp['title'] = $row['post_title'];
                $tmp['width'] = $width;
                $tmp['height'] = $height;
                array_push($rs, $tmp);
            }
        }
    }
    $encodedJson = json_encode($rs);
    echo $encodedJson;
    $redis->setex($redis_key, $seconds_of_caching, $encodedJson);
    //this caches it!!
    mysqli_close($con);
}
function get_first_img($content)
{
    $first_img = '';
    $content = str_replace("<!--more  -->", "", $content);
    $content = str_replace("><img", "> <img", $content);
    $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches);
    $first_img = $matches[1][0];
    if (empty($first_img)) {
        //if we do not find an image try to find one via string split
        $split = split("<img src=", $content);
        //echo $split[1];
        $first_img = split(" alt=", $split[1]);
示例#11
0
<?php

/* 
* =====================================
* Website: http://netkiller.github.com
* Author: neo <*****@*****.**>
* Email: netkiller@msn.com
* =====================================
*/
require 'SharedConfigurations.php';
$single_server = array('host' => '127.0.0.1', 'port' => 6379, 'database' => 0);
$multiple_servers = array(array('host' => '127.0.0.1', 'port' => 6379, 'database' => 15, 'alias' => 'first'), array('host' => '127.0.0.1', 'port' => 6380, 'database' => 15, 'alias' => 'second'));
$client = new Predis\Client($single_server, array('prefix' => 'fw:'));
$key = $_SERVER['REMOTE_ADDR'];
if (!$client->exists($key)) {
    $client->setex($key, 20, 1);
} else {
    $client->incrby($key, 1);
}
$counter = $client->get($key);
if ($counter > 10) {
    echo 'Deny';
}
print_r($client->get($key));
//var_dump($client->keys('*'));