예제 #1
0
 public function it_can_lrange()
 {
     $this->redis->lrange('test', 0, 10)->shouldBeCalled()->willReturn(['test']);
     $this->lRange('test', 0, 10)->shouldReturn(['test']);
     $this->redis->lrange('test', 0, 10)->willThrow(new \RedisException());
     $this->shouldThrow(DriverException::class)->during('lRange', ['test', 0, 10]);
 }
예제 #2
0
 /**
  * 主界面
  */
 public function index()
 {
     if (Auth::check()) {
         $cartkey = Auth::user()->front_uid;
     } else {
         $cartkey = $this->getIP();
     }
     $key = 'laravel:user:'******':cart';
     $shop_id = Redis::lrange($key, 0, 0);
     $ids = array_count_values(Redis::lrange($key, 1, -1));
     $shop = Shop::find($shop_id[0]);
     $cart_list = array();
     $cart_amount = 0;
     // 商品总价格
     $i = 0;
     foreach ($ids as $id => $amount) {
         $good = Menu::find($id);
         $cart_list[$i] = array('good_name' => $good->title, 'good_id' => $id, 'good_price' => $good->price, 'good_amount' => $amount, 'good_total' => $good->price * $amount);
         $cart_amount += $cart_list[$i]['good_total'];
         $i++;
     }
     $output = array('userbar' => $this->getUserBar(), 'deliver_place' => Session::get('deliver_place'), 'deliver_tel' => Session::get('deliver_tel'), 'deliver_name' => Session::get('deliver_name'), 'deliver_time' => array('08:00', '09:00', '10:12', '12:30'), 'data' => array('user_name' => '注释用户名', 'shop_path' => '', 'shop_id' => $shop->id, 'shop_logo' => $shop->pic, 'shop_name' => $shop->name, 'shop_href' => url('shop/' . $shop->id), 'shop_type' => $shop->type, 'cart_list' => $cart_list, 'cart_amount' => $cart_amount, 'deliver_place' => Session::get('deliver_place'), 'deliver_time' => array('08:00', '09:00', '10:12', '12:30'), 'pay_method' => array('0' => array('is_default' => 0, 'method_name' => '在线支付'))), 'pay_status' => '付款信息');
     //var_dump($output);
     return View::make("template.order.order")->with($output);
 }
예제 #3
0
파일: test.php 프로젝트: binshen/website
 public function info()
 {
     //phpinfo();
     $redis = new Redis();
     $redis->connect(REDIS_HOST, REDIS_PORT);
     $redis->auth(REDIS_AUTH);
     $chat_data = $redis->lrange("chat:orFu-vgK-snskoQdDgMkBe-jFe1k:2", 0, -1);
     var_dump($chat_data);
 }
예제 #4
0
 public function testRawCommand()
 {
     $this->redis->set('mykey', 'some-value');
     $str_result = $this->redis->rawCommand('get', 'mykey');
     $this->assertEquals($str_result, 'some-value');
     $this->redis->del('mylist');
     $this->redis->rpush('mylist', 'A', 'B', 'C', 'D');
     $this->assertEquals($this->redis->lrange('mylist', 0, -1), array('A', 'B', 'C', 'D'));
 }
예제 #5
0
파일: api.php 프로젝트: binshen/website
 public function update_weixin_user($openid, $broker_id)
 {
     $this->api_model->update_weixin_user($openid);
     $redis = new Redis();
     $redis->connect(REDIS_HOST, REDIS_PORT);
     $redis->auth(REDIS_AUTH);
     $key = "map:" . $broker_id;
     $users = $redis->lrange($key, 0, -1);
     if (!in_array($openid, $users)) {
         $redis->lpush($key, $openid);
     }
 }
예제 #6
0
 /**
  * 获取首页图表数据
  */
 public function getChart()
 {
     $shop_id = Auth::user()->shop_id;
     $output = array('success' => 'true', 'state' => 200, 'errMsg' => '', 'no' => 0, 'data' => array());
     $monStr = array('一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月');
     $output['data']['month'] = array_slice($monStr, date('m', strtotime('now')) - 6, 6);
     $output['data']['goods'] = array();
     $menus = Shop::find($shop_id)->menus;
     foreach ($menus as $menu) {
         $key = 'laravel:menu:' . $menu->id . ':sold:month';
         array_push($output['data']['goods'], array('goods_id' => $menu->id, 'goods_name' => $menu->title, 'goods_sails' => Redis::lrange($key, 0, 5)));
     }
     return Response::json($output);
 }
예제 #7
0
 public function testRename()
 {
     // strings
     $this->redis->delete('key0');
     $this->redis->set('key0', 'val0');
     $this->redis->renameKey('key0', 'key1');
     $this->assertTrue($this->redis->get('key0') === FALSE);
     $this->assertTrue($this->redis->get('key1') === 'val0');
     // lists
     $this->redis->delete('key0');
     $this->redis->lPush('key0', 'val0');
     $this->redis->lPush('key0', 'val1');
     $this->redis->renameKey('key0', 'key1');
     $this->assertTrue($this->redis->lGetRange('key0', 0, -1) === array());
     $this->assertTrue($this->redis->lGetRange('key1', 0, -1) === array('val1', 'val0'));
     // variadic
     $this->redis->delete('key0');
     $this->assertTrue(3 === $this->redis->lPush('key0', 'val0', 'val1', 'val2'));
     $this->assertTrue(array('val2', 'val1', 'val0') === $this->redis->lrange('key0', 0, -1));
     $this->redis->delete('key0');
     $this->assertTrue(3 === $this->redis->rPush('key0', 'val0', 'val1', 'val2'));
     $this->assertTrue(array('val0', 'val1', 'val2') === $this->redis->lrange('key0', 0, -1));
 }
예제 #8
0
 public function range($start, $length = null)
 {
     $end = is_null($length) ? -1 : $start + $length;
     return $this->redis->lrange($this->key, $start, $end);
 }
예제 #9
0
 public function getUserBarCart()
 {
     if (Auth::check()) {
         $cartkey = Auth::user()->front_uid;
     } else {
         $cartkey = $this->getIP();
     }
     $key = 'laravel:user:'******':cart';
     if ($shop_id = Redis::lindex($key, 0)) {
         $data['successs'] = 'true';
         $data['state'] = 200;
         $data['errMsg'] = '';
         $data['no'] = 0;
         $shop = Shop::find($shop_id);
         $data['data']['url'] = 'shop/' . $shop_id;
         $data['data']['shop_name'] = $shop->name;
         $data['data']['all_value'] = 0;
         $data['data']['state'] = $shop->state == 0 ? 0 : 1;
         if ($shop->state == 1) {
             $data['data']['state_msg'] = '店铺打烊了';
         } elseif ($shop->state == 2) {
             $data['data']['state_msg'] = '店铺太忙了';
         } else {
             $data['data']['state_msg'] = '';
         }
         $ids = array_count_values(Redis::lrange($key, 1, -1));
         $data['data']['goods'] = array();
         foreach ($ids as $id => $count) {
             $menu = Menu::find($id);
             $value = $menu->price * $count;
             $data['data']['all_value'] += $value;
             array_push($data['data']['goods'], array('good_name' => $menu->title, 'good_value' => $value, 'good_count' => $count));
         }
         return Response::json($data);
     } else {
         return array('success' => 'false', 'state' => 200, 'errMsg' => '', 'no' => 0, 'data' => array());
     }
 }
예제 #10
0
파일: b_house.php 프로젝트: binshen/website
 public function choose_broker($id, $o_bid)
 {
     $wx_user = $this->house_model->choose_broker($id);
     if (!empty($wx_user)) {
         $open_id = $wx_user['open_id'];
         $broker_id = $wx_user['broker_id'];
         $this->api_model->update_weixin_user($open_id);
         $this->session->set_userdata('rel_name', $wx_user['rel_name']);
         $this->session->set_userdata('wx_broker_id', $broker_id);
         if ($broker_id != $o_bid) {
             $redis = new Redis();
             $redis->connect(REDIS_HOST, REDIS_PORT);
             $redis->auth(REDIS_AUTH);
             if (!empty($o_bid)) {
                 $o_key = "map:" . $o_bid;
                 $redis->lrem($o_key, $open_id, 0);
             }
             $key = "map:" . $broker_id;
             $users = $redis->lrange($key, 0, -1);
             if (!in_array($open_id, $users)) {
                 $redis->lpush($key, $open_id);
             }
         }
     }
     $this->view_list(1);
 }
function getRedis($key)
{
    $redis = new Redis();
    $redis->connect(HOST_REDIS, 6379);
    return $redis->lrange($key, 0, 4);
}
예제 #12
0
<?php

header("Content-type:text/html;charset=utf-8");
$username = $_POST['username'];
$phone = $_POST['phone'];
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$begin_time = time();
for ($i = 0; $i < 5000; $i++) {
    $redis->set('username' . $i, $username);
    $redis->set('phone' . $i, $phone);
    $redis->lpush("tutorial-list", "Redis" . $i);
}
$arList = $redis->lrange("tutorial-list", 0, 1000);
echo "Stored string in redis:: ";
print_r($arList);
$end_time = time();
echo $end_time - $begin_time;
예제 #13
0
<?php

$redis = new Redis();
$redis->connect('192.168.0.34', 6379);
//$redis->set('goods_count',10);
echo $redis->get('goods_count');
//$redis->delete('userlist');
//
$userList = array();
$userArr = $redis->lrange('userlist', 0, -1);
foreach ($userArr as $key => $user) {
    $userList[$key] = json_decode($user, true);
}
var_dump($userList);