搭建Redis服务器
在主机redis64运行redis服务
[root@redis64 ~]
[root@redis64 ~]
[root@redis64 ~]
LISTEN 0 128 127.0.0.1:6379 0.0.0.0:* users:(("redis-server",pid=1114,fd=6))
[root@redis64 ~]
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set school nsd2306
OK
127.0.0.1:6379> get school
"nsd2306"
127.0.0.1:6379> exit
修改服务运行参数
[root@redis64 ~]
bind 192.168.88.64
port 6364
requirepass tye
[root@redis64 ~]
LISTEN 0 128 192.168.88.64:6364 0.0.0.0:* users:(("redis-server",pid=1183,fd=6))
[root@redis64 ~]
192.168.88.64:6364> ping
(error) NOAUTH Authentication required.
192.168.88.64:6364> auth tye
OK
192.168.88.64:6364> ping
PONG
192.168.88.64:6364> keys *
1) "school"
192.168.88.64:6364> get school
"nsd2306"
常用命令
- mset mget keys type
- exists ttl expire move select
- del flushdb flushall
[root@redis64 ~]
192.168.88.64:6364> mset name plj age 80 class nsd2023
OK
192.168.88.64:6364> keys *
1) "school"
2) "age"
3) "name"
4) "class"
192.168.88.64:6364> mget name age
1) "plj"
2) "80"
* 匹配所有变量名
? 一个字符
192.168.88.64:6364> keys *
1) "school"
2) "age"
3) "name"
4) "class"
192.168.88.64:6364> keys p?
(empty list or set)
192.168.88.64:6364> keys a??
1) "age"
192.168.88.64:6364> select 1
OK
192.168.88.64:6364[1]> select 16
(error) ERR DB index is out of range
192.168.88.64:6364[1]> select 15
OK
192.168.88.64:6364> move age 1
(integer) 1
192.168.88.64:6364> keys *
1) "school"
2) "name"
3) "class"
192.168.88.64:6364> select 1
OK
192.168.88.64:6364[1]> keys *
1) "age"
192.168.88.64:6364> exists name
(integer) 1
192.168.88.64:6364> get name
"plj"
192.168.88.64:6364> set name bob
OK
192.168.88.64:6364> get name
"bob"
192.168.88.64:6364> set sex girl
OK
192.168.88.64:6364> ttl sex
(integer) -1
192.168.88.64:6364> expire sex 15
(integer) 1
192.168.88.64:6364> ttl sex
(integer) 10
192.168.88.64:6364> ttl sex
(integer) 5
192.168.88.64:6364> ttl sex
(integer) -2
192.168.88.64:6364> keys sex
(empty list or set)
192.168.88.64:6364> set x 99
OK
192.168.88.64:6364> mset y 108
OK
192.168.88.64:6364> type x
string
192.168.88.64:6364> type y
string
192.168.88.64:6364> lpush tea nb wk zzg plj lx
(integer) 5
192.168.88.64:6364> type tea
list
192.168.88.64:6364> keys *
1) "tea"
2) "x"
3) "class"
4) "school"
5) "name"
6) "y"
192.168.88.64:6364> del x y
(integer) 2
192.168.88.64:6364> keys *
1) "tea"
2) "class"
3) "school"
4) "name"
192.168.88.64:6364> keys *
1) "tea"
2) "class"
3) "school"
4) "name"
192.168.88.64:6364> flushdb
OK
192.168.88.64:6364> keys *
(empty list or set)
192.168.88.64:6364> select 1
OK
192.168.88.64:6364[1]> keys *
1) "age"
192.168.88.64:6364[1]> flushall
OK
192.168.88.64:6364[1]> keys *
(empty list or set)
部署LNP+Redis
1.在主机192.168.88.64部署LNP 环境
2.配置PHP支持redis
3.编写网站脚本,把数据存储到本机的内存里
[root@redis64 ~]
[root@redis64 ~]
[root@redis64 nginx-1.22.1]
[root@redis64 nginx-1.22.1]
[root@redis64 nginx-1.22.1]
conf html logs sbin
[root@redis64 nginx-1.22.1]
65 location ~ .php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69
70 include fastcgi.conf;
71 }
[root@redis64 nginx-1.22.1]
[root@redis64 nginx-1.22.1]
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@redis64 nginx-1.22.1]
[root@redis64 nginx-1.22.1]
LISTEN 0 128 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=7679,fd=6),("nginx",pid=7678,fd=6))
[root@redis64 nginx-1.22.1]
listen = 127.0.0.1:9000
[root@redis64 nginx-1.22.1]
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[root@redis64 nginx-1.22.1]
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:* users:(("php-fpm",pid=7751,fd=8),("php-fpm",pid=7750,fd=8),("php-fpm",pid=7749,fd=8),("php-fpm",pid=7748,fd=8),("php-fpm",pid=7747,fd=8),("php-fpm",pid=7746,fd=6))
[root@redis64 nginx-1.22.1]
<?php
phpinfo();
?>
[root@redis64 ~]
[root@redis64 pub]
[root@redis64 redis-4.3.0]
Configuring for:
PHP Api Version: 20170718
Zend Module Api No: 20170718
Zend Extension Api No: 320170718
[root@redis64 redis-4.3.0]
[root@redis64 redis-4.3.0]
[root@redis64 redis-4.3.0]
extension_dir = "/usr/lib64/php/modules/"
extension = "redis.so"
[root@redis64 redis-4.3.0]
[root@redis64 redis-4.3.0]
redis
[root@redis64 redis-4.3.0]
[root@redis64 redis-4.3.0]
bind 127.0.0.1 192.168.88.64
[root@redis64 redis-4.3.0]
[root@redis64 redis-4.3.0]
LISTEN 0 128 192.168.88.64:6364 0.0.0.0:* users:(("redis-server",pid=10067,fd=7))
LISTEN 0 128 127.0.0.1:6364 0.0.0.0:* users:(("redis-server",pid=10067,fd=6))
[root@redis64 redis-4.3.0]
<?php
$redis = new redis();
$redis->connect("127.0.0.1", "6364");
$redis->auth("tarenaplj");
$redis->set("class","nsd");
echo "save okn";
?>
通过浏览器访问:http:
save ok
[root@redis64 redis-4.3.0]
192.168.88.64:6364> keys *
1) "class"
192.168.88.64:6364> get class
"nsd2023"