当前位置:网站首页>TP5 uses redis
TP5 uses redis
2022-04-23 06:52:00 【Collect and study by yourself】
1. open tp5 The official manual , Under cache, find using multiple cache types
Paste the following code into tp frame config The following cache settings
// Switch to redis operation
Cache::store('redis')->set('name','value');
// obtain redis
Cache::store('redis')->get('rename');
// Realization redis Message queue
stay /thinkphp/library/think/cache/driver/Redis.php Inside the file
// Add data to the queue
public function lPush($key, $value)
{
return $this->handler->lPush($key, $value);
}
// Get data from the queue
public function lPop($key)
{
return $this->handler->lPop($key);
}
Call... In the controller
// Storage
Cache::store('redis')->handler()->lPush('k','v');
// obtain
Cache::store('redis')->handler()->lPop('k');
A little more complicated
/**
* stay list The added value to the left of is $value The elements of
* @access public
* @param $key Indexes
* @param $value value
* @return int
*/
public function lPush($key,$value){
return $this->handler->lPush($key,$value);
}
/**
* stay list The value on the right of is $value The elements of
* @access public
* @param $key Indexes
* @return int
*/
public function lPop($key){
return $this->handler->lPop($key);
}
/**
* stay list Remove duplicate values
* @access public
* @param $key Indexes
* @return int
*/
public function lrem($key1,$key2){
return $this->handler->lrem ($key1,$key2);
}
/**
* stay list Judge
* @access public
* @param $key Indexes
* @return int
*/
public function lLen($key){
return $this->handler->lLen ($key);
}
Use in controller
Here is the code in the method :
$list=array(
'1'=>'a',
'2'=>'b',
'3'=>'c'
);
$redis=new Redis();
$keys='test1';
$total=$redis->lLen($keys);// Return key name test1 length
if($total == 0){
foreach ($list as $key => $val){
$redis->lPush($keys,$val);// Write the value of the array to the key name test1 Of the queue
}
}
// Here is the... Taken out , If you take it out elsewhere , Delete this paragraph
$data=$redis->lPop($keys);// Remove key name test1 The first data in the queue
if (!$data) {
return ' Completed ';
}
$redis->lrem($keys,$data);// duplicate removal
版权声明
本文为[Collect and study by yourself]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230555551672.html
边栏推荐
猜你喜欢
随机推荐
初步认识Promse
TypeScript(上)
深入理解控制反转和依赖注入
.NET Standard详解
Counts the number of occurrences of each character in the string
Add serial number to El table
TP6 的 each 遍历用法
ASP.NET CORE JWT认证
.Net Core 下使用 Quartz —— 【5】作业和触发器之触发器的通用属性和优先级
.Net Core 下使用 Quartz —— 【1】快速开始
offset和client獲取dom元素比特置信息
WebSocket(基础)
Node accesses server-side static resources
Router对象、Route对象、声明式导航、编程式导航
关于注解1
Node data flow
input文件上传
常用sql语句收藏
批量修改/批量更新数据库某一个字段的值
js查找字符串中出现了三次的字符