WRONGTYPE Operation against a key holding the wrong kind of value php

前端 未结 3 472
时光说笑
时光说笑 2020-12-22 16:01

Hi I am using Laravel with Redis .When I am trying to access a key by get method then get following error \"WRONGTYPE Operation against a key holding the wrong kind of value

3条回答
  •  情话喂你
    2020-12-22 16:23

    I faced this issue when trying to set something to redis. The problem was that I previously used "set" method to set data with a certain key, like

    $redis->set('persons', $persons)
    

    Later I decided to change to "hSet" method, and I tried it this way

    foreach($persons as $person){
        $redis->hSet('persons', $person->id, $person);
    }
    

    Then I got the aforementioned error. So, what I had to do is to go to redis-cli and manually delete "persons" entry with

    del persons
    

    It simply couldn't write different data structure under existing key, so I had to delete the entry and hSet then.

提交回复
热议问题