[Exception] JedisDataException: ERR wrong number of arguments for '***' command

本文详细解析了 Redis 中 zrem 命令错误的原因及解决方案,特别是当传入的参数数量不正确时,如何避免 JedisDataException 的异常抛出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

异常信息:

Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR wrong number of arguments for 'zrem' command
    at redis.clients.jedis.Protocol.processError(Protocol.java:66)
    at redis.clients.jedis.Protocol.process(Protocol.java:73)
    at redis.clients.jedis.Protocol.read(Protocol.java:138)
    at redis.clients.jedis.Connection.getIntegerReply(Connection.java:191)
    at redis.clients.jedis.Jedis.zrem(Jedis.java:1440)
    at com.gamejelly.gong.global.dbs.service.GlobalJedisService$26.doInJedis(GlobalJedisService.java:750)
    at com.hadoit.game.common.framework.nosql.redis.JedisTemplate.execute(JedisTemplate.java:79)
    at com.gamejelly.gong.global.dbs.service.GlobalJedisService.delRedisKeys(GlobalJedisService.java:746)
    at com.gamejelly.gong.global.dbs.proxy.GlobalCommandProxy.delRedisKeys(GlobalCommandProxy.java:642)
    at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.hadoit.game.engine.core.utils.method.MethodInvoationWrap.invoke(MethodInvoationWrap.java:63)

示例代码:

public void rem(String key,String[] delkeys){
    jedis.zrem(key, delKeys);
}

原因:

jedis.zrem(key, delKeys)数组参数delkeys长度为0,即抛出该异常
注:jedis还有很多方法都会抛出该异常,原因与此一致。jedis 不定长度参数方法都有这个问题

解决方案:

在代码中合适处检查数组参数长度
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值