dounieliang4712 2014-10-10 13:36
浏览 87

PHPRedis - time()不起作用

I have a problem.

In my project I have few servers which modify same data in redis. All the servers may have different time. In other words, I can't rely on app server time in some cases.

So I would like to use Redis time as general base point.

Everything could be fine, PHPRedis documentation says there is a function which does exactly what I need: time().

But here is a BIG surprise:

//... create connection etc...

Output is:


The question is - what the hell is this? Have you ever faced such a problem?

How can I get redis server time using it's functions?

Note: other redis functions work fine, I am able to read and write data. Connection is ok and is created correctly.

  • 写回答

1条回答 默认 最新

  • douaoj0994 2014-10-13 14:45

    Got no help here.

    As well as anywhere else.

    So I needed to invent a walkaround...

    Here is it, if someone needs it.

        // Generate unique temporary key
        $key = uniqid() . time();
        // Take some random future TS
        $future_ts = time() + 1000;
        $redis->setex($key, time(), 5);
        $redis->expireAt($key, $future_ts);
        // This variable now contains what I need
        $redis_ts = $future_ts - $redis->ttl($key);
    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序