Skip to content

Commit

Permalink
Updates doc/tong-bu-fu-wu/dao.md
Browse files Browse the repository at this point in the history
Auto commit by GitBook Editor
  • Loading branch information
fucongcong committed Nov 8, 2017
1 parent e187c84 commit de5e6c4
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
$callId1 = $service->addCall("User::getUsersCache", ['ids' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]);
$callId2 = $service->addCall("User::getUser", ['id' => 1]);
$res = (yield $service->multiCall());
dump($res[$callId1]);
dump($res[$callId2]);
```
Expand Down
87 changes: 87 additions & 0 deletions doc/tong-bu-fu-wu/dao.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,91 @@
### Dao

> ##### 框架内部会做断线重连,失败3次后将进行重连操作
#### 文档参考:[Doctrine DBAL’s documentation](http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/index.html)

##### $this->getDefault\(\)

> ##### 获取默认服务器连接,返回\Doctrine\DBAL\Connection对象
##### $this->getRead\($name = null\)

> ##### 获取读服务器连接,若name不填,随机读取。
##### $this->getWrite\($name = null\)

> ##### 获取写服务器连接,若name不填,随机读取。
##### $this->getAllRead\(\)

> 获取所有读服务器的连接
##### $this->getAllWrite\(\)

> 获取所有写服务器的连接
##### $this->querySql\($sql, $type, $name = null\)

> \* @param sql
>
> \* @param type\[write\|all\_write\|read\|all\_read\|default\]
>
> \* @param name
##### 具体业务中使用:

```
namespace src\Service\User\Dao\Impl;
use Dao;
use src\Service\User\Dao\UserDao;
class UserDaoImpl extends Dao implements UserDao
{
protected $table = "user";
public function getUser($id)
{
$queryBuilder = $this->getDefault()->createQueryBuilder();
$queryBuilder
->select("*")
->from($this->table)
->where('id = ?')
->setParameter(0, $id);
return $queryBuilder->execute()->fetch();
}
public function addUser($user)
{
$conn = $this->getDefault();
$affected = $conn->insert($this->table, $user);
if ($affected <= 0) {
return fasle;
}
return $conn->lastInsertId();
}
public function getUserByMobile($mobile)
{
$queryBuilder = $this->getDefault()->createQueryBuilder();
$queryBuilder
->select("*")
->from($this->table)
->where('mobile = ?')
->setParameter(0, $mobile);
return $queryBuilder->execute()->fetch();
}
public function updateUserPassword($userId, $password)
{
return $this->getDefault()->update($this->table, ['password' => $password], ['id' => $userId]);
}
}
```



22 changes: 21 additions & 1 deletion doc/tong-bu-fu-wu/filecachewen-jian-huan-cun-lei.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
### FileCache

###
##### 文件形式的缓存

#### FileCache::get\($cacheName, $cacheDir = false\)

```
use FileCache;
FileCache::get('test.php');
FileCache::get('test.php', 'runtime/cache/test/');
```

#### FileCache::set\($cacheName, $data, $cacheDir = false, $flag = false\)

```
use FileCache;
//默认路径是放在runtime/logs/service
FileCache::set('test.php', ['testdfata' => 'datadata']);
//指定路径
FileCache::set('test.php', ['testdfata' => 'datadata'], 'runtime/cache/test/', FILE_APPEND);
```



21 changes: 21 additions & 0 deletions doc/tong-bu-fu-wu/logri-zhi-lei.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
### Log

#### 默认路径存放于runtime/logs/service

```php

Log::debug('123',['user'=>1]);
Log::info('123',['user'=>1]);
Log::notice('123',['user'=>1]);
Log::warning('123',['user'=>1]);
Log::error('123',['user'=>1]);
Log::critical('123',['user'=>1]);
Log::alert('123',['user'=>1]);
Log::emergency('123',['user'=>1]);

//默认model是web.app,也可以自定义
Log::emergency('123',['user'=>1],'web.admin');
```

##





23 changes: 23 additions & 0 deletions doc/tong-bu-fu-wu/rediscache.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
### Cache

##### 目前只支持了Redis得cache,使用请在config/database.php配置中配置'cache' =&gt; 'redis',

```php
use Cache;
//key value expireTime
Cache::set('ha', 123, 60);
//也可以这样
Cache::redis() -> set('haa', 123, 60);

Cache::get('ha');
Cache::mGet(['ha', 'aa']);
Cache::hSet($hashKey, $key, $data, $expireTime);
Cache::hGet($hashKey, $key);
Cache::hDel($hashKey, $key);
Cache::hDel($hashKey);

//现在的类库方法还未扩展完全,目前只有以上方法
```

* ##### 你可以使用Cache::redis\(\) 获取redis实例,这是一个PhpRedis的实例,api地址\([https://github.com/phpredis/phpredis\](https://github.com/phpredis/phpredis\)\)





59 changes: 59 additions & 0 deletions doc/tong-bu-fu-wu/service.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,63 @@
### Service服务

* > #### Service服务是配合服务中心来实现服务化的。每个服务可以单独启动一个server,处理请求。
>
> #### 在开发Service模块时候,同样要注意内存释放问题。并且不可以使用异步服务,此模块是以同步方式执行的。
>
> #### 所以说,你可以用传统的方式来编写服务接口,当然你也可以使用内置的一些异步task方法来实现map-reduce,提升接口吞吐。
#### 1.开启服务如执行 app/service user,会开放服务下面指定开放模块所有公有函数调用

#### 2.使用Console控制台,自动初始化服务

```
app/console generate:service demo
```

#### 3.简单介绍一下生成的服务目录结构

* User \(示例\)

* Dao

* Impl \(数据层实现的接口\)

* UserDaoImpl.php\(接口实现\)

* UserDao.php\(接口\)

* Service

* Impl (服务层实现的接口)

* UserServiceImpl.php\(接口的实现\)

* Rely (定义服务之间的依赖关系)

* UserService.php\(接口\)

#### Service类

$this-&gt;createDao\($serviceName\)

> 实例化一个dao类
$this-&gt;createService\($serviceName\)

> 实例化一个service类
```
public function getUserDao()
{
return $this->createDao("User:User");
}
public function getUserProfileService()
{
return $this->createService("User:UserProfile");
}
```



0 comments on commit de5e6c4

Please sign in to comment.