Simple example of using redis in PHP. Simple example of using redis in PHP this article mainly introduces the simple example of using redis in PHP. it mainly shows you how to use redis in php, for more information about using redis in PHP, see the simple example.
This article mainly introduces a simple example of using apsaradb for redis in PHP. it mainly shows you how to use apsaradb for redis in php.
The example is very simple. it is explained in the annotations, so there is not much nonsense here.
The code is as follows:
/* Obtain the database name from the platform */
$ Dbname = "";
/* Obtain host, port, user, pwd from environment variables */
$ Host = '';
$ Port = '';
$ User = '';
$ Pwd = '';
Try {
/* After the connection is established, perform auth verification before performing the set operation */
$ Redis = new Redis ();
$ Ret = $ redis-> connect ($ host, $ port );
If ($ ret = false ){
Die ($ redis-> getLastError ());
}
$ Ret = $ redis-> auth ($ user. "-". $ pwd. "-". $ dbname );
If ($ ret = false ){
Die ($ redis-> getLastError ());
}
/* Next, you can perform operations on the database. for detailed operation methods, see the official phpredis documentation */
$ Redis-> flushdb ();
$ Ret = $ redis-> set ("key", "value ");
If ($ ret = false ){
Die ($ redis-> getLastError ());
} Else {
Echo "OK". $ redis-> get ("key ");
}
} Catch (RedisException $ e ){
Die ("Uncaught exception". $ e-> getMessage ());
}
?>
The above is all the content of the code described in this article. I hope you will like it.
Http://www.bkjia.com/PHPjc/963977.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/963977.htmlTechArticlePHP using redis simple example to share this article mainly introduced the PHP using redis simple example to share, mainly to show you, php using redis method, there is a need for small partners reference...