I would maybe do it something like this...
When a call is made, store the extension number in redis with an expiring key for the length you need, eg last hour, day week etc.
Then when new call comes in, look into redis for that callerid and find the extension that matched it, then route to...