redis

Redis 实现限流

下面介绍两种方法 zset function uuid(){ $str = "123456790abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; $uuid = ""; for ($i = 0; $i < 10; $i++) { $uuid .= $str[mt_rand(0, strlen($str) - 1)]; } return $uuid; } $time = time(); $key='limit:100'; $val = uuid(); $redis = n...

Redis GEO地理位置

Redis GEO 主要用于存储地理位置信息,并对存储的信息进行操作,该功能在 Redis 3.2 版本新增。 基于此可以实现附近的人,附近的店铺等功能 $redis = new Redis(); $redis->connect("docker-redis", 6379); //$r=$redis->geoadd('citys', 114.09981,33.585519, 'taiwei'); //$r=$redis->geoadd('citys', 114.070524,33.59067, 'dongwaitan'); //$r=$redis->geoadd('ci...

Redis 中的订阅消息转发到 WebSocket 客户端

WebSocketTest.php <?php class WebSocketTest { public \Swoole\WebSocket\Server $server; public function __construct() { $this->server = new Swoole\WebSocket\Server("0.0.0.0", 9502); $this->server->on('open', function (Swoole\WebSocket\Server $server, $request) { ...

docker搭建Redis集群-主从复制

一主二从 代码目录 │ docker-compose.yml ├─apache │ Dockerfile │ index.php ├─follower │ Dockerfile │ run.sh └─leader Dockerfile docker-compose.yml # docker-compose.yml # tell docker what version of the docker-compose.yml we're using version: '3' # define the network networks: web-network: # s...

php扩展的编译安装

这里以redis为例 工具 yum install autoconf 下载及编译 wget https://pecl.php.net/get/redis-5.3.4.tgz --no-check-certificate tar -xvzf redis-5.3.4.tgz cd redis-5.3.4 phpize ./configure --with-php-config=/usr/bin/php-config make && make install 添加到php.ini vi php.ini 959 extension=redis 重载php-fpm,使生效 s...