Install the Redis software in the running environment, and install the Redis extension in PHP after installation
Configure the cache.php file after the installation is successful
// The cache is configured as a composite type
'type' => 'complex',
'default' => [
'type' => 'file',
// Global cache validity period (0 is permanent)
'expire'=> 0,
// cache prefix
'prefix'=> '',
// cache directory
'path' => '…/runtime/cache/',
],
'redis' => [
// type
'type ' => 'redis',
// address
'host' => '127.0.0.1',
// global cache validity period (0 is permanent)
'expire'=> 0,
// cache prefix
'prefix'=> '' ,
// port
'port' => '6379',
// username
'username' => '',
// password
'password' => '',
],
then directly use $redis = new Redis(); use Local Redis
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
echo “Connection to server successfully”;
echo “
”;
//store data in the list
$redis->lpush(“tutorial-list”, “Redis”) ;
$redis->lpush("tutorial-list", "Mongodb");
$redis->lpush("tutorial-list", "Mysql");
// Get the stored data and output
$arList = redis − > lrange ( " tutorial − list " , 0 , 5 ) ; echo " Stored string in redis " ; printr ( redis->lrange("tutorial-list", 0 ,5); echo "Stored string in redis"; print_r(redis−>lrange("tutorial−list",0,5);echo"Storedstringinredis";printr(arList);
echo “
”;
r e s = res= res=redis->lrange(“tutorial-list”, 0 ,-1);
var_dump( $res);
EXIT;
Note:
A single character
get gets the value of a key (string value).
If the key does not exist, return false
set writes the key and value (string value).
If the write is successful, return ture
List-related operations
lPush
$redis->lPush(key, value);
add an element whose value is value to the left (head) of the list named key
rPush
$redis->rPush(key, value); add an element whose value
is value to the list named key Add an element with the value value to the right (tail)