implement error handling and thredis_close