使用composer require 引入predis,宝塔上安装php的redis扩展。 配置密码:requirepass redis密码

application/extra下新建redis.php配置文件。内容如下:

/*

* Redis配置

*/

return [

'host' => '127.0.0.1', // redis 主机ip

'port' => 6379, // redis 端口

'prefix' => 'rdb_', // redis 前缀

'auth' => 'root', // redis 账号

'password' => 'redispwd', // redis 密码

'select' => 0, // 使用哪一个 db,默认为 db0

'timeout' => 0,// redis连接的超时时间

'expire' => 0,//缓存时间

'persistent' => false,// 是否是长连接

];

redis.php配置文件同级目录有队列配置文件queue.php引用了redis配置,如下:

/*

* 消息队列配置

*/

return [

'connector' => 'Redis', // Redis 驱动

'expire' => 60, // 任务的过期时间,默认为60秒; 若要禁用,则设置为 null

'default' => 'paijinhua', // 默认的队列名称

'host' => \think\Config::get("redis.host"), // redis 主机ip

'port' => \think\Config::get("redis.port"), // redis 端口

'password' => \think\Config::get("redis.password"), // redis 密码

'select' => 0, // 使用哪一个 db,默认为 db0

'timeout' => 0, // redis连接的超时时间

'persistent' => false, // 是否是长连接

];

控制器中调用redis方法:

namespace app\admin\controller;

use think\controller;

use Predis\Client;

class Index extends Controller

{

//redis 简单使用

public function index(){

$client = new Client(config('redis'));//实例化

$client->lpush('username', ['lucy','lily']);

$array = $client->get('username');

dump($array);die;

}

}

可使用方法参考源码:

* @method int del(array $keys)

* @method string dump($key)

* @method int exists($key)

* @method int expire($key, $seconds)

* @method int expireat($key, $timestamp)

* @method array keys($pattern)

* @method int move($key, $db)

* @method mixed object($subcommand, $key)

* @method int persist($key)

* @method int pexpire($key, $milliseconds)

* @method int pexpireat($key, $timestamp)

* @method int pttl($key)

* @method string randomkey()

* @method mixed rename($key, $target)

* @method int renamenx($key, $target)

* @method array scan($cursor, array $options = null)

* @method array sort($key, array $options = null)

* @method int ttl($key)

* @method mixed type($key)

* @method int append($key, $value)

* @method int bitcount($key, $start = null, $end = null)

* @method int bitop($operation, $destkey, $key)

* @method array bitfield($key, $subcommand, ...$subcommandArg)

* @method int decr($key)

* @method int decrby($key, $decrement)

* @method string get($key)

* @method int getbit($key, $offset)

* @method string getrange($key, $start, $end)

* @method string getset($key, $value)

* @method int incr($key)

* @method int incrby($key, $increment)

* @method string incrbyfloat($key, $increment)

* @method array mget(array $keys)

* @method mixed mset(array $dictionary)

* @method int msetnx(array $dictionary)

* @method mixed psetex($key, $milliseconds, $value)

* @method mixed set($key, $value, $expireResolution = null, $expireTTL = null, $flag = null)

* @method int setbit($key, $offset, $value)

* @method int setex($key, $seconds, $value)

* @method int setnx($key, $value)

* @method int setrange($key, $offset, $value)

* @method int strlen($key)

* @method int hdel($key, array $fields)

* @method int hexists($key, $field)

* @method string hget($key, $field)

* @method array hgetall($key)

* @method int hincrby($key, $field, $increment)

* @method string hincrbyfloat($key, $field, $increment)

* @method array hkeys($key)

* @method int hlen($key)

* @method array hmget($key, array $fields)

* @method mixed hmset($key, array $dictionary)

* @method array hscan($key, $cursor, array $options = null)

* @method int hset($key, $field, $value)

* @method int hsetnx($key, $field, $value)

* @method array hvals($key)

* @method int hstrlen($key, $field)

* @method array blpop(array $keys, $timeout)

* @method array brpop(array $keys, $timeout)

* @method array brpoplpush($source, $destination, $timeout)

* @method string lindex($key, $index)

* @method int linsert($key, $whence, $pivot, $value)

* @method int llen($key)

* @method string lpop($key)

* @method int lpush($key, array $values)

* @method int lpushx($key, $value)

* @method array lrange($key, $start, $stop)

* @method int lrem($key, $count, $value)

* @method mixed lset($key, $index, $value)

* @method mixed ltrim($key, $start, $stop)

* @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)

* @method int sdiffstore($destination, array $keys)

* @method array sinter(array $keys)

* @method int sinterstore($destination, array $keys)

* @method int sismember($key, $member)

* @method array smembers($key)

* @method int smove($source, $destination, $member)

* @method string spop($key, $count = null)

* @method string srandmember($key, $count = null)

* @method int srem($key, $member)

* @method array sscan($key, $cursor, array $options = null)

* @method array sunion(array $keys)

* @method int sunionstore($destination, array $keys)

* @method int zadd($key, array $membersAndScoresDictionary)

* @method int zcard($key)

* @method string zcount($key, $min, $max)

* @method string zincrby($key, $increment, $member)

* @method int zinterstore($destination, array $keys, array $options = null)

* @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)

* @method int zremrangebyscore($key, $min, $max)

* @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)

* @method string zscore($key, $member)

* @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)

* @method int zremrangebylex($key, $min, $max)

* @method int zlexcount($key, $min, $max)

* @method int pfadd($key, array $elements)

* @method mixed pfmerge($destinationKey, array $sourceKeys)

* @method int pfcount(array $keys)

* @method mixed pubsub($subcommand, $argument)

* @method int publish($channel, $message)

* @method mixed discard()

* @method array exec()

* @method mixed multi()

* @method mixed unwatch()

* @method mixed watch($key)

* @method mixed eval($script, $numkeys, $keyOrArg1 = null, $keyOrArgN = null)

* @method mixed evalsha($script, $numkeys, $keyOrArg1 = null, $keyOrArgN = null)

* @method mixed script($subcommand, $argument = null)

* @method mixed auth($password)

* @method string echo($message)

* @method mixed ping($message = null)

* @method mixed select($database)

* @method mixed bgrewriteaof()

* @method mixed bgsave()

* @method mixed client($subcommand, $argument = null)

* @method mixed config($subcommand, $argument = null)

* @method int dbsize()

* @method mixed flushall()

* @method mixed flushdb()

* @method array info($section = null)

* @method int lastsave()

* @method mixed save()

* @method mixed slaveof($host, $port)

* @method mixed slowlog($subcommand, $argument = null)

* @method array time()

* @method array command()

* @method int geoadd($key, $longitude, $latitude, $member)

* @method array geohash($key, array $members)

* @method array geopos($key, array $members)

* @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)

redis类型 tp5_tp5配置使用redis笔记!相关推荐

  1. Redis:Redis配置文件相关配置、Redis的持久化

    目录: (1)Redis的配置文件 (2)常规配置 (3)安全配置 (4)Redis的持久化策略RDB (5)Redis的持久化策略AOF (6)Redis的持久化 (1)Redis的配置文件 red ...

  2. NAT的类型与配置(学习笔记)

    一.NAT的类型 1.静态NAT 静态NAT是指在路由器中,将内网IP地址固定地转换为外网IP地址,通常应用在允许外网用户访问内网服务器的场景中. 2.动态NAT 动态NAT指将一个内部IP地址转换为 ...

  3. Redis入门之Redis安装、配置及常用指令

    Redis入门 NoSQL 引言 为什么使用 NoSQL? NoSQL 的四大分类(键值.列存储.文档.图形) NoSQL 应用场景 Redis 介绍 Redis 安装 与 配置 Redis 启动服务 ...

  4. springBoot整合redis集群配置

    最近发现这篇博客阅读量比较大,今天特意抽空创建了一个可运行的开源项目. 项目的代码和之前的博客内容相比,做了些优化,请大家参考项目源码. 开源项目源码: springboot-redis-cluste ...

  5. 跟着狂神学Redis(NoSql+环境配置+五大数据类型+三种特殊类型+Hyperloglog+Bitmap+事务+Jedis+SpringBoot整合+Redis持久化+...)

    跟着狂神学Redis 狂神聊Redis 学习方式:不是为了面试和工作学习!仅仅是为了兴趣!兴趣才是最好的老师! 基本的理论先学习,然后将知识融汇贯通! 狂神的Redis课程安排: nosql 讲解 阿 ...

  6. Redis配置文件基本配置(笔记)

    解析配置文件 redis.conf常用配置 INCLUDES include /path/to/local/conf 可以包含引用其他redis配置文件 GENERAL 通用 1.pidfile /v ...

  7. 【CJY学习笔记】Redis容器的配置

    1.创建Redis的docker容器 Docker 创建 Redis 容器命令 docker run \ -d \ --name redis \ -p 6379:6379 \ --restart un ...

  8. Redis实现分布式限流(学习笔记

    Redis实现分布式限流(学习笔记2022.07.09) 前言: 以下实现都是基于: spring-boot-starter-web + spring-boot-starter-data-redis ...

  9. 《redis设计与实现》 读书笔记

    <redis设计与实现> 作者:黄健宏 读书笔记 一.前言 什么是redis: Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数 ...

  10. redis学习(1)之redis基础和配置主从

    redis介绍 redis介绍 为什么会出现redis呢? redis特性 速度快 基于key-value 丰富的功能 简单稳定 支持的语言多 持久化 主从复制 redis应用场景 缓存 排行榜系统 ...

最新文章

  1. [导入]SQL中的临时表和表变量
  2. 转:Chrome渲染分析之Timeline工具的使用
  3. Flash网站流量统计的方法
  4. idhttp.post方式 调用datasnap rest 远程方法
  5. python selenium对象怎么序列化_python selenium爬取斗鱼
  6. 苹果系统怎么降低版本_海信电视系统版本太低怎么升级?
  7. 利用Octave解线性方程组
  8. 源码--常用的人脸识别数据库
  9. linux后台执行脚本(产生日志和不产生日志)(大神请留言)
  10. Python获取矢量文件属性表字段及类型
  11. 3D建模与处理软件简介 刘利刚 中国科技大学
  12. 腾讯云API弹性公网IP踩坑
  13. 微信支付:请求参数与订单信息不一致
  14. SVD求解线性方程组
  15. 只有手机号或者身份证能查出来绑定QQ号码?大神请赐教
  16. 路由器与交换机配置测试题及答案
  17. snidel 2014春夏新品 画册款切换材质连衣裙
  18. “华为区块链白皮书”重磅发布(附下载链接)
  19. 蝴蝶效应,鳄鱼法则,罗森塔尔效应,帕金森定律,手表定律,破窗理论,晕轮效应 ,霍桑效应,二八定律,木桶理论,马太效应,踢猫效应…………
  20. c语言查找偶数,c-查找数字是偶数还是奇数的最快方法是什么?

热门文章

  1. C#中使用Log4Net记录日志
  2. java封装的概念学习笔记
  3. iOS学习之单例模式
  4. 汇编语言相关图书推荐
  5. Unity3D研究院之2D游戏开发制作原理(二十一) 【转】
  6. 自定义 feign 调用实现 hystrix 超时、异常熔断
  7. Java内存模型基础知识
  8. 面试题之TCP三次握手和四次挥手详解
  9. mysql把A表的数据插入到B表
  10. Linux 进程间通信 无名管道(pipe)