tp5数据库输入存入远程Redis
tp5,将数据库字段为下划线命名的方式转成小驼峰命名,再存入redis
config配置
'cache' => [
'type' => 'complex',
'default' => [
'type' => 'File',
'path' => CACHE_PATH,
],
'redis' => [
'type' => 'redis',
'host' => 'xxx.xx.xxx.xx',
'password' => 'xxxxxx',
],
php代码
use think\Cache;
public function change($str)
{
$res = $str;
foreach ($str as $keys => $values) {
$str = ucwords(str_replace('_', ' ', $values));
$str = str_replace(' ', '', lcfirst($str));
$a[$keys] = $str;
}
foreach ($a as $key => $value) {
$array[$key]= json_decode($value, true);
}
return $array;
}
public function do_redis()
{
$alms1 = $this->alms->selRedis();
$alms2 = ConfigRedis::change($alms1);
$alms3 = json_encode($alms2,JSON_UNESCAPED_UNICODE);
Cache::store('redis')->set('config:alms',$alms3);
}
如图