zoukankan      html  css  js  c++  java
  • hash 表 电商购物车缓存

       $id = $_GPC['id'];
            $product= pdo_fetch("select id,title,marketprice,total from ".tablename('ewei_shop_goods')." where id='$id'");
    
           //使用hashtable存储
            $redis= new Redis();
            $redis->connect('127.0.0.1',6379);
    
            if($p=$redis->hget('cart','productid_'.$id)){
                $p= json_decode($p,true);
                $p['num']++;
                $redis->hset('cart','productid_'.$id,json_encode($p));
            }else{
                $product['num'] =1;
                $redis->hset('cart','productid_'.$id,json_encode($product));
            }
    
            var_dump($redis->hGetAll('cart'));
    //session主流方式购物车的存储
      $id = $_GPC['id'];
            $product= pdo_fetch("select id,title,marketprice,total from ".tablename('ewei_shop_goods')." where id='$id'");
          session_start();
       //     var_dump($_SESSION['cart'][$id]);exit;
    
    
            if(!empty($_SESSION['cart']) && !empty($_SESSION['cart'][$id]))
            {
                echo 1122;
                $_SESSION['cart'][$id]['num']++;
    
            }else{
                $product['num'] = 1;
    
                $_SESSION['cart'][$id]= $product;
    
            }
    世界上最美的风景,是自己努力的模样
  • 相关阅读:
    「CH6801」棋盘覆盖
    「POJ3613」Cow Relays
    「Luogu4556」Vani有约会-雨天的尾巴
    The Proof of Fibonacci GCD
    Ubuntu flatabulous 主题
    CSP-S 2019 复赛游记
    「Luogu1402」酒店之王
    HDU/5499/模拟
    cfedu/A/求和
    HDU<1372>/bfs
  • 原文地址:https://www.cnblogs.com/xiong-hua/p/14107327.html
Copyright © 2011-2022 走看看