Home php教程 PHP源码 redis vs ssdb, hmset效率对比

redis vs ssdb, hmset效率对比

May 23, 2016 pm 04:40 PM

php代码

<?php
$test = new redis_test();
$test->totalSize = 100000;
$test->run();
 
class redis_test
{
    public $totalSize=1000000;
 
    function printf()
    {
      $args = func_get_args();
      if(count($args) == 1){
        $msg = $args[0].PHP_EOL;
      }else{
        $args[0] = $args[0].PHP_EOL;
        $msg = call_user_func_array("sprintf", $args);
      }
 
      echo $msg;
    }
 
    function run()
    {
        //测试redis->hmset()
        $this->printf("redis test start");
        $redis = new redis();
        $redis->connect(&#39;127.0.0.1&#39;, 6379);
        $this->test($redis);
 
        //测试ssdb->hmset()
        $this->printf("ssdb test start");
        $redis = new redis();
        $redis->connect(&#39;127.0.0.1&#39;, 8888);
        $this->test($redis);
    }
 
    function test($redis)
    {
        //导出一条测试记录
        $row = array (
          &#39;id&#39; => &#39;1&#39;,
          &#39;product&#39; => &#39;1&#39;,
          &#39;imei&#39; => &#39;000000000000000&#39;,
          &#39;model&#39; => &#39;Galaxy Note 3 - 4.4.2 - API 19 - 1080x1920&#39;,
          &#39;vcode&#39; => &#39;6&#39;,
          &#39;vcoded&#39; => &#39;11&#39;,
          &#39;channel&#39; => &#39;10001&#39;,
          &#39;download&#39; => &#39;0&#39;,
          &#39;ctime&#39; => &#39;1395992425&#39;,
          &#39;year&#39; => &#39;2014&#39;,
          &#39;month&#39; => &#39;201403&#39;,
          &#39;week&#39; => &#39;201413&#39;,
          &#39;day&#39; => &#39;20140328&#39;,
          &#39;day1&#39; => &#39;1&#39;,
          &#39;day2&#39; => &#39;1&#39;,
          &#39;day3&#39; => &#39;1&#39;,
          &#39;day4&#39; => &#39;1&#39;,
          &#39;day5&#39; => &#39;1&#39;,
          &#39;day6&#39; => &#39;1&#39;,
          &#39;day7&#39; => &#39;1&#39;,
          &#39;day14&#39; => &#39;1&#39;,
          &#39;day30&#39; => &#39;0&#39;,
          &#39;day60&#39; => &#39;0&#39;,
          &#39;vcode_1&#39; => &#39;0&#39;,
          &#39;vcode_2&#39; => &#39;0&#39;,
          &#39;vcode_3&#39; => &#39;0&#39;,
          &#39;vcode_6&#39; => &#39;20140710&#39;,
          &#39;vcode_7&#39; => &#39;20140331&#39;,
          &#39;vcode_8&#39; => &#39;0&#39;,
          &#39;vcode_9&#39; => &#39;20140414&#39;,
          &#39;vcode_10&#39; => &#39;0&#39;,
          &#39;vcode_11&#39; => &#39;20140710&#39;,
          &#39;vcode_12&#39; => &#39;0&#39;,
          &#39;vcode_13&#39; => &#39;0&#39;,
          &#39;vcode_14&#39; => &#39;0&#39;,
          &#39;vcode_15&#39; => &#39;0&#39;,
          &#39;vcode_16&#39; => &#39;0&#39;,
          &#39;vcode_17&#39; => &#39;0&#39;,
          &#39;vcode_18&#39; => &#39;0&#39;,
          &#39;vcode_19&#39; => &#39;0&#39;,
          &#39;last_act_year&#39; => &#39;2014&#39;,
          &#39;last_act_month&#39; => &#39;201407&#39;,
          &#39;last_act_week&#39; => &#39;201428&#39;,
          &#39;last_act_day&#39; => &#39;20140710&#39;,
          &#39;offday&#39; => &#39;77&#39;,
          &#39;lose&#39; => &#39;1&#39;,
        );
 
        $this->printf("Job start, %s, %s", $this->memory_get_usage(), date("Y-m-d H:i:s"));
        for($i=1; $i<=$this->totalSize; $i++)
        {
            $row["id"]    = $i;
            $row["imei"]  = md5(rand(). microtime(true));
            $row["model"] = rand();
 
            $redis->hmset($row["imei"], $row);
 
            if($i % 10000 === 0)
                $this->printf("Job %s done, %s, %s", $i, $this->memory_get_usage(), date("Y-m-d H:i:s"));
        }
 
        $this->printf("Job start, %s, %s", $this->memory_get_usage(), date("Y-m-d H:i:s"));
    }
 
    function memory_get_usage()
    {
        $size = memory_get_usage(true);
        $unit=array(&#39;b &#39;,&#39;kb&#39;,&#39;mb&#39;,&#39;gb&#39;,&#39;tb&#39;,&#39;pb&#39;);
        return sprintf("%02f", @round($size/pow(1024,($i=floor(log($size,1024)))), 2)).&#39; &#39;.$unit[$i];
    }
}
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)