memory_store: avoid nil array access by checking key exists. Returns nil if no key is found.