bonsaicode/redis 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bonsaicode/redis

Composer 安装命令:

composer require bonsaicode/redis

包简介

Implementation of the Redis Redlock algorithm, which is used to ensure only one server carries out a process in an environment where multiple duplicate servers exist, e.g. GCP auto-scaling load balancer.

README 文档

README

Implementation of the Redis Redlock algorithm, which is used to ensure only one server carries out a process in an environment where multiple duplicate servers exist, e.g. GCP auto-scaling load balancer. Also provides a wrapper for some phpredis methods. All phpredis methods can be used through this wrapper. This wrapper creates and uses a redis object in $GLOBALS['REDIS'].

See https://github.com/phpredis/phpredis for more info

Dependencies:

You must have a redis service running.

Requirements

Installation

To install the module, run the following command in the console:

$ composer require "bonsaicode/redis"

Usage

# Create connection with configuration

$_config = [
    'redis' => [
        'host'    => '10.0.0.1', # redis server
        'port'    => 6379,
        'timeout' => 2,
        'auth'    => 'password', # needed if your redis requires it, also needs to be in /etc/redis.conf and /etc/php.d/50-redis.ini - session.save_path
        'dbindex' => 1 # optional, session handler uses database 0, so we use 1 for app data        
    ]
];
BonsaiCode\Redis::connectSelect( $_config['redis'] );
unset( $_config['redis'] ); # remove config and password from memory

# acquire lock

$lockKey = 'cron1';
list( $lockAcquired, $lockValue ) = BonsaiCode\Redis::lockAcquire( $lockKey );
if( $lockAcquired ) {

	... your processing here ...

        # release lock 
    
	BonsaiCode\Redis::lockRelease( $lockKey, $lockValue );
}

see test/Redis.php for more examples

统计信息

  • 总下载量: 20
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: mit
  • 更新时间: 2019-09-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固