DEV Community

Discussion on: Remaining Stateless - Using Redis for token blacklisting in Node JS

Collapse
 
gileri profile image
Eric G.

Sets are more suited for the case you describe (storing unique, unordered items) as they are faster for your case and avoid accidentally storing duplicates.

The complexity of looking up an item is O(1) with sets, while on average O(n/2) for lists.

Collapse
 
mr_cea profile image
Ogbonna Basil

Your Correct Eric , Sets have a bigO notation of O(1). However every token generated is always unique. Also the push method for a List is also an armotized O(1). But yes you can use sets