连接到 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. (四)pdf的构成之文件体(树图)

    pdf的文件体类似于一个大树 有个根对象(catalog),该对象中保存着PDF的很多基本信息,并通过间接引用,辐射到所有的间接对象. (下图是大概的树形状)

  2. centos7+ 在线yum安装docker-ce

    yum install -y yum-utils   //扩展yum功能 yum-config-manager --add-repo http://mirrors.aliyun.com/docker- ...

  3. Microsoft.AspNet.Identity 自定义使用现有的表—登录实现,aspnet.identity

    Microsoft.AspNet.Identity是微软新引入的一种membership框架,也是微软Owin标准的一个实现.Microsoft.AspNet.Identity.EntityFrame ...

  4. Jupyter Notebook的配置(密码端口+远程登陆+nbextension)

    1 生成配置文件 linux和mac系统打开终端 windows系统打开anaconda自带的终端 jupyter notebook --generate-config 此时系统会生成 ~/.jupy ...

  5. C#特性的学习(一)

    1.预定定义特性之一:AttributeUsage AttributeUsage有三个属性: 第一个属性:ValidOn 规定特性可被放置的语言元素,默认是AttributeTargets.All.

  6. python-django中使用事务以及小坑

    django中使用事务 一.导入事务模块 from django.db import transaction 二.对相应的业务进行事务操作 方式一:为整个函数进行事务操作 @transaction.a ...

  7. aiohttp你不知道的异步操作网络请求

    aiohttp支持异步操作的网络请求的模块 1.一个简单异步协程爬取 read() text(encoding=编码) 比如:await r.text(encoding="utf-8&quo ...

  8. npm 安装卸载模块 & ionic插件安装与卸载

    npm安装模块 npm install xxx利用 npm 安装xxx模块到当前命令行所在目录 npm install -g xxx利用npm安装全局模块xxx 本地安装时将模块写入package.j ...

  9. ANE打包工具使用视频教程 -- 梦宇技术 @极客学院

    来源:http://xtiqin.blog.163.com/blog/static/17017217920133584934827/ ANE打包工具使用视频教程 2013-04-05 08:49:34 ...

  10. net webapi jwt验证授权

    参考文章:https://blog.csdn.net/liwan09/article/details/83820651