connect(...)" or use "redis-cli" to connect. Can."/> connect(...)" or use "redis-cli" to connect. Can.">
How to cache redis?
First of all, to use redis, you need to install it on the server in advance. The installation command is yum install redis (using Centos system). After using this command normally, the y/n option will pop up. Just select Y. . I won’t say more here because it has already been installed.
After installing redis-sever, check whether there is a redis extension in PHP. If not, install the redis extension. If there is, you can use it directly. PHP extensions can be viewed using php -m
After the extension is successfully installed, it is time to use PHP to use the redis extension. Generally, after the extension is installed, it is created directly using Redis. Just instantiate it.
$redis = new Redis()//实例化redis $redis->connect('127.0.0.1',6379)//127.0.0.1是连接地址,6379是端口号
can be used in php:
$reids->lpush('键名','键值'),这是存储队列; $redis->set('键名','键值'),这是存储string; $redis->hset('键名','键值'),这是hash;
You can also use redis-cli to connect, please note It is redis-cli -h connection address-a password/port for remote connection.
For more Redis related knowledge, please visit the Redis usage tutorial column!
The above is the detailed content of How to cache redis. For more information, please follow other related articles on the PHP Chinese website!