README.markdown 官方介绍

# Predis #

## About ##

Predis is a flexible and feature-complete PHP (>= 5.3) client library for the Redis key-value store.

For a list of frequently asked questions about Predis, see the __FAQ__ file in the root of the repository.
For a version compatible with PHP 5.2 you must use the backported version from the latest release in the 0.6.x series.

## Main features ##

- Full support for Redis 1.2, 2.0 and 2.2. Different versions of Redis are supported via server profiles.
- Client-side sharding with support for consistent hashing and custom distribution strategies.
- Command pipelining on single and aggregated connections.
- Abstraction for Redis transactions (Redis >= 2.0) with support for CAS operations (Redis >= 2.2).
- Lazy connections to Redis instances are automatically estabilished upon the first call to a command.
- Ability to connect to Redis using TCP/IP or UNIX domain sockets by default.
- Flexible system to define and register your own set of commands to a client instance.

## Quick examples ##

See the [official wiki](http://wiki.github.com/nrk/predis) of the project for a more
complete coverage of all the features available in Predis.

### Loading Predis

Predis relies on the autoloading features of PHP and complies with the
[PSR-0 standard](http://groups.google.com/group/php-standards/web/psr-0-final-proposal)
for interoperability with most of the major frameworks and libraries.
When used in simple projects or scripts you might need to define an autoloader function:

spl_autoload_register(function($class) {
        $file = PREDIS_BASE_PATH . strtr($class, '//', '/') . '.php';
        if (file_exists($file)) {
            require $file;
            return true;
        }
    });

You can also create a single Phar archive from the repository just by launching the _createPhar.php_
script located in the _bin_ directory. The generated Phar ships with a stub that defines an autoloader
function for Predis, so you just need to require the Phar archive in order to be able to use the library.

Alternatively you can generate a single PHP file that holds every class, just like older versions of Predis,
using the _createSingleFile.php_ script located in the _bin_ directory. In this way you can load Predis in
your scripts simply by using functions such as _require_ and _include_, but this practice is not encouraged.

### Connecting to a local instance of Redis ###

You don't have to specify a tcp host and port when connecting to Redis instances running on the
localhost on the default port:

$redis = new Predis/Client();
    $redis->set('library', 'predis');
    $value = $redis->get('library');

You can also use an URI string or an array-based dictionary to specify the connection parameters:

$redis = new Predis/Client('tcp://10.0.0.1:6379');

// is equivalent to:

$redis = new Predis/Client(array(
        'scheme' => 'tcp',
        'host'   => '10.0.0.1',
        'port'   => 6379,
    ));

### Pipelining multiple commands to multiple instances of Redis with client-side sharding ###

Pipelining helps with performances when there is the need to issue many commands to a server
in one go. Furthermore, pipelining works transparently even on aggregated connections. Predis,
in fact, supports client-side sharding of data using consistent-hashing on keys and clustered
connections are supported natively by the client class.

$redis = new Predis/Client(array(
        array('host' => '10.0.0.1', 'port' => 6379),
        array('host' => '10.0.0.2', 'port' => 6379)
    ));

$replies = $redis->pipeline(function($pipe) {
        for ($i = 0; $i < 1000; $i++) {
            $pipe->set("key:$i", str_pad($i, 4, '0', 0));
            $pipe->get("key:$i");
        }
    });

### Overriding standard connection classes with custom ones ###

Predis allows developers to create new connection classes to add support for new protocols
or override the existing ones to provide a different implementation compared to the default
classes. This can be obtained by subclassing the Predis/Network/IConnectionSingle interface.

class MyConnectionClass implements Predis/Network/IConnectionSingle {
        // implementation goes here
    }

// Let Predis automatically use your own class to handle the default TCP connection

Predis/ConnectionSchemes::define('tcp', 'MyConnectionClass');

You can have a look at the Predis/Network namespace for some actual code that gives a better
insight about how to create new connection classes.

### Definition and runtime registration of new commands on the client ###

Let's suppose Redis just added the support for a brand new feature associated
with a new command. If you want to start using the above mentioned new feature
right away without messing with Predis source code or waiting for it to find
its way into a stable Predis release, then you can start off by creating a new
class that matches the command type and its behaviour and then bind it to a
client instance at runtime. Actually, it is easier done than said:

class BrandNewRedisCommand extends Predis/Commands/Command {
        public function getId() { return 'NEWCMD'; }
    }

$redis = new Predis/Client();
    $redis->getProfile()->defineCommand('BrandNewRedisCommand', 'newcmd');
    $redis->newcmd();

## Development ##

Predis is fully backed up by a test suite which tries to cover all the aspects of the
client library and the interaction of every single command with a Redis server. If you
want to work on Predis, it is highly recommended that you first run the test suite to
be sure that everything is OK, and report strange behaviours or bugs.

When modifying Predis please be sure that no warnings or notices are emitted by PHP
by running the interpreter in your development environment with the "error_reporting"
variable set to E_ALL | E_STRICT.

The recommended way to contribute to Predis is to fork the project on GitHub, create
new topic branches on your newly created repository to fix or add features and then
open a new pull request with a description of the applied changes. Obviously, you can
use any other Git hosting provider of your preference. Diff patches will be accepted
too, even though they are not the preferred way to contribute to Predis.

## Dependencies ##

- PHP >= 5.3.0
- PHPUnit >= 3.5.0 (needed to run the test suite)

## Links ##

### Project ###
- [Source code](http://github.com/nrk/predis/)
- [Wiki](http://wiki.github.com/nrk/predis/)
- [Issue tracker](http://github.com/nrk/predis/issues)

### Related ###
- [Redis](http://code.google.com/p/redis/)
- [PHP](http://php.net/)
- [PHPUnit](http://www.phpunit.de/)
- [Git](http://git-scm.com/)

## Author ##

- [Daniele Alessandri](mailto:suppakilla@gmail.com) ([twitter](http://twitter.com/JoL1hAHN))

## Contributors ##

- [Lorenzo Castelli](http://github.com/lcastelli)
- [Jordi Boggiano](http://github.com/Seldaek) ([twitter](http://twitter.com/seldaek))
- [Sebastian Waisbrot](http://github.com/seppo0010) for his work on extending [phpiredis](http://github.com/seppo0010/phpiredis) for Predis

## License ##

The code for Predis is distributed under the terms of the MIT license (see LICENSE).

redis客户端predis介绍相关推荐

  1. redis客户端 predis与phpredis 比较

    predis目录中有一个FAQ.markdown文件,FAQ中文意思经常问到的问题,该文档对redis的客户端predis和phpredis进行了比较分析,优点,不足做了说明,还是老外的文档清楚,一看 ...

  2. PHP: Redis客户端predis/predis

    文档: packagist: https://packagist.org/packages/predis/predis github: https://github.com/predis/predis ...

  3. 操作Redis客户端工具详解之功能介绍及配置

    问题背景 日常开发过程中,对于缓存,我们并不陌生.常用的缓存有个Redis.memcache.memcached等.那么操作缓存的工具又有很多,我们该怎么选择呢? 今天我们聊一下Redis的操作客户端 ...

  4. Redisson--最好用的Redis客户端--介绍

    原文网址:Redisson--最好用的Redis客户端--介绍_IT利刃出鞘的博客-CSDN博客 简介 说明 本文介绍Redisson这款最好用的Redis客户端. 官网 官网:Redisson: R ...

  5. [ 搭建Redis本地服务器实践系列三 ] :图解Redis客户端工具连接Redis服务器

    原文:[ 搭建Redis本地服务器实践系列三 ] :图解Redis客户端工具连接Redis服务器 上一章 [ 搭建Redis本地服务器实践系列二 ] :图解CentOS7配置Redis  介绍了Red ...

  6. Java开发-Redis客户端Jedis

    1.部署Redis后启动服务端: 2.Jedis网址:https://github.com/xetorthio/jedis/tree/2.6 应用maven管理jar包依赖:新建maven项目(ecl ...

  7. 阿里云专访Redisson作者Rui Gu:构建开源企业级Redis客户端之路

    摘要: 本文为阿里云同学在RedisConf2018上对Redisson开源客户端作者Rui Gu做的一个专访,主要介绍了Rui Gu参与开启Redisson客户端开发的历程,同时也详细介绍了Redi ...

  8. 深入Redis客户端(redis客户端属性、redis缓冲区、关闭redis客户端)

    深入Redis客户端(redis客户端属性.redis缓冲区.关闭redis客户端) Redis 数据库采用 I/O 多路复用技术实现文件事件处理器,服务器采用单线程单进程的方式来处理多个客户端发送过 ...

  9. 使用.NET System.IO.Pipelines和Kestrel套接字库创建Redis客户端

    目录 背景 介绍 Redis协议 软件设计 下载最新的存储库存档 本文是关于为Redis服务器创建异步客户端的系列文章中的第一篇,该客户端低分配,因此GC压力小,数据复制最少.这是使用技术完成的,这些 ...

最新文章

  1. C++多线程:thread类创建线程的多种方式
  2. IF10+的数据库文章!这里有5个案例,一起发起来?
  3. 皮一皮:到底是土还是士...
  4. php弱类型变量是什么,php弱类型变量如何实现?
  5. Github标星66.6k+:常见数据结构与算法的Python实现
  6. 解决无法连接到visual studio开发服务器的问题
  7. 一朵更好的云 MADE IN 青云QingCloud
  8. 自定义WPF ListBox的选择样式
  9. ASP.Net Web 服务 – 如何使用会话状态
  10. 微服务 API 网关建设,实践经验分享!
  11. Unity高亮插件HighlightingSystem使用
  12. 如何在Visio中旋转图形
  13. OCM实验-备份恢复-控制文件
  14. 日本性价比旅馆分析报告
  15. linux wipe命令,如何使用wipefs命令擦除磁盘上的签名
  16. c# NPOI 导出Excel 冻结窗格
  17. 神策应用-概述认知(一)
  18. linux防火墙之firewalld
  19. win10 升级到21H1 后Thinkpad X系列本本 音频驱动 没有声音
  20. 有效载荷偶联ADC抗体偶联物的特征及应用探讨-瑞禧

热门文章

  1. 计算机组成原理-第一章(1)-概述
  2. linux|使用Telnet进行与板子通讯
  3. 《算法(第四版)》1.3.49:有限个栈实现队列,练习题学习小结
  4. 【计算理论】图灵机 ( 图灵机示例 )
  5. 爬取链家北京租房数据并做简单分析
  6. 12 | 理解电路:从电报机到门电路,我们如何做到“千里传信”?
  7. 超市积分管理系统(论文+源码)
  8. 大佬们当年是怎样熬过资本寒冬的?
  9. 51单片机常用波特率设置
  10. 软件测试必学内容,你都掌握了吗?