RedisTemplate模糊查询scan报错:ERR value is not an integer or out of range

在项目中使用Redis的scan命令进行模糊查询时,本地测试正常,但在Tomcat环境中遇到错误,提示Redis值不是integer类型或超出范围。错误源于`count(Long.MAX_VALUE)`,将之改为`Integer.MAX_VALUE`后问题解决。
摘要由CSDN通过智能技术生成

项目中redis模糊查询使用了scan命令,在本地测试运行没有问题但部署到tomcat就会报错,错误显示redis值不是integer型或超出integer范围。代码和报错信息如下:

public List<Object> keys(String pattern) {
        List<Object> keys = new ArrayList<>();
        this.scan(pattern, item -> {
            //符合条件的key
            String key = new String(item, StandardCharsets.UTF_8);
            keys.add(key);
        });
        return keys;
  }

private void scan(String pattern, Consumer<byte[]> consumer) {
        this.redisTemplate.execute((RedisConnection connection) -> {
            try (Cursor<byte[]> cursor =
                         connection.scan(ScanOptions.scanOptions()
                                 .count(Long.MAX_VALUE)
                                 .match(pattern).build())) {
                cursor.forEachRemaining(consumer);
                return null;

            } catch (IOException e) {
                log.error("scan错误", e);
                throw new RuntimeException(e);
            }
        });
    }

io.lettuce.core.RedisCommandExecutionException: ERR value is not an integer or out of range
    at io.lettuce.core.internal.ExceptionFactory.createExecutionException(ExceptionFactory.java:137)
    at io.lettuce.core.internal.Exceptions.bubble(Exceptions.java:72)
    at io.lettuce.core.internal.Futures.awaitOrCancel(Futures.java:250)
    at io.lettuce.core.FutureSyncInvocationHandler.handleInvocation(FutureSyncInvocationHandler.java:75)
    at io.lettuce.core.internal.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:80)
    at com.sun.proxy.$Proxy148.scan(Unknown Source)
    at org.springframework.data.redis.connection.lettuce.LettuceKeyCommands$1.doScan(LettuceKeyCommands.java:266)
    at org.springframework.data.redis.connection.lettuce.LettuceScanCursor.scanAndProcessState(LettuceScanCursor.java:81)
    at org.springframework.data.redis.connection.lettuce.LettuceScanCursor.doScan(LettuceScanCursor.java:56)
    at org.springframework.data.redis.core.ScanCursor.scan(ScanCursor.java:88)
    at org.springframework.data.redis.core.ScanCursor.doOpen(ScanCursor.java:123)
    at org.springframework.data.redis.core.ScanCursor.open(ScanCursor.java:112)
    at org.springframework.data.redis.connection.lettuce.LettuceKeyCommands.doScan(LettuceKeyCommands.java:277)
    at org.springframework.data.redis.connection.lettuce.LettuceKeyCommands.scan(LettuceKeyCommands.java:245)
    at org.springframework.data.redis.connection.DefaultedRedisConnection.scan(DefaultedRedisConnection.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.data.redis.core.CloseSuppressingInvocationHandler.invoke(CloseSuppressingInvocationHandler.java:61)
    at com.sun.proxy.$Proxy568.scan(Unknown Source)

解决: 最终我是将connection.scan(ScanOptions.scanOptions().count(Long.MAX_VALUE).match(pattern).build()中的Long.MAX_VALUE改为了Integer.MAX_VALUE后方法就可以正常执行了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值