Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

Using the Redis script in SpringBoot, an error is reported: attempt to compare nil with number at

$
0
0

In SpringBoot, I use RedisTemplate to execute the Lua script to implement the interface current limiter. The script is as follows:

local key = KEYS[1]local count = tonumber(ARGV[1])local expiration = tonumber(ARGV[2])if redis.call('EXISTS', key) == 0 then    redis.call('SET', key, 1)    redis.call('EXPIRE', key, expiration)    return 1else    local current_count = tonumber(redis.call('GET', key))    if current_count == nil then        redis.log(redis.LOG_NOTICE, 'current_count is nil')        redis.log(redis.LOG_NOTICE, current_count)        return 10    end    if current_count >= count then        return current_count    else        redis.call('INCR', key)        return current_count + 1    endend

What I don't understand is that it was normal for him to deposit in Redis for the first time, but this error occurred in the second accumulation:attempt to compare nil with number at org.springframework.data.redis.connection.lettuce.lettuceexceptionconverter.convert

But the fetched value should not be a nil, and I also judged whether the current_count is nil or not. Obviously, the program did not enter this judgment, which means it is not nil

But when executing this section of code: if current_count >= count then ,I get an error that tells me that nil cannot be compared with type number? what's the situation? ? ? This surprised me.

Has anyone specified why, please explain, thank you.

no redundant operation.


Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>