Rewrite config.m4 and changes to memory handling

I am not sure why the config.m4 uses pkgconfig (it doesn't seem like hiredis installs pkgconfig files). However with these changes it builds on my mac and linux when using --with-hiredis-dir.

Other changes:
  - Persistent connections don't use emalloc anymore
  - Removed some duplicate code
  - Cast ZEND_FETCH_RESOURCE2 results to correct type

Tests seem to be ok with these changes.