predis 参数说明手册

发布订阅

<?php

/*
 * This file is part of the Predis package.
 *
 * (c) Daniele Alessandri <suppakilla@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

require __DIR__.'/shared.php';

// Starting from Redis 2.0 clients can subscribe and listen for events published
// on certain channels using a Publish/Subscribe (PUB/SUB) approach.

// Create a client and disable r/w timeout on the socket
$client = new Predis\Client($single_server + array('read_write_timeout' => 0));

// Initialize a new pubsub consumer.
$pubsub = $client->pubSubLoop();

// Subscribe to your channels
$pubsub->subscribe('control_channel', 'notifications');

// Start processing the pubsup messages. Open a terminal and use redis-cli
// to push messages to the channels. Examples:
//   ./redis-cli PUBLISH notifications "this is a test"
//   ./redis-cli PUBLISH control_channel quit_loop
foreach ($pubsub as $message) {
    switch ($message->kind) {
        case 'subscribe':
            echo "Subscribed to {$message->channel}", PHP_EOL;
            break;

        case 'message':
            if ($message->channel == 'control_channel') {
                if ($message->payload == 'quit_loop') {
                    echo 'Aborting pubsub loop...', PHP_EOL;
                    $pubsub->unsubscribe();
                } else {
                    echo "Received an unrecognized command: {$message->payload}.", PHP_EOL;
                }
            } else {
                echo "Received the following message from {$message->channel}:",
                     PHP_EOL, "  {$message->payload}", PHP_EOL, PHP_EOL;
            }
            break;
    }
}

// Always unset the pubsub consumer instance when you are done! The
// class destructor will take care of cleanups and prevent protocol
// desynchronizations between the client and the server.
unset($pubsub);

// Say goodbye :-)
$version = redis_version($client->info());
echo "Goodbye from Redis $version!", PHP_EOL;

 

 

$userInfo = Redis::set('test','mytest','EX',10);这样才对,这样设置过期时间是10秒

下面是对的

public function set($key, $value, $expireResolution = null, $expireTTL = null, $flag = null)

第一个参数 和第二个参数不用讲

expireResolution 是过期策略,比如

EX seconds -- Set the specified expire time, in seconds. 秒

PX milliseconds -- Set the specified expire time, in milliseconds. 毫秒

NX -- Only set the key if it does not already exist. 不存在则设置

XX -- Only set the key if it already exist. 存在则设置

第四个参数是

expireTTL 过期时间

 

 predis 参数说明手册

* @method int    del(array $keys) 在 key 存在时删除 key
* @method string dump($key) 序列化给定 key ,并返回被序列化的值
* @method int    exists($key) 检查给定 key 是否存在
* @method int    expire($key, $seconds) 为给定 key 设置过期时间,以秒计
* @method int    expireat($key, $timestamp) 为给定 key 设置过期时间,以秒计 时间戳(unix timestamp)。
* @method array  keys($pattern) 查找所有符合给定模式( pattern)的 key 。
* @method int    move($key, $db) 将当前数据库的 key 移动到给定的数据库 db 当中。
* @method mixed  object($subcommand, $key) 允许从内部察看给定 key 的 Redis 对象
* @method int    persist($key) 移除 key 的过期时间,key 将持久保持
* @method int    pexpire($key, $milliseconds) 设置 key 的过期时间以毫秒计
* @method int    pexpireat($key, $timestamp) 设置 key 的过期时间以毫秒计 时间戳(unix timestamp)。
* @method int    pttl($key) 以毫秒为单位返回 key 的剩余的过期时间
* @method string randomkey() 从当前数据库中随机返回一个 key 。
* @method mixed  rename($key, $target) 修改 key 的名称
* @method int    renamenx($key, $target) 仅当 newkey 不存在时,将 key 改名为 newkey
* @method array  scan($cursor, array $options = null) 迭代数据库中的数据库键
* @method array  sort($key, array $options = null) 返回或保存给定列表、集合、有序集合 key 中经过排序的元素
* @method int    ttl($key) 以秒为单位,返回给定 key 的剩余生存时间(TTL, time to live)。
* @method mixed  type($key) 返回 key 所储存的值的类型
* @method int    append($key, $value) 用于为指定的 key 追加值。
* @method int    bitcount($key, $start = null, $end = null) 计算字符串中的设置位数(填充计数)。
* @method int    bitop($operation, $destkey, $key) 对一个或多个保存二进制位的字符串 key 进行位元操作,并将结果保存到 destkey 上。
* @method array  bitfield($key, $subcommand, ...$subcommandArg) 把Redis字符串当作位数组,并能对变长位宽和任意未字节对齐的指定整型位域进行寻址
* @method int    decr($key) 将 key 中储存的数字值减一
* @method int    decrby($key, $decrement) 将 key 中储存的数字值减指定的减量值
* @method string get($key) 用于获取指定 key 的值。如果 key 不存在,返回 nil 。如果key 储存的值不是字符串类型,返回一个错误
* @method int    getbit($key, $offset) 对 key 所储存的字符串值,获取指定偏移量上的位(bit)
* @method string getrange($key, $start, $end) 用于获取存储在指定 key 中字符串的子字符串。字符串的截取范围由 start 和 end 两个偏移量决定(包括 start 和 end 在内)
* @method string getset($key, $value) 用于设置指定 key 的新值,并返回 key 的旧值
* @method int    incr($key) 将 key 中储存的数字值加一
* @method int    incrby($key, $increment) 将 key 中储存的数字值加指定的减量值
* @method string incrbyfloat($key, $increment) 为 key 中所储存的值加上指定的浮点数增量值
* @method array  mget(array $keys) 返回所有(一个或多个)给定 key 的值。 如果给定的 key 里面,有某个 key 不存在,那么这个 key 返回特殊值 nil
* @method mixed  mset(array $dictionary) 用于同时设置一个或多个 key-value 对
* @method int    msetnx(array $dictionary) 用于所有给定 key 都不存在时,同时设置一个或多个 key-value 对
* @method mixed  psetex($key, $milliseconds, $value) 以毫秒为单位设置 key 的生存时间
* @method mixed  set($key, $value, $expireResolution = null, $expireTTL = null, $flag = null)将字符串值 value 关联到 key 。如果 key 已经持有其他值, SET 就覆写旧值,无视类型。
* @method int    setbit($key, $offset, $value) 用于对 key 所储存的字符串值,设置或清除指定偏移量上的位(bit)。
* @method int    setex($key, $seconds, $value) 为指定的 key 设置值及其过期时间。如果 key 已经存在, SETEX 命令将会替换旧的值
* @method int    setnx($key, $value) 在指定的 key 不存在时,为 key 设置指定的值
* @method int    setrange($key, $offset, $value) 用指定的字符串覆盖给定 key 所储存的字符串值,覆盖的位置从偏移量 offset 开始
* @method int    strlen($key) 用于获取指定 key 所储存的字符串值的长度。当 key 储存的不是字符串值时,返回一个错误。
* @method int    hdel($key, array $fields) 用于删除哈希表 key 中的一个或多个指定字段,不存在的字段将被忽略
* @method int    hexists($key, $field) 检测hash表中键是否存在
* @method string hget($key, $field) 返回哈希表中,指定键的值
* @method array  hgetall($key) 返回哈希表中,所有的字段和值
* @method int    hincrby($key, $field, $increment) 用于为哈希表中的字段值加1
* @method string hincrbyfloat($key, $field, $increment) 用于为哈希表中的字段值加上指定浮点数增量值
* @method array  hkeys($key) 返回hash表$key的键名
* @method int    hlen($key) 返回hash表$key的键的数量
* @method array  hmget($key, array $fields) 批量获取$key中的字段值。
* @method mixed  hmset($key, array $dictionary) 将指定的字段设置为存储在其中的哈希中各自的值key。该命令覆盖散列中已存在的任何指定字段。如果key不存在,则创建一个保存散列的新密钥。
* @method array  hscan($key, $cursor, array $options = null) 迭代哈希表中的键值对。 分页
* @method int    hset($key, $field, $value) 设置field在存储在哈希key来value。如果key不存在,则创建一个保存散列的新密钥。如果field已经存在于散列中,它将被覆盖。
* @method int    hsetnx($key, $field, $value) 设置field在哈希存储在key到value,只有当field不存在。如果key不存在,则创建一个保存散列的新密钥。如果field已经存在,则该操作不起作用。
* @method array  hvals($key) 返回存储在中的哈希中的所有值key
* @method int    hstrlen($key, $field) 返回与相关联的值的字符串长度field在存储在散列key。如果key或者field不存在,则返回0
* @method array  blpop(array $keys, $timeout) 移出并获取列表的第一个元素, 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止。
* @method array  brpop(array $keys, $timeout) 移出并获取列表的最后一个元素, 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止
* @method array  brpoplpush($source, $destination, $timeout) 从列表中弹出一个值,将弹出的元素插入到另外一个列表中并返回它; 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止。
* @method string lindex($key, $index) 用于通过索引获取列表中的元素。你也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推。
* @method int    linsert($key, $whence, $pivot, $value) 用于在列表的元素前或者后插入元素。 当指定元素不存在于列表中时,不执行任何操作。 当列表不存在时,被视为空列表,不执行任何操作。 如果 key 不是列表类型,返回一个错误
* @method int    llen($key) 返回列表的长度。 如果列表 key 不存在,则 key 被解释为一个空列表,返回 0 。 如果 key 不是列表类型,返回一个错误。
* @method string lpop($key) 用于移除并返回列表的第一个元素。
* @method int    lpush($key, array $values) 将一个或多个值插入到列表头部。 如果 key 不存在,一个空列表会被创建并执行 LPUSH 操作。 当 key 存在但不是列表类型时,返回一个错误。
* @method int    lpushx($key, $value) 将一个或多个值插入到已存在的列表头部,列表不存在时操作无效
* @method array  lrange($key, $start, $stop) 返回列表中指定区间内的元素,区间以偏移量 START 和 END 指定。
* @method int    lrem($key, $count, $value) 根据参数 COUNT 的值,移除列表中与参数 VALUE 相等的元素
* @method mixed  lset($key, $index, $value) 通过索引来设置元素的值
* @method mixed  ltrim($key, $start, $stop) 对一个列表进行修剪(trim),就是说,让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除
* @method string rpop($key) 用于移除并返回列表的最后一个元素
* @method string rpoplpush($source, $destination) 移除列表的最后一个元素,并将该元素添加到另一个列表并返回
* @method int    rpush($key, array $values) 用于将一个或多个值插入到列表的尾部(最右边)
* @method int    rpushx($key, $value) 用于将一个值插入到已存在的列表尾部(最右边)。如果列表不存在,操作无效
* @method int    sadd($key, array $members) 将一个或多个成员元素加入到集合中,已经存在于集合的成员元素将被忽略
* @method int    scard($key) 返回集合中元素的数量
* @method array  sdiff(array $keys) 返回给定集合之间的差集。不存在的集合 key 将视为空集
* @method int    sdiffstore($destination, array $keys) 将给定集合之间的差集存储在指定的集合中。如果指定的集合 key 已存在,则会被覆盖
* @method array  sinter(array $keys) 返回给定所有给定集合的交集。 不存在的集合 key 被视为空集。 当给定集合当中有一个空集时,结果也为空集(根据集合运算定律)。
* @method int    sinterstore($destination, array $keys) 将给定集合之间的交集存储在指定的集合中。如果指定的集合已经存在,则将其覆盖
* @method int    sismember($key, $member) 判断成员元素是否是集合的成员
* @method array  smembers($key) 返回集合中的所有的成员。 不存在的集合 key 被视为空集合
* @method int    smove($source, $destination, $member) 将指定成员 member 元素从 source 集合移动到 destination 集合
* @method string spop($key, $count = null) 用于移除集合中的指定 key 的一个或多个随机元素,移除后会返回移除的元素
* @method string srandmember($key, $count = null) 用于返回集合中的一个随机元素
* @method int    srem($key, $member) 用于移除集合中的一个或多个成员元素,不存在的成员元素会被忽略
* @method array  sscan($key, $cursor, array $options = null) 用于迭代集合中键的元素
* @method array  sunion(array $keys) 返回给定集合的并集。不存在的集合 key 被视为空集
* @method int    sunionstore($destination, array $keys) 将给定集合的并集存储在指定的集合 destination 中。如果 destination 已经存在,则将其覆盖
* @method int    zadd($key, array $membersAndScoresDictionary) 用于将一个或多个成员元素及其分数值加入到有序集当中
* @method int    zcard($key) 用于计算集合中元素的数量。
* @method string zcount($key, $min, $max) 用于计算有序集合 中指定分数区间的成员数量
* @method string zincrby($key, $increment, $member) 为有序集 key 的成员 member 的 score 值加上增量 increment 。
* @method int    zinterstore($destination, array $keys, array $options = null) 计算给定的一个或多个有序集的交集,其中给定 key 的数量必须以 numkeys 参数指定,并将该交集(结果集)储存到 destination 。
* @method array  zrange($key, $start, $stop, array $options = null) 返回有序集中,指定区间内的成员
* @method array  zrangebyscore($key, $min, $max, array $options = null) 返回有序集合中指定分数区间的成员列表。有序集成员按分数值递增(从小到大)次序排列
* @method int    zrank($key, $member) 返回有序集中指定成员的排名。其中有序集成员按分数值递增(从小到大)顺序排列
* @method int    zrem($key, $member) 用于移除有序集中的一个或多个成员,不存在的成员将被忽略
* @method int    zremrangebyrank($key, $start, $stop) 用于移除有序集中,指定排名(rank)区间内的所有成员
* @method int    zremrangebyscore($key, $min, $max) 用于移除有序集中,指定分数(score)区间内的所有成员
* @method array  zrevrange($key, $start, $stop, array $options = null) 返回有序集中,指定区间内的成员
* @method array  zrevrangebyscore($key, $max, $min, array $options = null) 返回有序集中指定分数区间内的所有的成员。有序集成员按分数值递减(从大到小)的次序排列。
* @method int    zrevrank($key, $member) 返回有序集中成员的排名。其中有序集成员按分数值递减(从大到小)排序。
* @method int    zunionstore($destination, array $keys, array $options = null) 计算给定的一个或多个有序集的并集,其中给定 key 的数量必须以 numkeys 参数指定,并将该并集(结果集)储存到 destination 。
* @method string zscore($key, $member) 返回有序集中,成员的分数值。 如果成员元素不是有序集 key 的成员,或 key 不存在,返回 nil
* @method array  zscan($key, $cursor, array $options = null) 用于迭代有序集合中的元素(包括元素成员和元素分值)
* @method array  zrangebylex($key, $start, $stop, array $options = null) 通过字典区间返回有序集合的成员
* @method array  zrevrangebylex($key, $start, $stop, array $options = null) 返回排序集中$key中的所有元素,其key值介于max和之间min
* @method int    zremrangebylex($key, $min, $max) 用于移除有序集合中给定的字典区间的所有成员
* @method int    zlexcount($key, $min, $max) 在计算有序集合中指定字典区间内成员数量
* @method int    pfadd($key, array $elements) 将所有元素参数添加到 $key 数据结构中
* @method mixed  pfmerge($destinationKey, array $sourceKeys) 将多个 HyperLogLog 合并为一个 HyperLogLog ,合并后的 HyperLogLog 的基数估算值是通过对所有 给定 HyperLogLog 进行并集计算得出的。
* @method int    pfcount(array $keys) 返回给定 $keys 的基数估算值
* @method mixed  pubsub($subcommand, $argument) 用于查看订阅与发布系统状态,它由数个不同格式的子命令组成
* @method int    publish($channel, $message) 用于将信息发送到指定的频道
* @method mixed  discard() 用于取消事务,放弃执行事务块内的所有命令
* @method array  exec() 用于执行所有事务块内的命令
* @method mixed  multi() 用于标记一个事务块的开始
* @method mixed  unwatch() 用于取消 WATCH 命令对所有 key 的监视。
* @method mixed  watch($key) 用于监视一个(或多个) key ,如果在事务执行之前这个(或这些) key 被其他命令所改动,那么事务将被打断
* @method mixed  eval($script, $numkeys, $keyOrArg1 = null, $keyOrArgN = null) 通过内置的 Lua 解释器,可以使用 EVAL 命令对 Lua 脚本进行求值
* @method mixed  evalsha($script, $numkeys, $keyOrArg1 = null, $keyOrArgN = null) 根据给定的 sha1 校验码,对缓存在服务器中的脚本进行求值
* @method mixed  script($subcommand, $argument = null) 脚本
* @method mixed  auth($password) 用于检测给定的密码和配置文件中的密码是否相符 输入密码
* @method string echo($message) 用于打印给定的字符串
* @method mixed  ping($message = null) 使用客户端向 Redis 服务器发送一个 PING测试与服务器的连接是否仍然生效,或者用于测量延迟值
* @method mixed  select($database) 用于切换到指定的数据库,数据库索引号 index 用数字值指定,以 0 作为起始索引值。
* @method mixed  bgrewriteaof() 用于异步执行一个 AOF(AppendOnly File) 文件重写操作。重写会创建一个当前 AOF 文件的体积优化版本。
* @method mixed  bgsave() 用于在后台异步保存当前数据库的数据到磁盘
* @method mixed  client($subcommand, $argument = null) redis 服务的客户端操作
* @method mixed  config($subcommand, $argument = null) redis 服务的配置参数操作
* @method int    dbsize() 用于返回当前数据库的 key 的数量
* @method mixed  flushall() 用于清空整个 Redis 服务器的数据(删除所有数据库的所有 key )
* @method mixed  flushdb() 用于清空当前数据库中的所有 key
* @method array  info($section = null) 以一种易于理解和阅读的格式,返回关于 Redis 服务器的各种信息和统计数值
* @method int    lastsave() 返回最近一次 Redis 成功将数据保存到磁盘上的时间,以 UNIX 时间戳格式表示
* @method mixed  save() 执行一个同步保存操作,将当前 Redis 实例的所有数据快照(snapshot)以 RDB 文件的形式保存到硬盘
* @method mixed  slaveof($host, $port) 用于在 Redis 运行时动态地修改复制(replication)功能的行为
* @method mixed  slowlog($subcommand, $argument = null) 用于读取和重置Redis慢查询日志
* @method array  time() 用于返回当前服务器时间
* @method array  command() 用于返回所有的Redis命令的详细信息,以数组形式展示
* @method int    geoadd($key, $longitude, $latitude, $member) 将指定的地理空间位置(纬度、经度、名称)添加到指定的key中
* @method array  geohash($key, array $members) 返回一个或多个位置元素的 Geohash 表示
* @method array  geopos($key, array $members) 从key里返回所有给定位置元素的位置(经度和纬度)
* @method string geodist($key, $member1, $member2, $unit = null) 返回两个给定位置之间的距离
* @method array  georadius($key, $longitude, $latitude, $radius, $unit, array $options = null) 以给定的经纬度为中心, 找出某一半径内的元素
* @method array  georadiusbymember($key, $member, $radius, $unit, array $options = null) 找出位于指定范围内的元素 中心点是由给定的位置元素决定的

 

posted @ 2022-11-17 14:35  菜的掉渣  阅读(423)  评论(0编辑  收藏  举报