php-redis - Is there a way to store PHP object in Redis without serializing it?

前端 未结 4 827
我寻月下人不归
我寻月下人不归 2021-02-14 17:10

I am trying to store user\' request URL as the key and a PHP object corresponding to that key as the value in Redis. I tried the following:

$redisClient = new Re         


        
4条回答
  •  囚心锁ツ
    2021-02-14 17:56

    An addition to Aliweb's answer!

    Redis supports integers as well as actions like INCR, INCRBY, DECR and DECRBY.

    As for the question:

    Serialize only if is not a String or Int. Serialization is a costly operation!

    on GET and HGET try to see what if it is serialized:

    '

    private function string_unserialize($str){
            $data = @unserialize($str);
            if ($str === 'b:0;'){
                return 0;
            }elseif($data !== false){
                return $data;
            }else {
                return $str;
            }
        }
    

    '

提交回复
热议问题