基于centos的redis与php

前端之家收集整理的这篇文章主要介绍了基于centos的redis与php前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

基于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.zip
unzip master.zip
cd PHPredis-master/
PHPize
./configure
make && make install && make test

配置PHP添加扩展

find / -name PHP.ini
vi /etc/PHP.ini
G
extension="redis.so"
:wq
service httpd restart   # or reboot
测试PHPredis
[root@nfvbfqi9 ~]# PHP -a
Interactive shell


PHP > $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:v
get pageview                #获取k:v
del pageview                #删除k:v
save                        #保存
help @generic               #


DEL key [key ...]
summary: Delete a key
since: 1.0.0

DUMP key
summary: Return a serialized version of the value stored at the specified key.
since: 2.6.0

EXISTS key [key ...]
summary: Determine if a key exists
since: 1.0.0

EXPIRE key seconds
summary: Set a key's time to live in seconds
since: 1.0.0

EXPIREAT key timestamp
summary: Set the expiration for a key as a UNIX timestamp
since: 1.2.0

KEYS pattern
summary: Find all keys matching the given pattern
since: 1.0.0

MIGRATE 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.0

MOVE key db
summary: Move a key to another database
since: 1.0.0

OBJECT subcommand [arguments [arguments ...]]
summary: Inspect the internals of Redis objects
since: 2.2.3

PERSIST key
summary: Remove the expiration from a key
since: 2.2.0

PEXPIRE key milliseconds
summary: Set a key's time to live in milliseconds
since: 2.6.0

PEXPIREAT key milliseconds-timestamp
summary: Set the expiration for a key as a UNIX timestamp specified in milliseconds
since: 2.6.0

PTTL key
summary: Get the time to live for a key in milliseconds
since: 2.6.0

RANDOMKEY -
summary: Return a random key from the keyspace
since: 1.0.0

RENAME key newkey
summary: Rename a key
since: 1.0.0

RENAMENX key newkey
summary: Rename a key,only if the new key does not exist
since: 1.0.0

RESTORE key ttl serialized-value [REPLACE]
summary: Create a key using the provided serialized value,prevIoUsly obtained using DUMP.
since: 2.6.0

SCAN cursor [MATCH pattern] [COUNT count]
summary: Incrementally iterate the keys space
since: 2.8.0

SORT 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 set
since: 1.0.0

TTL key
summary: Get the time to live for a key
since: 1.0.0

TYPE key
summary: Determine the type stored at key
since: 1.0.0

WAIT numslaves timeout
summary: Wait for the synchronous replication of all the write commands sent in the context of the cu                                                                          rrent connection
since: 3.0.0

GEORADIUSBYMEMBER_RO key arg arg arg arg ...options...
summary: Help not available
since: not known

REPLCONF arg ...options...
summary: Help not available
since: not known

SUBSTR key arg arg arg
summary: Help not available
since: not known

PSYNC arg arg arg
summary: Help not available
since: not known

TOUCH key arg ...options...
summary: Help not available
since: not known

PFSELFTEST arg
summary: Help not available
since: not known

GEORADIUS_RO key arg arg arg arg arg ...options...
summary: Help not available
since: not known

POST arg ...options...
summary: Help not available
since: not known

LATENCY arg arg ...options...
summary: Help not available
since: not known

HOST: arg ...options...
summary: Help not available
since: not known

ASKING arg
summary: Help not available
since: not known

RESTORE-ASKING key arg arg arg ...options...
summary: Help not available
since: not known

PFDEBUG arg arg arg ...options...
summary: Help not available
since: not known

Then you know how to do IT.

原文链接:https://www.f2er.com/centos/375943.html

猜你在找的CentOS相关文章