connect(...)" or use "redis-cli" to connect. Can."/> connect(...)" or use "redis-cli" to connect. Can.">

Home >Database >Redis >How to cache redis

How to cache redis

藏色散人
藏色散人Original
2019-08-29 14:03:175468browse

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

How to cache redis

can be used in php:

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

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!

Statement:
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
Previous article:How to use redis in javaNext article:How to use redis in java