PHPackages                             guanghua/socket-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. guanghua/socket-redis

ActiveYii2-extension[Caching](/categories/caching)

guanghua/socket-redis
=====================

socket redis连接,用于redis命令,缓存

24PHP

Since May 18Pushed 2y ago1 watchersCompare

[ Source](https://github.com/J-guanghua/socket-redis)[ Packagist](https://packagist.org/packages/guanghua/socket-redis)[ RSS](/packages/guanghua-socket-redis/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Installation
------------

[](#installation)

安装此扩展的首选方法是通过 [composer](http://getcomposer.org/download/).

要么跑

```
php composer.phar require guanghua/socket-redis "dev-master"

```

或添加

```
"guanghua/socket-redis": "dev-master"

```

到你的需求部分 `composer.json` 文件.

Usage
-----

[](#usage)

一旦安装了扩展，只需使用它在您的代码:

```
一，redis 使用操作

use guanghua\redis\RedisConn;

$redis = RedisConn([
   'hostname' => '127.0.0.1', //连接主机
   'port'     => 6379, //连接端口
   'database' => 0 //连接数据库
])

// 设置指定 key 的值
$redis->SET('KEY_NAME', "VALUE");

// 获取指定 key 的值。
$redis->GET('KEY_NAME');

// 向有序集合添加一个或多个成员
$redis->ZADD('myset', 1, "hello");

$redis->ZADD('myset', 5, "hello2");

// 返回有序集中，成员的分数值
$value = $redis->ZRANGE('myset',0, -1,'WITHSCORES');

更多命令参考redis文档.............

二，redis cache 使用操作

use guanghua\redis\RedisCache;

$cache = RedisCache([
   'redis' => $redis,
])
// 缓存一个对象,或数组 200秒
$cache->set('obj',new \queue\KeyWordJob(['id'=>['dwdwfefe']]),200);

$cache->set('obj',[1,2,3,4,5],200);

// 获取缓存值
$value = $cache->get('obj');

//从缓存中删除所有值
$cache->flush();

三，redis session 使用操作

use guanghua\redis\RedisSession;

// session实例,可以解决分布式系统用户登录
$session = RedisSession([
   'redis' => $redis,
])

//设置 session 值
$session->set('username',[1,2,3,4,5]);

// 方式2 设置session变量
$_SESSION['username'] = 'JohnDoe';
$_SESSION['email'] = 'john@example.com';

//获取 session 值
$session->get('username');
```

###  Health Score

14

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/28997235?v=4)[华](/maintainers/J-guanghua)[@J-guanghua](https://github.com/J-guanghua)

---

Top Contributors

[![J-guanghua](https://avatars.githubusercontent.com/u/28997235?v=4)](https://github.com/J-guanghua "J-guanghua (27 commits)")

### Embed Badge

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

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

###  Alternatives

[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21114.2k](/packages/iazaran-smart-cache)[ichhabrecht/intcache

Turn uncachable page objects into cacheable links

193.9k](/packages/ichhabrecht-intcache)

PHPackages © 2026

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