连接到 redis 服务

<?php
//连接本地的 Redis 服务
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
echo "Connection to server sucessfully";
//查看服务是否运行
echo "Server is running: " . $redis->ping();
?>

执行脚本,输出结果为:

Connection to server sucessfully
Server is running: PONG

Redis PHP String(字符串) 实例

<?php
//连接本地的 Redis 服务
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
echo "Connection to server sucessfully";
//设置 redis 字符串数据
$redis->set("tutorial-name", "Redis tutorial");
// 获取存储的数据并输出
echo "Stored string in redis:: " . $redis->get("tutorial-name");
?>

执行脚本,输出结果为:

Connection to server sucessfully
Stored string in redis:: Redis tutorial

Redis PHP List(列表) 实例

<?php
//连接本地的 Redis 服务
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
echo "Connection to server sucessfully<br/>";
//存储数据到列表中
$redis->lpush("tutorial-list", "Redis");
$redis->lpush("tutorial-list", "Mongodb");
$redis->lpush("tutorial-list", "Mysql");
// 获取存储的数据并输出
$arList = $redis->lrange("tutorial-list", 0 ,5);
echo "Stored string in redis------<br/>";
echo"压入队列:<br/>";var_export($arList);
echo "<br/>";
// 获取列表长度
$llen = $redis->llen('tutorial-list');
while ($llen){
echo "弹出数据:".$redis->lpop('tutorial-list')."<br/>";
$llen = $redis->llen('tutorial-list');
}
// 获取存储的数据并输出
$arList = $redis->lrange("tutorial-list", 0 ,5);
echo "Stored string in redis------<br/>";
var_export($arList);
?>

执行脚本,输出结果为:

Connection to server sucessfully
Stored string in redis------
压入队列:
array ( 0 => 'Mysql', 1 => 'Mongodb', 2 => 'Redis',)
弹出数据:Mysql
弹出数据:Mongodb
弹出数据:Redis
Stored string in redis------
array ()        

Redis PHP Keys 实例

<?php
//连接本地的 Redis 服务
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
echo "Connection to server sucessfully";
// 获取数据并输出
$arList = $redis->keys("*");
echo "Stored keys in redis:: ";
print_r($arList);
?>

执行脚本,输出结果为:

Connection to server sucessfully
Stored string in redis::
tutorial-name
tutorial-list

连接到 redis 服务的更多相关文章

  1. Codis——分布式Redis服务的解决方案

    Codis——分布式Redis服务的解决方案 之前介绍过的 Twemproxy 是一种Redis代理,但它不支持集群的动态伸缩,而codis则支持动态的增减Redis节点:另外,官方的redis 3. ...

  2. docker 中运行 redis 服务

    先使用 dockerfile 创建一个 redis 容器 FROM ubuntu:latest RUN apt-get update RUN apt-get -y install redis-serv ...

  3. redis服务以及phpredis扩展的安装

    一.下载软件包 下载redis wget http://download.redis.io/releases/redis-3.0.7.tar.gz 下载redis的php扩展 wget http:// ...

  4. Redis服务之常用配置(一)

    上一篇博客聊了下redis的简介以及redis的yum安装和源码编译安装需要注意到问题,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/13378138.html ...

  5. Redis服务之常用配置(二)

    上一篇博客我们聊了下redis的INCLUDE.NETWORK.GENERAL配置段相关配置和说明,回顾请参考:https://www.cnblogs.com/qiuhom-1874/p/133831 ...

  6. Redis服务之Redis Cluster

    在上一篇博客中我们聊到了redis的高可用组件sentinel的相关配置,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/13429776.html:sentin ...

  7. 【Azure Redis 缓存】Azure Cache for Redis服务中,除开放端口6379,6380外,对13000,13001,15000,15001 为什么也是开放的呢?

    问题描述 在使用安全检测工具对Azure Redis服务端口进行扫描时,发现Redis对外开放了13001, 13000,15000,15001端口.非常不理解的是,在门户上只开放了6379,6380 ...

  8. 【Azure Redis 缓存】由Azure Redis是否可以自定义密码而引申出Azure PaaS的Redis服务是否可以和自建的Redis进行主从配置呢?

    问题描述 在自建的Redis服务中,可以通过 config set requirepass <Password> 设置Redis的登录密码,然后使用auth 命令输入密码.操作命令如下: ...

  9. 黑客是如何通过开放的Redis服务入侵服务器的

    0x00 简要说明 百度百科:Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-V ...

随机推荐

  1. CF449E Jzzhu and Squares

    题目大意:有一个$n\times m$的方格图,求其中所有的格点正方形完整包含的小方格个数,多组询问.$n,m\leqslant 10^6$ 题解:令$n\leqslant m$.有一个显然的式子:$ ...

  2. ActiveX的AssemblyInof.cs文件 IObjectSafety  接口

    ActiveX的AssemblyInof.cs文件 IObjectSafety  接口 [Guid("D4176A17-2A33-4903-8F37-9EBDD7CAFFD3"), ...

  3. 利用脚本一键执行脚本,创建SharePoint文档库列表

    SharePoint基于文档库和列表上进行二次开发,生成新的文档库和新的列表模板 通过新的模板,创建新的文档库与列表 --定义site对象$site = SPSite http://dvt176/si ...

  4. Java 日期时间与unix时间戳之间转换

    日期时间  <-->  时间戳 java.time 包提供的新的日期和时间API LocalDateTime: 本地日期时间类 ZoneId: 时区类 ZonedDateTime: 带时区 ...

  5. 【洛谷 P3966】 [TJOI2013]单词(AC自动机,差分)

    把单词连起来,中间插入间隔符,同 #include <cstdio> #include <queue> #include <cstring> using names ...

  6. 基于【 springBoot +springCloud+vue 项目】一 || 后端搭建

    缘起 本项目是基于之前学习的一个Dubbo+SSM分布式项目进行升级,基于此项目对前后端分离项目.微服务项目进一步深入学习.之前学习了vue.springBoot.springCloud后,没有进行更 ...

  7. JavaScript函数参数传递

    Hello,今天和大家分享下JS中的一个基本概念:函数参数传递! 先来看看一个DEMO var str="hello world"; function func(s){ s=&qu ...

  8. Mysql学习之事务的隔离性

    今天咱们说说事务,相信大家都知道事务的 ACID (Atomicity.Consistency.Isolation.Durability,即原子性.一致性.隔离性.持久性). 原子性:表示一个事务不可 ...

  9. Linux命令——df

    参考:12 Useful “df” Commands to Check Disk Space in Linux 简介 df用于查看文件系统磁盘空间使用情况. df 读取的数据几乎都是针对一整个文件系统 ...

  10. React官方中文文档【安装】

    https://reactjs.org/docs/getting-started.html  //React官方文档地址 1.入门 此页面是React文档和相关资源的概述. React是一个用于构建用 ...