您的位置:首页 > 数据库 > Redis

将数据库字段为下划线命名的方式转成小驼峰命名,再存入redis

2018-01-23 11:36 555 查看

tp5数据库输入存入远程Redis

tp5,将数据库字段为下划线命名的方式转成小驼峰命名,再存入redis

config配置

'cache' => [
// 使用复合缓存类型
'type' => 'complex',
// 默认使用的缓存
'default' => [
// 驱动方式
'type' => 'File',
// 缓存保存目录
'path' => CACHE_PATH,
],
// redis缓存
'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);
}


如图

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: