laravel中redis个方法的使用

在laravel中使用redis自带方法的时候会发现许多原生的方法都不存在了,laravel对其进行了重新的封装但是在文档中并没有找到相关的资料最后在

\vendor\predis\predis\src\Profile\RedisProfile.php

该文件的createCommand方法重打印出

$this->commands

发现许多方法名是被重写的,以下为所有重新定义的方法名

array(151) {
  ["EXISTS"]=>
  string(24) "Predis\Command\KeyExists"
  ["DEL"]=>
  string(24) "Predis\Command\KeyDelete"
  ["TYPE"]=>
  string(22) "Predis\Command\KeyType"
  ["KEYS"]=>
  string(22) "Predis\Command\KeyKeys"
  ["RANDOMKEY"]=>
  string(24) "Predis\Command\KeyRandom"
  ["RENAME"]=>
  string(24) "Predis\Command\KeyRename"
  ["RENAMENX"]=>
  string(32) "Predis\Command\KeyRenamePreserve"
  ["EXPIRE"]=>
  string(24) "Predis\Command\KeyExpire"
  ["EXPIREAT"]=>
  string(26) "Predis\Command\KeyExpireAt"
  ["TTL"]=>
  string(28) "Predis\Command\KeyTimeToLive"
  ["MOVE"]=>
  string(22) "Predis\Command\KeyMove"
  ["SORT"]=>
  string(22) "Predis\Command\KeySort"
  ["DUMP"]=>
  string(22) "Predis\Command\KeyDump"
  ["RESTORE"]=>
  string(25) "Predis\Command\KeyRestore"
  ["SET"]=>
  string(24) "Predis\Command\StringSet"
  ["SETNX"]=>
  string(32) "Predis\Command\StringSetPreserve"
  ["MSET"]=>
  string(32) "Predis\Command\StringSetMultiple"
  ["MSETNX"]=>
  string(40) "Predis\Command\StringSetMultiplePreserve"
  ["GET"]=>
  string(24) "Predis\Command\StringGet"
  ["MGET"]=>
  string(32) "Predis\Command\StringGetMultiple"
  ["GETSET"]=>
  string(27) "Predis\Command\StringGetSet"
  ["INCR"]=>
  string(30) "Predis\Command\StringIncrement"
  ["INCRBY"]=>
  string(32) "Predis\Command\StringIncrementBy"
  ["DECR"]=>
  string(30) "Predis\Command\StringDecrement"
  ["DECRBY"]=>
  string(32) "Predis\Command\StringDecrementBy"
  ["RPUSH"]=>
  string(27) "Predis\Command\ListPushTail"
  ["LPUSH"]=>
  string(27) "Predis\Command\ListPushHead"
  ["LLEN"]=>
  string(25) "Predis\Command\ListLength"
  ["LRANGE"]=>
  string(24) "Predis\Command\ListRange"
  ["LTRIM"]=>
  string(23) "Predis\Command\ListTrim"
  ["LINDEX"]=>
  string(24) "Predis\Command\ListIndex"
  ["LSET"]=>
  string(22) "Predis\Command\ListSet"
  ["LREM"]=>
  string(25) "Predis\Command\ListRemove"
  ["LPOP"]=>
  string(27) "Predis\Command\ListPopFirst"
  ["RPOP"]=>
  string(26) "Predis\Command\ListPopLast"
  ["RPOPLPUSH"]=>
  string(34) "Predis\Command\ListPopLastPushHead"
  ["SADD"]=>
  string(21) "Predis\Command\SetAdd"
  ["SREM"]=>
  string(24) "Predis\Command\SetRemove"
  ["SPOP"]=>
  string(21) "Predis\Command\SetPop"
  ["SMOVE"]=>
  string(22) "Predis\Command\SetMove"
  ["SCARD"]=>
  string(29) "Predis\Command\SetCardinality"
  ["SISMEMBER"]=>
  string(26) "Predis\Command\SetIsMember"
  ["SINTER"]=>
  string(30) "Predis\Command\SetIntersection"
  ["SINTERSTORE"]=>
  string(35) "Predis\Command\SetIntersectionStore"
  ["SUNION"]=>
  string(23) "Predis\Command\SetUnion"
  ["SUNIONSTORE"]=>
  string(28) "Predis\Command\SetUnionStore"
  ["SDIFF"]=>
  string(28) "Predis\Command\SetDifference"
  ["SDIFFSTORE"]=>
  string(33) "Predis\Command\SetDifferenceStore"
  ["SMEMBERS"]=>
  string(25) "Predis\Command\SetMembers"
  ["SRANDMEMBER"]=>
  string(30) "Predis\Command\SetRandomMember"
  ["ZADD"]=>
  string(22) "Predis\Command\ZSetAdd"
  ["ZINCRBY"]=>
  string(30) "Predis\Command\ZSetIncrementBy"
  ["ZREM"]=>
  string(25) "Predis\Command\ZSetRemove"
  ["ZRANGE"]=>
  string(24) "Predis\Command\ZSetRange"
  ["ZREVRANGE"]=>
  string(31) "Predis\Command\ZSetReverseRange"
  ["ZRANGEBYSCORE"]=>
  string(31) "Predis\Command\ZSetRangeByScore"
  ["ZCARD"]=>
  string(30) "Predis\Command\ZSetCardinality"
  ["ZSCORE"]=>
  string(24) "Predis\Command\ZSetScore"
  ["ZREMRANGEBYSCORE"]=>
  string(37) "Predis\Command\ZSetRemoveRangeByScore"
  ["PING"]=>
  string(29) "Predis\Command\ConnectionPing"
  ["AUTH"]=>
  string(29) "Predis\Command\ConnectionAuth"
  ["SELECT"]=>
  string(31) "Predis\Command\ConnectionSelect"
  ["ECHO"]=>
  string(29) "Predis\Command\ConnectionEcho"
  ["QUIT"]=>
  string(29) "Predis\Command\ConnectionQuit"
  ["INFO"]=>
  string(29) "Predis\Command\ServerInfoV26x"
  ["SLAVEOF"]=>
  string(28) "Predis\Command\ServerSlaveOf"
  ["MONITOR"]=>
  string(28) "Predis\Command\ServerMonitor"
  ["DBSIZE"]=>
  string(33) "Predis\Command\ServerDatabaseSize"
  ["FLUSHDB"]=>
  string(34) "Predis\Command\ServerFlushDatabase"
  ["FLUSHALL"]=>
  string(29) "Predis\Command\ServerFlushAll"
  ["SAVE"]=>
  string(25) "Predis\Command\ServerSave"
  ["BGSAVE"]=>
  string(35) "Predis\Command\ServerBackgroundSave"
  ["LASTSAVE"]=>
  string(29) "Predis\Command\ServerLastSave"
  ["SHUTDOWN"]=>
  string(29) "Predis\Command\ServerShutdown"
  ["BGREWRITEAOF"]=>
  string(41) "Predis\Command\ServerBackgroundRewriteAOF"
  ["SETEX"]=>
  string(30) "Predis\Command\StringSetExpire"
  ["APPEND"]=>
  string(27) "Predis\Command\StringAppend"
  ["SUBSTR"]=>
  string(27) "Predis\Command\StringSubstr"
  ["BLPOP"]=>
  string(35) "Predis\Command\ListPopFirstBlocking"
  ["BRPOP"]=>
  string(34) "Predis\Command\ListPopLastBlocking"
  ["ZUNIONSTORE"]=>
  string(29) "Predis\Command\ZSetUnionStore"
  ["ZINTERSTORE"]=>
  string(36) "Predis\Command\ZSetIntersectionStore"
  ["ZCOUNT"]=>
  string(24) "Predis\Command\ZSetCount"
  ["ZRANK"]=>
  string(23) "Predis\Command\ZSetRank"
  ["ZREVRANK"]=>
  string(30) "Predis\Command\ZSetReverseRank"
  ["ZREMRANGEBYRANK"]=>
  string(36) "Predis\Command\ZSetRemoveRangeByRank"
  ["HSET"]=>
  string(22) "Predis\Command\HashSet"
  ["HSETNX"]=>
  string(30) "Predis\Command\HashSetPreserve"
  ["HMSET"]=>
  string(30) "Predis\Command\HashSetMultiple"
  ["HINCRBY"]=>
  string(30) "Predis\Command\HashIncrementBy"
  ["HGET"]=>
  string(22) "Predis\Command\HashGet"
  ["HMGET"]=>
  string(30) "Predis\Command\HashGetMultiple"
  ["HDEL"]=>
  string(25) "Predis\Command\HashDelete"
  ["HEXISTS"]=>
  string(25) "Predis\Command\HashExists"
  ["HLEN"]=>
  string(25) "Predis\Command\HashLength"
  ["HKEYS"]=>
  string(23) "Predis\Command\HashKeys"
  ["HVALS"]=>
  string(25) "Predis\Command\HashValues"
  ["HGETALL"]=>
  string(25) "Predis\Command\HashGetAll"
  ["MULTI"]=>
  string(31) "Predis\Command\TransactionMulti"
  ["EXEC"]=>
  string(30) "Predis\Command\TransactionExec"
  ["DISCARD"]=>
  string(33) "Predis\Command\TransactionDiscard"
  ["SUBSCRIBE"]=>
  string(30) "Predis\Command\PubSubSubscribe"
  ["UNSUBSCRIBE"]=>
  string(32) "Predis\Command\PubSubUnsubscribe"
  ["PSUBSCRIBE"]=>
  string(39) "Predis\Command\PubSubSubscribeByPattern"
  ["PUNSUBSCRIBE"]=>
  string(41) "Predis\Command\PubSubUnsubscribeByPattern"
  ["PUBLISH"]=>
  string(28) "Predis\Command\PubSubPublish"
  ["CONFIG"]=>
  string(27) "Predis\Command\ServerConfig"
  ["PERSIST"]=>
  string(25) "Predis\Command\KeyPersist"
  ["STRLEN"]=>
  string(27) "Predis\Command\StringStrlen"
  ["SETRANGE"]=>
  string(29) "Predis\Command\StringSetRange"
  ["GETRANGE"]=>
  string(29) "Predis\Command\StringGetRange"
  ["SETBIT"]=>
  string(27) "Predis\Command\StringSetBit"
  ["GETBIT"]=>
  string(27) "Predis\Command\StringGetBit"
  ["RPUSHX"]=>
  string(28) "Predis\Command\ListPushTailX"
  ["LPUSHX"]=>
  string(28) "Predis\Command\ListPushHeadX"
  ["LINSERT"]=>
  string(25) "Predis\Command\ListInsert"
  ["BRPOPLPUSH"]=>
  string(42) "Predis\Command\ListPopLastPushHeadBlocking"
  ["ZREVRANGEBYSCORE"]=>
  string(38) "Predis\Command\ZSetReverseRangeByScore"
  ["WATCH"]=>
  string(31) "Predis\Command\TransactionWatch"
  ["UNWATCH"]=>
  string(33) "Predis\Command\TransactionUnwatch"
  ["OBJECT"]=>
  string(27) "Predis\Command\ServerObject"
  ["SLOWLOG"]=>
  string(28) "Predis\Command\ServerSlowlog"
  ["CLIENT"]=>
  string(27) "Predis\Command\ServerClient"
  ["PTTL"]=>
  string(35) "Predis\Command\KeyPreciseTimeToLive"
  ["PEXPIRE"]=>
  string(31) "Predis\Command\KeyPreciseExpire"
  ["PEXPIREAT"]=>
  string(33) "Predis\Command\KeyPreciseExpireAt"
  ["MIGRATE"]=>
  string(25) "Predis\Command\KeyMigrate"
  ["PSETEX"]=>
  string(37) "Predis\Command\StringPreciseSetExpire"
  ["INCRBYFLOAT"]=>
  string(37) "Predis\Command\StringIncrementByFloat"
  ["BITOP"]=>
  string(26) "Predis\Command\StringBitOp"
  ["BITCOUNT"]=>
  string(29) "Predis\Command\StringBitCount"
  ["HINCRBYFLOAT"]=>
  string(35) "Predis\Command\HashIncrementByFloat"
  ["EVAL"]=>
  string(25) "Predis\Command\ServerEval"
  ["EVALSHA"]=>
  string(28) "Predis\Command\ServerEvalSHA"
  ["SCRIPT"]=>
  string(27) "Predis\Command\ServerScript"
  ["TIME"]=>
  string(25) "Predis\Command\ServerTime"
  ["SENTINEL"]=>
  string(29) "Predis\Command\ServerSentinel"
  ["SCAN"]=>
  string(22) "Predis\Command\KeyScan"
  ["BITPOS"]=>
  string(27) "Predis\Command\StringBitPos"
  ["SSCAN"]=>
  string(22) "Predis\Command\SetScan"
  ["ZSCAN"]=>
  string(23) "Predis\Command\ZSetScan"
  ["ZLEXCOUNT"]=>
  string(27) "Predis\Command\ZSetLexCount"
  ["ZRANGEBYLEX"]=>
  string(29) "Predis\Command\ZSetRangeByLex"
  ["ZREMRANGEBYLEX"]=>
  string(35) "Predis\Command\ZSetRemoveRangeByLex"
  ["ZREVRANGEBYLEX"]=>
  string(36) "Predis\Command\ZSetReverseRangeByLex"
  ["HSCAN"]=>
  string(23) "Predis\Command\HashScan"
  ["PUBSUB"]=>
  string(27) "Predis\Command\PubSubPubsub"
  ["PFADD"]=>
  string(29) "Predis\Command\HyperLogLogAdd"
  ["PFCOUNT"]=>
  string(31) "Predis\Command\HyperLogLogCount"
  ["PFMERGE"]=>
  string(31) "Predis\Command\HyperLogLogMerge"
  ["COMMAND"]=>
  string(28) "Predis\Command\ServerCommand"
}

 只要调用KEY就能使用对应的redis方法了,如:

Redis::EXISTS(‘key‘);//对应Predis\Command\KeyExists

  

时间: 2024-10-06 15:21:34

laravel中redis个方法的使用的相关文章

laravel中redis的配置和使用

引入redis composer require predis/predis 会在composer.json中引入最新版本的predis composer update 把下载predis 库加入到vendor,命令执行成功后,如图: 配置redis 说到laravel 中redis 的配置,其实默认项目中已经有了相关配置,只是默认没有使用.默认使用的是: 项目 使用类型 CACHE_DRIVER file SESSION_DRIVER file 添加redis数据库使用 'redis' =>

Laravel中Redis的使用

安装 laravel中使用redis首先需要你通过 Composer 安装 predis/predis 包: composer require predis/predis 配置 redis的配置文件是:config/database.php 'redis' => [ 'client' => 'predis', 'default' => [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PA

laravel中redis队列的使用

一.配置文件 首先我们需要在配置文件中配置默认队列驱动为Redis,队列配置文件是config/queue.php: return [ 'default' => env('QUEUE_DRIVER', 'sync'), 'connections' => [ 'sync' => [ 'driver' => 'sync', ], 'database' => [ 'driver' => 'database', 'table' => 'jobs', 'queue' =&g

关于Laravel中使用response()方法调用json()返回数据unicode编码转换的问题解决

laravel默认返回的json是unicode码,如果为直接可以看的文字,后面要加  ->setEncodingOptions(JSON_UNESCAPED_UNICODE) 不让转成unicode码 return Response::json($data, $this->getStatusCode(), $header)->setEncodingOptions(JSON_UNESCAPED_UNICODE); public function response(){ // 返回json

Laravel框架中的make方法详解

为什么网上已经有这么多的介绍Laravel的执行流程了,Laravel的容器详解了,Laravel的特性了,Laravel的启动过程了之类的文章,我还要来再分享呢? 因为,每个人的思维方式和方向是不一样的,所以就会出现这样的一个场景,当你遇到一个问题在网上寻求答案的时候,有很多文章都解释了你的这个问题,但是你只对其中一篇感兴趣,那是因为作者的思维方式和你的很接近而作者的文笔也可能是你喜欢的那种类型.正因如此,我也来分享一些我在研究Laravel框架时的一些观点和看法,希望给那些和我有类似思维方式

laravel 操作 redis

laravel框架中本身已经存在相应的redis的配置我们在使用的时候只需要更改配置即可,但是在使用的时候一定要注意命名空间的问题,具体可查看config/app.php下面的aliases数组中具体的路径 1.安装启动Redis及依赖包 如果使用的是Homestead虚拟机作为本地开发环境的话,Homestead已经为我们安装好了Redis并开机启动,如果是使用Windows开发环境的话,可参考 这篇文章 安装启动Redis. Redis启动之后,还需要在Laravel项目根目录下运行如下命令

Laravel中利用队列发送邮件的方法示例

https://www.jb51.net/article/121647.htm 本文主要给大家介绍了关于Laravel中队列发送邮件的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍: 批量处理任务的场景在我们开发中是经常使用的,比如邮件群发,消息通知,短信,秒杀等等,我们需要将这个耗时的操作放在队列中来处理,从而大幅度缩短Web请求和相应的时间.下面讲解下Laravel中队列的使用 1.配置文件 config/queue.php ? 1 2 3 4 5 6 7 8 9 1

laravel中HTML::style类出错解决方法

在laravel中,HTML类可以很方便地实现对css文件,js文件等的引用.例如,传统引入方法是: <LINK REL=STYLESHEET TYPE="text/css" HREF="example.css"> 但是用laravel中的HTML类则是: {{ HTML::style('css/example.css') }} {{ HTML::style('css/example.css') }} 可以看出,laravel帮我们省了一些时间. 但是,

Laravel 中通过自定义分页器分页方法实现伪静态分页链接以利于 SEO

我们知道,Laravel 自带的分页器方法包含 simplePaginate 和 paginate 方法,一个返回不带页码的分页链接,另一个返回带页码的分页链接,但是这两种分页链接页码都是以带问号的动态参数形式附加在查询字符串中,形如 https://laravelacademy.org?page=100,但是这种包含动态参数的 URL 格式对 SEO 不友好,我们最好将其转化为 https://laravelacademy.org/page/100 这种不带问号的伪静态分页链接格式,遗憾的是