zoukankan      html  css  js  c++  java
  • tp5.1 使用redis

    如题,首先设置redis服务器连接配置,在/config/cache文件中

    return [
        //缓存配置为复合类型
        'type' => 'complex',
        'default' => [
            'type' => 'file',
            'expire' => 0,
            //'缓存前缀
            'prefix' => '',
            'path' => '../runtime/cache',
        ],
        'redis' => [
            'type' => 'redis',
            'host' => '127.0.0.1',
            'port' => '6379',
            'expire' => 0,
            'prefix' => ''
        ]
    ];

    在控制器中 use thinkfacadeCache;

    简单操作存取字符串

    $redis = new Redis();
    $redis->set('name','value');
    $name = $redis->get('name');

    其他如list、hash、set、sorted set使用

    $redis = new Redis();
    $list = $redis->handler()->lrange('list01','0','-1');

    连接其他服务器的redis。注释:连接服务器的redis配置文件中要bind 0.0.0.0 我绑了操作的ip地址但是不管用,也没认真研究。当然了,如果你连得redis是从服务器的话,那么只能读,不能写。否则会报错

    $option = [
                'type' => 'redis',
                'host' => '192.168.1.103',
                'port' => '6379',
                'timeout' => '0',
                'expire' => '',
                'prefix' => ''
            ];
    Cache::connect($option)->set('name','value',3600);
    Cache::connect($option)->handler()->rpush('k1','v1','v2','v3');
  • 相关阅读:
    算法题之丢手绢问题
    Java接口成员变量和方法默认修饰符
    清空select下拉框的方法
    Java基础数据类型的默认值
    JVM内存区域划分
    Java中匿名内部类
    Java值传递
    部署web Service到tomcat
    Tomcat环境下配置数据源
    遇到和需要解决的问题
  • 原文地址:https://www.cnblogs.com/dayin1/p/14014807.html
Copyright © 2011-2022 走看看