# redis **Repository Path**: homevip/redis ## Basic Information - **Project Name**: redis - **Description**: 自定义 Redis 类 - **Primary Language**: PHP - **License**: Not specified - **Default Branch**: develop - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-07-01 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### Redis.php ``` // 安装 yaconf 扩展 // 定义配置 $Redis = Redis::instance([ 'host' => config('database.redis.cache.host'), 'port' => config('database.redis.cache.port'), 'password' => config('database.redis.cache.password'), 'db' => config('database.redis.cache.database'), ]); // 默认配置 $Redis = Redis::instance(); // __call 方法使用 [当类中不存在该方法,直接调用call 实现调用底层redis相关的方法] var_dump($Redis->set('aaa', 600)); // 添加 var_dump($Redis->get('aaa')); // 获取 ``` ##### 使用 ``` use RedisLock; public function test(Request $request) { $key = 'key_' . uniqid(); $requestID = 'requestID_' . uniqid(); // 加锁 if ($this->lock($key, $requestID)) { // 代码逻辑 // 释放锁 $this->unlock($key, $requestID); } } ```