-
Mingyi Kang authored
In unwatchAllKeys() function, we traverse all the keys watched by the client, and for each key we need to remove the client from the list of clients watching that key. This is implemented by listSearchKey which traverses the list of clients. If we can reach the node of the list of clients from watchedKey in O(1) time, then we do not need to call listSearchKey anymore. Changes in this PR: put the node of the list of clients of each watched key in the db inside the watchedKey structure. In this way, for every key watched by the client, we can get the watchedKey structure and then reach the node in the list of clients in db->watched_keys to remove it from that list. From the perspective of the list of clients watching the key, the list node is inside a watchedKey structure, so we can get to the watchedKey struct from the listnode by struct member offset math. And because of this, node->value is not used, we can point node->value to the list itself, so that we don't need to fetch the list of clients from the dict.
3b462ce5