基于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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值