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 1y 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 1mo 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

15

—

LowBetter than 3% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity18

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://www.gravatar.com/avatar/f276791e5734a8cbcfde51477f2cc733f81c1fd95c55e150efa75bec3493f2b5?d=identicon)[J-guanghua](/maintainers/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

[predis/predis

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

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

A Redis bundle for Symfony

1.0k39.4M67](/packages/snc-redis-bundle)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)

PHPackages © 2026

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