Get the App
SLTechnology News&Howtos  ›  Database  › 

How to cache redis

Shulou Source: shulou.com Published: 2022-06-01 11:40:49 09月10日 Update

This article uses easy-to-understand examples to introduce how to cache redis, the code is very detailed, interested friends can refer to, hope to be helpful to you.

How do I 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, the yPay option will pop up. Just select Y. I won't say any more here because it has already been installed.

After installing redis-sever, check to see if there is any redis extension in php, if not, install the redis extension, and if so, you can use it directly. Php extensions can be viewed using php-m

After the extension is installed successfully, you can use php to use the redis extension. Generally, you can use Redis to create instantiation directly after installing the extension.

$redis = new Redis () / / instantiate redis$redis- > connect ('127.0.0.1) / / 127.0.0.1 is the connection address, and 6379 is the port number

In php, you can use:

$reids- > lpush ('key name', 'key value'), this is the storage queue; $redis- > set ('key name', 'key value'), this is storage string;$redis- > hset ('key name', 'key value'), this is hash

You can also use redis-cli to connect, but note that the redis-cli-h connection address-a password / port, makes a remote connection.

On how to cache redis to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Cache this is commands addresses instances more storage help yes success code examples interests content slogans passwords guys buddies articles methods Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple vpn MariaDB Shulou Information Redmi