I have some keys in redis. I can do a MGET and fetch the values. But when the key is not present I get a (nil) from redis. But how to check that in java ? I am checking for null but it is not working.
127.0.0.1:6379> MGET key1 key2 key3 key4
1) "Hello"
2) "World"
3) "Hi"
4) "Hi-World"
127.0.0.1:6379> MGET key1 key2 key3 key5 key4
1) "Hello"
2) "World"
3) "Hi"
4) (nil)
5) "Hi-World"
127.0.0.1:6379>
In my java class actually I am mapping the key-list and value-list from MGET in a hash map. And on the value list I am doing some operations. There I need to put a null check. But simple java null
is not working.
2
Answers
If you have object as a map then you can access it like this
You can always call exists to check if a key exists in Redis. To check with java, first, create a client and call the appropriate method.