• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

PHP redis key

武飞扬头像
微齐天大圣.
帮助1

        连接redis

        $redis = new \Redis();
        $redis->connect('127.0.0.1','6379');
        $redis->auth('123456');// 密码
        $redis->select(1);// 指定数据库

        $key='str_set11';
        // 设置key
        /*$str_set=$redis->set($key,'hello world');
        if(!$str_set){
           $redis->set($key,'hello world');
        }*/
        // 获取key值
        // $str=$redis->get($key);
        
        // 删除key
        // $str=$redis->del($key);
        
        // 序列化key
        // $str=$redis->dump($key);
        
        // 判断指定key是否存在
        // $str=$redis->exists($key);
        
        // 设置key过期时间(秒)
        // $str=$redis->expire($key, 5);
        
        // 设置key到指定时间过期
        // $str=$redis->expireat($key, strtotime('2022-11-28 09:44:30'));
        
        // 设置key过期时间(毫秒)
        // $str=$redis->pexpire($key, 10000);
        
        // 设置key到指定时间过期(毫秒)
        // $str=$redis->pexpireat($key, strtotime('2022-11-28 09:44:00'));
        
        // 搜索key
        // $str=$redis->keys('str*');
        
        // 移动key到指定数据库
        // $str=$redis->move($key,2);
        
        // 取消key的过期时间
        // $str=$redis->persist($key);
        
        // 获取key的剩余过期时间->pexpire
        // $str=$redis->pttl($key);
        
        // 获取key的剩余过期时间->expire
        // $str=$redis->ttl($key);
        
        // 随机返回一个key
        // $str=$redis->randomkey($key);
        
        // 修改key的名称
        // $str=$redis->rename($key,'str_set11');
        
        // 修改key的名称,只有参数2不存在时才成功
        // $str=$redis->renamenx($key,'str_set12');
        
        


        var_dump($str);

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgffgff
系列文章
更多 icon
同类精品
更多 icon
继续加载