zoukankan      html  css  js  c++  java
  • redis 缓存 MySQL 数据库

    <?php
    $redis = new Redis();
    $redis->connect('127.0.0.1',6379) or die ("could net connect redis server");
    # $query = "select * from test limit 9";
    $query = "select * from test";
    for ($key = 1; $key < 10; $key++)
    {
    if (!$redis->get($key))
    {
    $connect = mysql_connect('127.0.0.1','redis','westos');
    mysql_select_db(test);
    $result = mysql_query($query);
    //如果没有找到$key,就将该查询sql的结果缓存到redis
    while ($row = mysql_fetch_assoc($result))
    {
    $redis->set($row['id'],$row['name']);
    }
    $myserver = 'mysql';
    break;
    }
    else
    {
    $myserver = "redis";
    $data[$key] = $redis->get($key);
    }
    }

    echo $myserver;
    echo "<br>";
    for ($key = 1; $key < 10; $key++)
    {
    echo "number is <b><font color=#FF0000>$key</font></b>";

    echo "<br>";

    echo "name is <b><font color=#FF0000>$data[$key]</font></b>";

    echo "<br>";
    }
    ?>


    转载原文链接:https://blog.csdn.net/lilygg/article/details/88068648

  • 相关阅读:
    android 设置时间和日期
    android 对话框
    android notification 通知
    android 动画(转载)
    js的作用域题
    js高级
    js中级6
    js中级小知识5
    js中级小知识4
    js中级小知识3
  • 原文地址:https://www.cnblogs.com/summerGraden/p/13271834.html
Copyright © 2011-2022 走看看