Using hashsets and sorted sets in redis to create a Trie
In this recipe, we will be using hedis to create simple trie in Redis. We will a use hashset to store an object, and store its searchable index in the sorted set in redis. We will be using the prefix trie to create a searchable index. For example, if we are searching for "APPLE", we will index all prefixes ("A","AP","APP","APPL", and "APPLE") in the index. Whenever a user enters a string to search, we will be able to look up our index and get the result.
Getting ready
Start the Redis server, and note down the connection info. In this recipe, we will assume that Redis is working on the same machine at the port 6379. This is what hedis assumes to connect to the Redis server using the default connection information.
How to do it...
- Create a new project called
hedis-trie
with asimple
stack template:
stack new hedis-trie simple
- Add a dependency on the hedis library in the
build-depends
sub-section of theexecutable
section:
executable...