As the business progresses, You Need To directly operate redis data!
You need to obtain the key with the specified prefix, just like operating mysql. You need to obtain the specified record segment!
Zf2 strongly supports redis cache, but when I used zf2 redis cache factory mode, I found that zf2 does not support redis keys!
// Thanks to the blog: http://my.oschina.net/cart/
The following describes how to expand zf2 redis:
\module\Application\src\Application\Service\RedisExtendService.php<?phpnamespace Application\Service;use Zend\Cache\Storage\Adapter\Redis;class RedisExtendService extends Redis{ public function __construct($options = null) { parent::__construct($options); } /** * support regular * * @param sting $keys */ public function getKeys($keys) { return $this->getRedisResource()->keys($keys); }}
OK. expansion is complete!
In indexaction, we directly use our extended zf2 redis. As long as you are willing to scale and don't want to be limited to zf2, you can use many original redis methods:
<?phpnamespace Application\Controller;use Zend\Mvc\Controller\AbstractActionController;use Zend\View\Model\ViewModel;class IndexController extends AbstractActionController{ private static $redis; private function redis(){ if(!self::$redis){$config = $this->getServiceLocator()->get(‘config‘); self::$redis = new \Application\Service\RedisExtendService($config[‘Redis‘]); } return self::$redis; } public function indexAction(){ var_dump($this->redis()->getKeys(‘Member_*‘));var_dump($this->redis()->getKeys(‘Item_*‘));var_dump($this->redis()->getKeys(‘Product_*‘)); }}
With this article, we can draw a lot from the opposite: a large number of inheritance extensions zf2!
And your expansion is efficient and portable!
Scale zf2 redis Zend framework 2 redis extend-key regular