# Predis #
[![Software license][ico-license]](LICENSE)
[![Latest stable][ico-version-stable]][link-releases]
[![Latest development][ico-version-dev]][link-releases]
[![Monthly installs][ico-downloads-monthly]][link-downloads]
[![Build status][ico-build]][link-actions]
[![Coverage Status][ico-coverage]][link-coverage]
A flexible and feature-complete [Redis](http://redis.io) client for PHP 7.2 and newer.
More details about this project can be found on the [frequently asked questions](FAQ.md).
## Main features ##
- Support for Redis from __3.0__ to __7.0__.
- Support for clustering using client-side sharding and pluggable keyspace distributors.
- Support for [redis-cluster](http://redis.io/topics/cluster-tutorial) (Redis >= 3.0).
- Support for master-slave replication setups and [redis-sentinel](http://redis.io/topics/sentinel).
- Transparent key prefixing of keys using a customizable prefix strategy.
- Command pipelining on both single nodes and clusters (client-side sharding only).
- Abstraction for Redis transactions (Redis >= 2.0) and CAS operations (Redis >= 2.2).
- Abstraction for Lua scripting (Redis >= 2.6) and automatic switching between `EVALSHA` or `EVAL`.
- Abstraction for `SCAN`, `SSCAN`, `ZSCAN` and `HSCAN` (Redis >= 2.8) based on PHP iterators.
- Connections are established lazily by the client upon the first command and can be persisted.
- Connections can be established via TCP/IP (also TLS/SSL-encrypted) or UNIX domain sockets.
- Support for custom connection classes for providing different network or protocol backends.
- Flexible system for defining custom commands and override the default ones.
## How to _install_ and use Predis ##
This library can be found on [Packagist](http://packagist.org/packages/predis/predis) for an easier
management of projects dependencies using [Composer](http://packagist.org/about-composer).
Compressed archives of each release are [available on GitHub](https://github.com/predis/predis/releases).
```shell
composer require predis/predis
```
### Loading the library ###
Predis relies on the autoloading features of PHP to load its files when needed and complies with the
[PSR-4 standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md).
Autoloading is handled automatically when dependencies are managed through Composer, but it is also
possible to leverage its own autoloader in projects or scripts lacking any autoload facility:
```php
// Prepend a base path if Predis is not available in your "include_path".
require 'Predis/Autoloader.php';
Predis\Autoloader::register();
```
### Connecting to Redis ###
When creating a client instance without passing any connection parameter, Predis assumes `127.0.0.1`
and `6379` as default host and port. The default timeout for the `connect()` operation is 5 seconds:
```php
$client = new Predis\Client();
$client->set('foo', 'bar');
$value = $client->get('foo');
```
Connection parameters can be supplied either in the form of URI strings or named arrays. The latter
is the preferred way to supply parameters, but URI strings can be useful when parameters are read
from non-structured or partially-structured sources:
```php
// Parameters passed using a named array:
$client = new Predis\Client([
'scheme' => 'tcp',
'host' => '10.0.0.1',
'port' => 6379,
]);
// Same set of parameters, passed using an URI string:
$client = new Predis\Client('tcp://10.0.0.1:6379');
```
Password protected servers can be accessed by adding `password` to the parameters set. When ACLs are
enabled on Redis >= 6.0, both `username` and `password` are required for user authentication.
It is also possible to connect to local instances of Redis using UNIX domain sockets, in this case
the parameters must use the `unix` scheme and specify a path for the socket file:
```php
$client = new Predis\Client(['scheme' => 'unix', 'path' => '/path/to/redis.sock']);
$client = new Predis\Client('unix:/path/to/redis.sock');
```
The client can leverage TLS/SSL encryption to connect to secured remote Redis instances without the
need to configure an SSL proxy like stunnel. This can be useful when connecting to nodes running on
various cloud hosting providers. Encryption can be enabled with using the `tls` scheme and an array
of suitable [options](http://php.net/manual/context.ssl.php) passed via the `ssl` parameter:
```php
// Named array of connection parameters:
$client = new Predis\Client([
'scheme' => 'tls',
'ssl' => ['cafile' => 'private.pem', 'verify_peer' => true],
]);
// Same set of parameters, but using an URI string:
$client = new Predis\Client('tls://127.0.0.1?ssl[cafile]=private.pem&ssl[verify_peer]=1');
```
The connection schemes [`redis`](http://www.iana.org/assignments/uri-schemes/prov/redis) (alias of
`tcp`) and [`rediss`](http://www.iana.org/assignments/uri-schemes/prov/rediss) (alias of `tls`) are
also supported, with the difference that URI strings containing these schemes are parsed following
the rules described on their respective IANA provisional registration documents.
The actual list of supported connection parameters can vary depending on each connection backend so
it is recommended to refer to their specific documentation or implementation for details.
Predis can aggregate multiple connections when providing an array of connection parameters and the
appropriate option to instruct the client about how to aggregate them (clustering, replication or a
custom aggregation logic). Named arrays and URI strings can be mixed when providing configurations
for each node:
```php
$client = new Predis\Client([
'tcp://10.0.0.1?alias=first-node', ['host' => '10.0.0.2', 'alias' => 'second-node'],
], [
'cluster' => 'predis',
]);
```
See the [aggregate connections](#aggregate-connections) section of this document for more details.
Connections to Redis are lazy meaning that the client connects to a server only if and when needed.
While it is recommended to let the client do its own stuff under the hood, there may be times when
it is still desired to have control of when the connection is opened or closed: this can easily be
achieved by invoking `$client->connect()` and `$client->disconnect()`. Please note that the effect
of these methods on aggregate connections may differ depending on each specific implementation.
### Client configuration ###
Many aspects and behaviors of the client can be configured by passing specific client options to the
second argument of `Predis\Client::__construct()`:
```php
$client = new Predis\Client($parameters, ['prefix' => 'sample:']);
```
Options are managed using a mini DI-alike container and their values can be lazily initialized only
when needed. The client options supported by default in Predis are:
- `prefix`: prefix string applied to every key found in commands.
- `exceptions`: whether the client should throw or return responses upon Redis errors.
- `connections`: list of connection backends or a connection factory instance.
- `cluster`: specifies a cluster backend (`predis`, `redis` or callable).
- `replication`: specifies a replication backend (`predis`, `sentinel` or callable).
- `aggregate`: configures the client with a custom aggregate connection (callable).
- `parameters`: list of default connection parameters for aggregate connections.
- `commands`: specifies a command factory instance to use through the library.
Users can also provide custom options with values or callable objects (for lazy initialization) that
are stored in the options container for later use through the library.
### Aggregate connections ###
Aggregate connections are the foundation upon which Predis implements clustering and replication and
they are used to group multiple connections to single Redis nodes and hide the specific logic needed
to handle them properly depending on the context. Aggregate connections usually require an array of
connection parameters along with the appropriate client opti
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
今天给大家带来wordpress开启redis缓存 加速速度仅需0.1秒,不开玩笑真的非常有效,wordpress在数据比较大的情况下表现为慢吞吞。原因就是不断的对数据库的查询造成的,怎么才能减少MYSQL数据库负担呢?那么就是需要利用插件Redis Object Cache来实现。 宝塔面板php安装Redis拓展,注意要到php拓展里面安装Redis拓展,不能直接在宝塔软件商店里面装,直接在软件商店装会pho会连接不上redis
资源推荐
资源详情
资源评论
收起资源包目录
wordpress加速缓存插件Redis Object CacheV2.4.4 (405个子文件)
create-command-test 7KB
admin.css 3KB
Dockerfile 747B
Dockerfile 747B
Dockerfile 747B
Dockerfile 747B
Dockerfile 747B
Dockerfile 713B
生财指南针.jpg 41KB
apexcharts.min.js 476KB
admin.js 17KB
composer.json 1KB
composer.json 612B
LICENSE 1KB
LICENSE 1KB
README.markdown 9KB
LICENSE.md 34KB
README.md 20KB
object-cache.php 100KB
Client.php 57KB
class-plugin.php 49KB
SentinelReplication.php 20KB
RedisCluster.php 19KB
Client.php 17KB
ClientInterface.php 16KB
KeyPrefixProcessor.php 15KB
ClusterStrategy.php 15KB
MasterSlaveReplication.php 14KB
MultiExec.php 12KB
Sentinel.php 12KB
PhpiredisSocketConnection.php 12KB
StreamConnection.php 11KB
ClientContextInterface.php 11KB
overview.php 10KB
Cluster.php 9KB
WebdisConnection.php 9KB
ReplicationStrategy.php 8KB
settings.php 7KB
PhpiredisStreamConnection.php 7KB
HashRing.php 7KB
Pipeline.php 6KB
class-metrics.php 6KB
AbstractConsumer.php 6KB
PredisCluster.php 5KB
Parameters.php 5KB
Factory.php 5KB
class-predis.php 5KB
class-tab.php 5KB
class-commands.php 5KB
diagnostics.php 5KB
SlotMap.php 5KB
Connections.php 5KB
CursorBasedIterator.php 5KB
ListKey.php 4KB
Consumer.php 4KB
AbstractConnection.php 4KB
Commands.php 4KB
DispatcherLoop.php 4KB
Consumer.php 4KB
class-autoloader.php 4KB
query-monitor.php 4KB
Factory.php 4KB
Aggregate.php 4KB
Replication.php 4KB
class-qm-collector.php 4KB
ConnectionErrorProof.php 4KB
GEOSEARCH.php 3KB
Atomic.php 3KB
class-qm-output.php 3KB
ProtocolProcessor.php 3KB
CRC16.php 3KB
ResponseReader.php 3KB
MultiExecState.php 3KB
Options.php 3KB
ProcessorChain.php 3KB
CompositeStreamConnection.php 3KB
Handler.php 3KB
Cluster.php 3KB
CompositeProtocolProcessor.php 3KB
RawCommand.php 3KB
INFO.php 3KB
Command.php 3KB
ScriptCommand.php 2KB
MultiBulkIterator.php 2KB
ZRANGE.php 2KB
MultiBulkTuple.php 2KB
ParametersInterface.php 2KB
RedisFactory.php 2KB
CommunicationException.php 2KB
CRC16.php 2KB
GEORADIUS.php 2KB
SORT.php 2KB
MultiBulk.php 2KB
Count.php 2KB
OptionsInterface.php 2KB
ZMPOP.php 2KB
KetamaRing.php 2KB
redis-cache.php 2KB
ZSCAN.php 2KB
HSCAN.php 2KB
共 405 条
- 1
- 2
- 3
- 4
- 5
资源评论
凉亭下
- 粉丝: 621
- 资源: 283
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- DIWA353锅筒筒体的焊接工艺 - .pdf
- DLT 370-2010 承压设备焊接接头金属磁记忆检测.pdf
- DLT 678-1999 电站钢结构焊接通用技术条件.pdf
- DLT 678-2013 电力钢结构焊接通用技术条件.pdf
- DLT 734-2000 火力发电厂锅炉汽包焊接修复技术导则.pdf
- DLT 754-2001 铝母线焊接技术规程.pdf
- 基于AI外呼系统,基于自然语言处理(NLP)、语音识别(ASR)、语音合成(TTS)和通讯(freeswitch)技术,实现自动语音应答,用自然逼真的对话与客户
- DLT 754-2013 母线焊接技术规程.pdf
- DLT 819-2010 火力发电厂焊接热处理技术规程.pdf
- DLT 821-2002 钢制承压管道对接焊接接头射线检验技术规程.pdf
- DLT 868-2014 焊接工艺评定规程.pdf
- DLT 820-2002 管道焊接接头超声波检验技术规程.pdf
- DLT 1097-2008 火电厂凝汽器管板焊接技术规程.pdf
- DLT 905-2004 汽轮机叶片焊接修复技术导则.pdf
- DLT 1118-2009 核电厂常规岛焊接技术规程.pdf
- DLT 1117-2009 核电厂常规岛焊接工艺评定规程.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功