连接到 redis 服务
连接到 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 服务的更多相关文章
- Codis——分布式Redis服务的解决方案
Codis——分布式Redis服务的解决方案 之前介绍过的 Twemproxy 是一种Redis代理,但它不支持集群的动态伸缩,而codis则支持动态的增减Redis节点:另外,官方的redis 3. ...
- docker 中运行 redis 服务
先使用 dockerfile 创建一个 redis 容器 FROM ubuntu:latest RUN apt-get update RUN apt-get -y install redis-serv ...
- redis服务以及phpredis扩展的安装
一.下载软件包 下载redis wget http://download.redis.io/releases/redis-3.0.7.tar.gz 下载redis的php扩展 wget http:// ...
- Redis服务之常用配置(一)
上一篇博客聊了下redis的简介以及redis的yum安装和源码编译安装需要注意到问题,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/13378138.html ...
- Redis服务之常用配置(二)
上一篇博客我们聊了下redis的INCLUDE.NETWORK.GENERAL配置段相关配置和说明,回顾请参考:https://www.cnblogs.com/qiuhom-1874/p/133831 ...
- Redis服务之Redis Cluster
在上一篇博客中我们聊到了redis的高可用组件sentinel的相关配置,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/13429776.html:sentin ...
- 【Azure Redis 缓存】Azure Cache for Redis服务中,除开放端口6379,6380外,对13000,13001,15000,15001 为什么也是开放的呢?
问题描述 在使用安全检测工具对Azure Redis服务端口进行扫描时,发现Redis对外开放了13001, 13000,15000,15001端口.非常不理解的是,在门户上只开放了6379,6380 ...
- 【Azure Redis 缓存】由Azure Redis是否可以自定义密码而引申出Azure PaaS的Redis服务是否可以和自建的Redis进行主从配置呢?
问题描述 在自建的Redis服务中,可以通过 config set requirepass <Password> 设置Redis的登录密码,然后使用auth 命令输入密码.操作命令如下: ...
- 黑客是如何通过开放的Redis服务入侵服务器的
0x00 简要说明 百度百科:Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-V ...
随机推荐
- vue 仿写微信公众号自定义菜单
先看效果图 代码参考 <template> <div> <!-- 公众号设置 --> <el-col :span="24" style=& ...
- PB 奇葩BUG
1. 在数据窗口的Edit 中选则CHeckBox 后,必须给默认值,否则会导致数据保存不了,也无提示. 2.当使用数据窗口的 setfile()函数时 如果 条件中有两个LIKE 则会报错,一个LI ...
- ASP.NET WebAPI 连接数据库
ASP.NET Web API 是一种框架,用于轻松构建可以访问多种客户端(包括浏览器和移动设备)的 HTTP 服务. ASP.NET Web API 是一种用于在 .NET Framework 上构 ...
- Java身份证处理工具
身份证处理工具 /** * <html> * <body> * <P> Copyright 1994 JsonInternational</p> * & ...
- ESP8266 智能家居简单实现
本文转自CSDN,地址 https://blog.csdn.net/jsagacity/article/details/78531819 全文如下 : 前段时间,公司利用 ESP8266 这个WiFi ...
- 【开发工具】- Xshell工具的下载和安装
下载地址:https://www.netsarang.com/zh/free-for-home-school/ Xshell 是一个强大的安全终端模拟软件,它支持SSH1, SSH2, 以及Micro ...
- JavaScript 自己写一个 replaceAll() 函数
JavaScript 的 replace() 方法可以在字符串中用一些字符替换另一些字符,或替换一个与正则表达式匹配的子串. 但是,只输入字符串的话,仅替换第一个字符,当然也可以用正则表达式来进行 ...
- mysql57重新安装后无法再次启动mysql57服务“本地计算机上的MySQL服务启动后停止。某些服务在未由其他服务或程序使用时将自动。”--解决方法
本地计算机上的MySQL服务启动后停止.某些服务在未由其他服务或程序使用时将自动. (win10,mysql5.7+) 解决方法: 第一步:查看MySQL57安装路径 只要在programData路径 ...
- java 懒汉式、饿汉式单例模式 不含多线程的情况
//饿汉式 提前生成了单例对象 class Singleton{ private static final Singleton instance=new Singleton(); private Si ...
- 微信小程序API~用户信息
UserInfo 用户信息 属性 string nickName 用户昵称 string avatarUrl 用户头像图片的 URL.URL 最后一个数值代表正方形头像大小(有 0.46.64.96. ...