I want to do a fuzzy search in Redis
I have lots of Domain-IP info to maintain, and I want to use a hash to hold them
The structure of Domain-IP is sth like this:
Domain-IP
domain
ip
last-access (last time I use this ip to access the domain)
access-count
...
Now I want to do two things:
search this Domain-IP info by domain, sth like: select * from domain-ip where domain = "www.google.com"
update Domain-IP info by domain and IP, sth like: update domain-ip set access-count = access-count + 1 where domain = "www.google.com" and ip = "192.168.1.1"
so my design the structure in Redis is:
HSET domainip.www.google.com.192.168.1.1 access-count 20
HSET domainip.www.google.com.192.168.1.2 access-count 20
so I can serach them by domain like this, for example, search info about www.google.com:
- get all keys starts with www.google.com by : keys domainip.www.google.com*
- use these keys to get all the info about google in a loop:
for (string key : keys) { execute("HGETALL " + key) // then convert the hash into a POJO }
and the update operation as follow:
"HSET domainip." + domainStr + "." + ipStr + " access-count " + newAccessCount;
"HSET domainip." + domainStr + "." + ipStr + " last-access " + newLastAccess;
My question is :
Does the loop causes performance issue?
Is that right to update the hash filed one by one?
It will be nice if you can provide a good idea to complete the operation what I want in Redis, Thx :D