1. 云栖社区>
  2. PHP教程>
  3. 正文

基于centos的redis与php

作者:用户 来源:互联网 时间:2017-12-01 09:30:42

phpcentosredis基于

基于centos的redis与php - 摘要: 本文讲的是基于centos的redis与php, 基于centos的redis与php 这是一个简要操作日记。。。 1、安装 安装phpize。phpize用于生成configure文件,为php扩展模块的编译生成配置文件。 yum install php-devel -y 安装red

基于centos的redis与php

这是一个简要操作日记。。。

1、安装

安装phpize。phpize用于生成configure文件,为php扩展模块的编译生成配置文件。

yum install php-devel  -y

安装redis

yum install redis -y

从源码安装phpredis

wget https://github.com/nicolasff/phpredis/archive/master.zipunzip master.zipcd phpredis-master/phpize./configuremake && make install && make test

配置php添加扩展

find / -name php.inivi /etc/php.iniGextension="redis.so":wqservice httpd restart   # or reboot
测试phpredis
[[email protected] ~]# php -aInteractive shellphp > $redis= new Redis();php > $redis->connect('127.0.0.1',6379);php > $redis->set("pageview",10);php > $k=$redis->get("pageview");php > echo $k;10

2、简单操作

redis

启动redis服务

加$令其后台执行,加()表示在子shell中执行命令,纵然当前shell退出,此服务进程不会被kill。

(redis-server&)
加入开机自启动脚本

注意>表示写文件会清空原有内容,>>表示追加到文件末尾行。

echo "(redis-server&)" >>/etc/rc.local
启动redis命令行
redis-cli       #进入redis命令行模式
退出redis命令行
quit

注意不要用shutdown。shutdown命令会关闭当前redis服务,也即kill掉redis服务进程

dbsize                      #获取记录条数set pageview 0              #设置k:vget pageview                #获取k:vdel pageview                #删除k:vsave                        #保存help @generic               #DEL key [key ...]summary: Delete a keysince: 1.0.0DUMP keysummary: Return a serialized version of the value stored at the specified key.since: 2.6.0EXISTS key [key ...]summary: Determine if a key existssince: 1.0.0EXPIRE key secondssummary: Set a key's time to live in secondssince: 1.0.0EXPIREAT key timestampsummary: Set the expiration for a key as a UNIX timestampsince: 1.2.0KEYS patternsummary: Find all keys matching the given patternsince: 1.0.0MIGRATE host port key| destination-db timeout [COPY] [REPLACE] [KEYS key]summary: Atomically transfer a key from a Redis instance to another one.since: 2.6.0MOVE key dbsummary: Move a key to another databasesince: 1.0.0OBJECT subcommand [arguments [arguments ...]]summary: Inspect the internals of Redis objectssince: 2.2.3PERSIST keysummary: Remove the expiration from a keysince: 2.2.0PEXPIRE key millisecondssummary: Set a key's time to live in millisecondssince: 2.6.0PEXPIREAT key milliseconds-timestampsummary: Set the expiration for a key as a UNIX timestamp specified in millisecondssince: 2.6.0PTTL keysummary: Get the time to live for a key in millisecondssince: 2.6.0RANDOMKEY -summary: Return a random key from the keyspacesince: 1.0.0RENAME key newkeysummary: Rename a keysince: 1.0.0RENAMENX key newkeysummary: Rename a key, only if the new key does not existsince: 1.0.0RESTORE key ttl serialized-value [REPLACE]summary: Create a key using the provided serialized value, previously obtained using DUMP.since: 2.6.0SCAN cursor [MATCH pattern] [COUNT count]summary: Incrementally iterate the keys spacesince: 2.8.0SORT key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern ...]] [ASC|DESC] [ALPHA] [STORE                                                                           destination]summary: Sort the elements in a list, set or sorted setsince: 1.0.0TTL keysummary: Get the time to live for a keysince: 1.0.0TYPE keysummary: Determine the type stored at keysince: 1.0.0WAIT numslaves timeoutsummary: Wait for the synchronous replication of all the write commands sent in the context of the cu                                                                          rrent connectionsince: 3.0.0GEORADIUSBYMEMBER_RO key arg arg arg arg ...options...summary: Help not availablesince: not knownREPLCONF arg ...options...summary: Help not availablesince: not knownSUBSTR key arg arg argsummary: Help not availablesince: not knownPSYNC arg arg argsummary: Help not availablesince: not knownTOUCH key arg ...options...summary: Help not availablesince: not knownPFSELFTEST argsummary: Help not availablesince: not knownGEORADIUS_RO key arg arg arg arg arg ...options...summary: Help not availablesince: not knownPOST arg ...options...summary: Help not availablesince: not knownLATENCY arg arg ...options...summary: Help not availablesince: not knownHOST: arg ...options...summary: Help not availablesince: not knownASKING argsummary: Help not availablesince: not knownRESTORE-ASKING key arg arg arg ...options...summary: Help not availablesince: not knownPFDEBUG arg arg arg ...options...summary: Help not availablesince: not known

Then you know how to do IT.

以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索php , centos , redis 基于 ,以便于您获取更多的相关知识。

弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率

40+云计算产品,6个月免费体验

稳定可靠、可弹性伸缩的在线数据库服务,全球最受欢迎的开源数据库之一

云服务器9.9元/月,大学必备