Found related solution. Please go through this link.
Using of Keys is not advised and also if you go through the documentation you can see that. Though here is the performance is given but it's for the sake of understanding more deep knowledge, nothing else. The best way is to use Lua Script which is advisable and also the performance is really good. And if you see the comments you will also get to know about the difference as well, I guess.
The performance for the KEY, SCAN , Lua Script :
- KEYS: the fastest method
- SCAN: ~1.5 times slower
- SCAN with lua:~2.4 times slower
- SCAN with lua and additional checks: ~4.3 times slower
- KEYS with lua: ~18 times slower
For me, it was quite difficult to understand the syntax of Lua. So, here is the code to help understanding the syntax.
Scan without count in Lua Script:
local ans, has, cursor = {}, {}, "0";
repeat
local t = redis.call("SCAN", cursor, "MATCH", KEYS[1], "COUNT", 1000000000);
local list = t[2];
for i = 1, #list do
local s = list[i];
if has[s] == nil then has[s] = 1; ans[#ans + 1] = s; end;
end;
cursor = t[1];
until cursor == "0";
return #ans; --or return ans;