Home > Database > Redis > body text

How to cache redis

藏色散人
Release: 2019-08-29 14:03:52
Original
5397 people have browsed it

How to cache redis

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.

How to cache redis

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

How to cache redis

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是端口号
Copy after login

How to cache redis

can be used in php:

$reids->lpush('键名','键值'),这是存储队列;
$redis->set('键名','键值'),这是存储string;
$redis->hset('键名','键值'),这是hash;
Copy after login

How to cache redis

You can also use redis-cli to connect, please note It is redis-cli -h connection address-a password/port for remote connection.

How to cache redis

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!