WRONGTYPE 针对持有错误类型值 php 的键的操作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37953019/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:26:28  来源:igfitidea点击:

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

phpredis

提问by Trushar Narodia

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"

嗨,我正在将 Laravel 与 Redis 一起使用。当我尝试通过 get 方法访问密钥时,出现以下错误“针对持有错误类型值的密钥的错误类型操作”

I am using following code to access the key value -

我正在使用以下代码访问键值 -

i use this code for get data from redis

我使用此代码从 redis 获取数据

$values = "l_messages";
$value = $redis->HGETALL($values);
print($value);

回答by Phoebe Li

Redis supports 5 data types. You need to know what type of value that a key maps to, as for each data type, the command to retrieve it is different.

Redis 支持 5 种数据类型。您需要知道一个键映射到什么类型的值,对于每种数据类型,检索它的命令是不同的。

Here are the commands to retrieve key value:

以下是检索键值的命令:

  • if value is of type string -> GET <key>
  • if value is of type hash -> HGETALL <key>
  • if value is of type lists -> lrange <key> <start> <end>
  • if value is of type sets -> smembers <key>
  • if value is of type sorted sets -> ZRANGEBYSCORE <key> <min> <max>
  • 如果值是字符串类型 -> GET <key>
  • 如果值的类型为 hash -> HGETALL <key>
  • 如果值是列表类型 -> lrange <key> <start> <end>
  • 如果值是类型集 -> smembers <key>
  • 如果值是排序集类型 -> ZRANGEBYSCORE <key> <min> <max>

Use the TYPEcommand to check the type of value a key is mapping to:

使用该TYPE命令检查键映射到的值的类型:

  • type <key>
  • 类型 <key>

回答by advance512

This error means that the value indexed by the key "l_messages" is not of type hash, but rather something else. You've probably set it to that other value earlier in your code. Try various other value-getter commands, starting with GET, to see which one works and you'll know what type is actually here.

此错误意味着由键 "l_messages" 索引的值不是 type hash,而是其他类型。您可能已经在代码的早期将其设置为其他值。尝试各种其他的取值命令,从 GET 开始,看看哪一个有效,你就会知道这里实际上是什么类型。