连接到 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 ...
随机推荐
- SpringCloud入门使用
目的: 1.springcloud简介 入门案例 2.注册中心eureka springcloud简介 推荐一个springcloud讲解详细的博客:https://blog.csdn.net/qq3 ...
- Java8时间转换
===java8中时间的各种转换(LocalDateTime)=== 1.将LocalDateTime转为自定义的时间格式的字符串 public static String getDateTimeAs ...
- easy ui 常用控件配置
table comboBox 下拉高度 panelHeight:'auto' textBox
- SWD下载k60
转:JTAG各类接口针脚定义,含义及SWD接线方式 IAR设置如下
- BUAA OO 2019 第三单元作业总结
目录 总 JML规格化设计 理论基础 工具链 规格验证 验证代码 代码静态检查 自动生成测试样例 生成结果 错误分析 作业设计 第九次作业 架构 代码实现 第十次作业 架构 代码实现 第十一次作业 架 ...
- PHP 常用数据库操作
1.建立与数据库服务器的连接(前提数据库服务器必须打开) 第一个参数:本地地址 第二个参数:数据库账户 第三个参数:数据库密码 第四个参数:数据库名称 $connection = mysqli_con ...
- error: unknown filesystem; grub rescue
我的电脑是win10+ubumtu双系统 在一次windows更新之后,系统无法进入win10和linux系统,出现如图错误 解决方案1: 大部分中文博客的解决方案:这里有个更加详细的: https: ...
- Ceph分布式存储部署过程
前言: 环境介绍:此次部署系统为Cenots 7 MON.OSD 10.110.180.112 Admin MON.OSD 10.110.180.113 Node1 MON.OSD 10.110.18 ...
- websocket之简易聊天室
一,带昵称的群聊 #!/usr/bin/env python # -*- coding:utf8 -*- import json from flask import Flask, request, r ...
- thinkphp概述
thinkphp框架是一个免费的,开源,快速,简单的面向对象的轻量级PHP开发框架. 了解什么是thinkphp概述,thinkphp项目目录结构,thinkphp的控制器,视图,thinkphp项目 ...