search

Home  >  Q&A  >  body text

redis-php set失败

$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
echo "Server is running: " . $redis->ping();

运行后输出:Server is running: +PONG

这说明运行成功了吗?

如果成功了

$redis->set("tutorial-name", "Redis tutorial");

我set个key一直返回false

查了资料没找到原因,log文件也没发现

漂亮男人漂亮男人2797 days ago745

reply all(6)I'll reply

  • 世界只因有你

    世界只因有你2017-04-25 09:04:59

    Why does the

    key have - in the middle? You should make the key simpler, such as a

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-04-25 09:04:59

    Can you write the command directly to see if the key can be put in?

    reply
    0
  • ringa_lee

    ringa_lee2017-04-25 09:04:59

    It seems useless. redis->select($db);Select the database.

    reply
    0
  • 世界只因有你

    世界只因有你2017-04-25 09:04:59

    I also encountered that set returned false, and there was no specific prompt information when testing in the code. Then I went to the Linux server to test whether redis was valid. The test results showed that there was indeed a problem with set, and it prompted (error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error. Then go to Baidu or Google and run config set stop- according to the online method writes-on-bgsave-error no or modify sysctl vm.overcommit_memory=1 (you can try both) and it will be ok

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-04-25 09:04:59

    pong means the link is successful. If it cannot be set, please check the log

    reply
    0
  • 世界只因有你

    世界只因有你2017-04-25 09:04:59

    I also encountered this when I was learning redis. As long as I run some error statements in the front, it will not work anymore, such as $redis->set('iliked',1);$redis->decr('iliked' ,2);//After executing this sentence, refresh the page frequently, and then write $redis->delete('iliked'); or the set operation mentioned above will not work. At this time, redis needs to be restarted. That's it. Very depressing! ! !

    reply
    0
  • Cancelreply