首页 > 数据库 >webman:用thinkcache访问redis(v1.5.7)

webman:用thinkcache访问redis(v1.5.7)

时间:2023-08-23 09:55:47浏览次数:35  
标签:use webman redis thinkcache url https

一,官方文档地址:

https://www.workerman.net/doc/webman/db/thinkcache.html

二,安装组件

liuhongdi@lhdpc:/data/webman/imageadmin$ composer require -W webman/think-cache

三,配置redis

config/thinkcache.php,按自己的实际情况配置

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 <?php return [     'default' => 'file',     'stores' => [         'file' => [             'type' => 'File',             // 缓存保存目录             'path' => runtime_path() . '/cache/',             // 缓存前缀             'prefix' => '',             // 缓存有效期 0表示永久缓存             'expire' => 0,         ],         'redis' => [             'type' => 'redis',             'host' => '127.0.0.1',             'port' => 6379,             'prefix' => '',             'expire' => 0,         ],     ], ];

四,代码:

app/controller/ImageController.php

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 <?php namespace app\controller;   use support\Request; use app\result\Result; use support\Log; use think\facade\Db; use think\facade\Cache;   use app\model\Comment as CommentModel;   class ImageController {           //图片的详情     public function detail(Request $request)     {          $url = 'https://wx3.sinaimg.cn/mw690/7f8d08b2gy1hh0qy7n57qj213y0u0wj2.jpg';         //set         Cache::store('redis')->set('url',$url,3600);         //get         $content = Cache::store('redis')->get("url");         //返回         $data = ["url"=>$content];         return Result::Success($data);     }

说明:刘宏缔的架构森林—专注it技术的博客,
网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/08/19/webman-yong-thinkcache-fang-wen-redis/
代码: https://github.com/liuhongdi/ 或 https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: [email protected]

五,测试效果

1,查看输出

2,从客户端查看效果:

liuhongdi@lhdpc:/data/webman/imageadmin$ redis-cli
127.0.0.1:6379> get url
"s:65:\"https://wx3.sinaimg.cn/mw690/7f8d08b2gy1hh0qy7n57qj213y0u0wj2.jpg\";"
127.0.0.1:6379> ttl url
(integer) 3504

六,查看webman的版本:

liuhongdi@lhdpc:/data/webman/imageadmin$ composer show workerman/webman-framework
name     : workerman/webman-framework
descrip. : High performance HTTP Service Framework.
keywords : High Performance, http service
versions : * v1.5.7
...

标签:use,webman,redis,thinkcache,url,https
From: https://www.cnblogs.com/architectforest/p/17650333.html

相关文章

  • webman:配置异常处理返回json格式(v1.5.7)
    一,添加一个除0错的异常代码:页面显示效果如图:二,配置:php代码1,config/123456789101112131415161718<?php/** *Thisfileispartofwebman. * *LicensedunderTheMITLicense *Forfullcopyrightandlicenseinformation......
  • redis
    目录1redis介绍2redislinux下安装3redis启动方式3.1最简启动3.2动态参数启动3.3配置文件启动3.4客户端连接命令4redis典型场景5redis通用命令6数据结构和内部编码7redis字符串类型1redis介绍#特性Redis特性(8个)#速度快:10wops(每秒10w读写),数据存在内存中,c语言实现......
  • Redis系列19:LRU内存淘汰算法分析
    Redis系列1:深刻理解高性能Redis的本质Redis系列2:数据持久化提高可用性Redis系列3:高可用之主从架构Redis系列4:高可用之Sentinel(哨兵模式)Redis系列5:深入分析Cluster集群模式追求性能极致:Redis6.0的多线程模型追求性能极致:客户端缓存带来的革命Redis系列8:Bitmap实现亿万级......
  • Redis基础
    什么是Redis?Redis 是一个基于C语言开发的开源数据库,与传统数据库不同的是Redis的数据是存在内存中的,所以他又被叫做内存数据库,他的读写速度非常快,被广泛的应用于缓存方向。并且,Redis存储的是key,value键值对数据。为了满足不同的业务场景,Redis内置了多种数据类型实现(比如String,H......
  • SpringBoot复习:(48)RedisAutoConfiguration自动配置类
    RedisAutoConfiguration类代码如下:可以看到在这个类中配置了2个bean:redisTemplate和stringRedisTemplate.而它通过@EnableConfigurationProperties(RedisProperties.class)注解,把配置文件中配置的Redis相关的信息引入进来了,RedisProperties代码如下:还可以看到RedisAutoConfigu......
  • Spring Cache + Redis 缓存数据使用
    使用SpringCache的好处:1,提供基本的Cache抽象,方便切换各种底层Cache;2,通过注解Cache可以实现类似于事务一样,缓存逻辑透明的应用到我们的业务代码上,且只需要更少的代码就可以完成;3,提供事务回滚时也自动回滚缓存;4,支持比较复杂的缓存逻辑; 以下以自己的某个模块搞得列子1项目......
  • redis的应用场景
    Redis最适合所有数据in-momory的场景,虽然Redis也提供持久化功能,但实际更多的是一个disk-backed的功能,跟传统意义上的持久化有比较大的差别,那么可能大家就会有疑问,似乎Redis更像一个加强版的Memcached,那么何时使用Memcached,何时使用Redis呢? 如果简单地比较Redis与Memcached的区别......
  • Redis 缓存满了怎么办?
    引言Redis缓存使用内存来保存数据,随着需要缓存的数据量越来越大,有限的缓存空间不可避免地会被写满。此时,应该怎么办?本篇文章接下来就来聊聊缓存满了之后的数据淘汰机制。值得注意的是,在Redis中过期策略和内存淘汰策略是两个完全不同的概念。Redis过期策略指的是Redis使......
  • redis centos7下面的安装
    1.使用ftp等工具上传redis-5.0.14.tar.gz到linux服务器2.执行tar-zxvfredis-5.0.14.tar.gz3.进入目录cdredis-5.0.14后执行编译和安装命令make&&makeinstall4.安装后程序路径在/usr/local/bin中,该目录已经设置到了系统环境变量中,可任何时候执行redis-cli:是redis提......
  • 使用redis pipeline提升性能
    前言本篇来介绍一下redispipeline,主要是由于最近一次在帮开发同学review代码的时候,发现对redis有个循环操作可以优化。场景大概是这样的,根据某个uid要从redis查询一批数据,每次大概1000个key左右,如果查得到就返回,否则查db,然后写回缓存。由于每次要查的key比较多,虽然redis单次查询......