这个报错是因为什么呢?setValue传入字符串value正常,传入对象就报错。
来源:4-3 Redis实战应用配置—哈希表hset&hgetall
慕侠3297407
2022-10-31 05:37:01
PS C:\Users\18660\Desktop\929\8-4> npx babel-node src/config/test.js
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
ReplyError: WRONGTYPE Operation against a key holding the wrong kind of value
ReplyError: WRONGTYPE Operation against a key holding the wrong kind of value
ReplyError: WRONGTYPE Operation against a key holding the wrong kind of value
getValueimooc message from redis client
C:\Users\18660\Desktop\929\8-4\node_modules\redis-parser\lib\parser.js:193
return new ReplyError(string)
^
ReplyError: WRONGTYPE Operation against a key holding the wrong kind of value
at parseError (C:\Users\18660\Desktop\929\8-4\node_modules\redis-parser\lib\parser.js:193:12)
at parseType (C:\Users\18660\Desktop\929\8-4\node_modules\redis-parser\lib\parser.js:303:14) {
command: 'HGETALL',
args: [ 'imoocobj' ],
code: 'WRONGTYPE'
}
PS C:\Users\18660\Desktop\929\8-4>const path=require('path')
const utils=require('./utils')
const webpack=require('webpack')
const nodeExternals=require('webpack-node-externals')
const {CleanWebpackPlugin}=require('clean-webpack-plugin')
const webpackconfig={
target:'node',
entry:{
server:path.join(utils.APP_PATH,'index.js')
},
output:{
filename:"[name].bundle.js",
path:utils.DIST_PATH
},
module:{
rules:[{
test:/\.(js|jxs)$/,
use:{
loader:'babel-loader'
},
exclude:[path.join(__dirname,'/node_modules')]
}
]
},
externals:[nodeExternals()],
plugins:[
new CleanWebpackPlugin(),
new webpack.DefinePlugin({
'process.env':{
NODE_ENV:(process.env.NODE_ENV==='production'||process.env.NODE_ENV==='prod')?'production':'development'
}
})
],
node:{
console:true,
global:true,
process:true,
Buffer:true,
__filename:true,
__dirname:true,
setImmediate:true,
path:true
}
}
module.exports=webpackconfigimport { getHValue, getValue,setValue } from "./RedisConfig";
setValue('imooc','imooc message from redis client')
getValue('imooc').then((res)=>{
console.log('getValue'+res)
})
setValue('imoocobj',{name:'brian',age:30,email:'brian@tomic.com'})
getHValue('imoocobj').then((res)=>{
console.log('getHValue'+res)
})2回答
慕雪晨
2023-08-08
我也出现过这个问题,对了一下代码,和老师的是一样的,redis版本也是一样的,也是报的这个错误

经过研究发现,因为上一节学习操作,已经创建了一个imooc的字符串,再次执行就又创建了一个一模一样的数据了,就报错了。我把之前创建的imooc删除了,重新再执行一遍就成功了。对象的如果报错,也可以先删除一下 再操作,以防重复然后报错

Brian
2022-10-31
相似问题