laravel从入门到精通之redis配置和使用

1:首先我们先使用  Composer 安装依赖:

$ composer require "predis/predis:~1.0" 

2:确保运行环境下已安装redis

具体安装可查看:https://blog.csdn.net/qq_29099209/article/details/79787067

3:操作说明

3.1:实例化Redis

use Illuminate\Support\Facades\Redis;

$redis = new Redis();

3.2:设置key和value的值

$redis::set('name', 'wjh');

3.3获取有关指定键的值

$redis::get('name')

函数hu汇总,可根据redis 函数来找laravel中对应的方法使用

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"
}

 

你可能感兴趣的:(PHP)