<?php/* Gets the database name from the platform */$dbname = ""; /* Take host,port,user,pwd*/from environment variables $host = '; $port = '; $user = '; $pwd = '; After a connection is made to the try { /*, the Auth validation is required prior to the collection 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 operate the library, please refer to Phpredis Official document * /$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 ());}? >
Using Redis with PHP