PHPackages                             phalapi/redis - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. phalapi/redis

ActiveLibrary[Caching](/categories/caching)

phalapi/redis
=============

PhalApi 2.x 扩展类库 - Redis 丰富基础redisCache类功能,更贴切复杂场景下的redis使用。

2.0.0(8y ago)122.6k5[3 issues](https://github.com/wenzhenxi/phalapi2-redis/issues)[1 PRs](https://github.com/wenzhenxi/phalapi2-redis/pulls)GPL-3.0-or-laterPHPPHP &gt;=5.3.3

Since Jan 25Pushed 4y ago2 watchersCompare

[ Source](https://github.com/wenzhenxi/phalapi2-redis)[ Packagist](https://packagist.org/packages/phalapi/redis)[ Docs](https://www.phalapi.net/)[ RSS](/packages/phalapi-redis/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

基于PhalApi2的Redis拓展
==================

[](#基于phalapi2的redis拓展)

[![](https://camo.githubusercontent.com/d17444d1c116ba8de47ca5f2d1550a5076c737e97beff214dca622d75b668533/687474703a2f2f776562746f6f6c732e71696e6975646e2e636f6d2f6d61737465722d4c4f474f2d32303135303431305f35302e6a7067)](https://camo.githubusercontent.com/d17444d1c116ba8de47ca5f2d1550a5076c737e97beff214dca622d75b668533/687474703a2f2f776562746f6f6c732e71696e6975646e2e636f6d2f6d61737465722d4c4f474f2d32303135303431305f35302e6a7067)

前言
--

[](#前言)

Redis在PHP开发中运用场景已经无处不在,小到简单缓存大到数据库或消息队列都可以使用Redis来进行实现,基于PhalApi2的出世,PhalApi2-Redis也紧接着进行了本次适配来提供更好的开发体验,PhalApi2-Redis提供相对于原生PhalApi2-RedisCache缓存更强大的Redis操作以及完善的封装机制,帮助开发者更好的使用Redis低成本的来解决实际的业务问题.

附上:

官网地址:[http://www.phalapi.net/](http://www.phalapi.net/ "PhalApi官网")

项目GitHub地址:[https://github.com/wenzhenxi/phalapi2-redis](https://github.com/wenzhenxi/phalapi2-redis "项目Git地址")

项目码云地址 : [https://gitee.com/wenzhenxi/phalapi2-redis](https://gitee.com/wenzhenxi/phalapi2-redis "项目码云地址")

安装配置Redis
---------

[](#安装配置redis)

基于Liunx强烈推荐使用oneinstack在配置php 和 Redis同事会将依赖打包好:

**oneinstack**:[https://oneinstack.com/](https://oneinstack.com/ "oneinstack")

手动安装redis网上有很多教程这里不再提及,主要注意一下配置文件:

```
databases 100                      #redis库的最大数量默认16推荐修改100
requirepass phalapi                #连接此redis的连接密码默认无密码推荐设置

```

手动安装php-redis依赖如下:

```
//下载phpredis解压安装
wget https://github.com/nicolasff/phpredis/archive/master.zip
unzip master.zip -d phpredis
cd phpredis/phpredis-master
phpize
./configure
make && make install
//在php.ini中注册phpredis
extension = redis.so

```

此后可以在phpinfo()中看到redis即可

安装PhalApi2-Redis
----------------

[](#安装phalapi2-redis)

在项目的composer.json文件中，添加：

```
{
    "require": {
        "phalapi/redis": "2.0.*"
    }
}

```

配置好后，执行composer update更新操作即可。

配置文件
----

[](#配置文件)

我们需要在 **./config/app.php** 配置文件中追加以下配置：

```
    /**
     * 扩展类库 - Redis扩展
     */
    'redis' => array(
        //Redis链接配置项
        'servers'  => array(
            'host'   => '127.0.0.1',        //Redis服务器地址
            'port'   => '6379',             //Redis端口号
            'prefix' => 'PhalApi_',         //Redis-key前缀
            'auth'   => 'phalapi',          //Redis链接密码
        ),
        // Redis分库对应关系操作时直接使用名称无需使用数字来切换Redis库
        'DB'       => array(
            'developers' => 1,
            'user'       => 2,
            'code'       => 3,
        ),
        //使用阻塞式读取队列时的等待时间单位/秒
        'blocking' => 5,
    ),

```

入门使用
----

[](#入门使用)

初始化PhalApi2-Redis,入口文件index.php加入如下代码

```

// 惰性加载Redis
\PhalApi\DI()->redis = function () {
    return new \PhalApi\Redis\Lite(\PhalApi\DI()->config->get("app.redis.servers"));
}c

```

常用基础操作(具体API可以查阅代码中src/Lite.php)

```
// 存入永久的键值队
\PhalApi\DI()->redis->set_forever(键名,值,库名);
// 获取永久的键值队
\PhalApi\DI()->redis->get_forever(键名, 库名);

// 存入一个有时效性的键值队,默认600秒
\PhalApi\DI()->redis->set_Time(键名,值,有效时间,库名);
// 获取一个有时效性的键值队
\PhalApi\DI()->redis->get_Time(键名, 库名);

// 写入队列左边
\PhalApi\DI()->redis->set_Lpush(队列键名,值, 库名);
// 读取队列右边
\PhalApi\DI()->redis->get_lpop(队列键名, 库名);
// 读取队列右边 如果没有读取到阻塞一定时间(阻塞时间或读取配置文件blocking的值)
\PhalApi\DI()->redis->get_Brpop(队列键名,值, 库名);

// 删除一个键值队适用于所有
\PhalApi\DI()->redis->del(键名, 库名);
// 自动增长
\PhalApi\DI()->redis->get_incr(键名, 库名);
// 切换DB并且获得操作实例
\PhalApi\DI()->redis->get_redis(键名, 库名);

```

**如果大家有更好的建议可以私聊或加入到PhalApi大家庭中前来一同维护PhalApi****注:笔者能力有限有说的不对的地方希望大家能够指出,也希望多多交流!**

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3078d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/35d70b1236f8f67d96ba3da4ba88889faf2837ff8f7ab62acc54fe6cb4992c87?d=identicon)[dogstarhuang](/maintainers/dogstarhuang)

---

Top Contributors

[![wenzhenxi](https://avatars.githubusercontent.com/u/12265719?v=4)](https://github.com/wenzhenxi "wenzhenxi (9 commits)")

---

Tags

redisphalapiphalapi-redis

### Embed Badge

![Health badge](/badges/phalapi-redis/health.svg)

```
[![Health](https://phpackages.com/badges/phalapi-redis/health.svg)](https://phpackages.com/packages/phalapi-redis)
```

###  Alternatives

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k318.6M2.7k](/packages/predis-predis)[snc/redis-bundle

A Redis bundle for Symfony

1.0k40.4M72](/packages/snc-redis-bundle)[clue/redis-protocol

A streaming Redis protocol (RESP) parser and serializer written in pure PHP.

5214.4M13](/packages/clue-redis-protocol)[cache/redis-adapter

A PSR-6 cache implementation using Redis (PhpRedis). This implementation supports tags

534.0M27](/packages/cache-redis-adapter)[rtcamp/nginx-helper

Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also provides cloudflare edge cache purging with Cache-Tags.

23617.0k1](/packages/rtcamp-nginx-helper)[contributte/redis

Redis client integration into Nette framework

181.7M2](/packages/contributte-redis)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
