Following is my lua script
if redis.call('sismember',KEYS[1],ARGV[1])==1
then redis.call('srem',KEYS[1],ARGV[1])
else return 0
end
store = tonumber(redis.call('hget',KEYS[2],'capacity'))
store = store + 1
redis.call('hset',KEYS[2],'capacity',store)
return 1
when I run this srcipt in Java, An exception like
@user_script:1: WRONGTYPE Operation against a key holding the wrong kind of value
throws, the Java code is like
Object ojb = jedis.evalsha(sha,2,userName.getBytes(),
id.getBytes(),id.getBytes()) ;
where userName is “tau” and id is “002” in my code,
and I test the type of “tau” and “002” as follows,
127.0.0.1:6379> type tau
set
127.0.0.1:6379> type 002
hash
and exactly, the content of them are :
127.0.0.1:6379> hgetall 002
name
"鏁版嵁搴撲粠鍒犲簱鍒拌窇璺?
teacher
"taochq"
capacity
54
127.0.0.1:6379> smembers tau
002
004
001
127.0.0.1:6379>
Now I’m so confused and don’t know what’s wrong, any help will be grateful
2
Answers
The error is quite verbose – you’re trying to perform an operation on key of the wrong type.
Run
MONITOR
alongside and then your script – then you’ll be able to spot the error easily.Try your script as:
You’ll see if it works. Most likely,
userName.getBytes()
andid.getBytes()
are not returning what you expect. UseMONITOR
as Itamar suggests to see what’s actually reaching the server.You’ll get a separate a different issue:
Script attempted to create global variable 'store'
. Addlocal
to the 5th line: