Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
system
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
_site-res
system
Commits
d1b186b0
Commit
d1b186b0
authored
May 23, 2018
by
tufengqi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cache部分结构调整
parent
265551ba
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
100 additions
and
14 deletions
+100
-14
DefaultBaseImpl.php
classes/fpf/cache/DefaultBaseImpl.php
+13
-2
HashTableIntf.php
classes/fpf/cache/HashTableIntf.php
+4
-2
SimpleTableIntf.php
classes/fpf/cache/SimpleTableIntf.php
+10
-0
TableConst.php
classes/fpf/cache/TableConst.php
+17
-10
YiiTraitHashTable.php
classes/fpf/cache/YiiTraitHashTable.php
+56
-0
No files found.
classes/fpf/cache/DefaultBaseImpl.php
View file @
d1b186b0
<?php
namespace
fpf\cache
;
use
fpf\cache\TableConstant
;
/**
* 简单的KEY VALUE形式的构造真实KEY的方法
*/
class
DefaultBaseImpl
{
public
static
function
get
TableKey
(
$prefix_tag
,
$table_name
,
$key
)
public
static
function
get
SimpleTableKey
(
$db_name
,
$table_name
,
$key
)
{
return
$prefix_tag
.
$table_name
.
TableConstant
::
CONNECTOR_TAG
.
$key
;
return
$db_name
.
TableConstant
::
CONNECTOR_TAG
.
$table_name
.
TableConstant
::
CONNECTOR_TAG
.
$key
;
}
public
static
function
getHashTable
(
$db_name
,
$table_name
)
{
return
$db_name
.
TableConstant
::
CONNECTOR_TAG
.
$table_name
;
}
public
static
function
checkTable
(
$db_name
,
$table
)
{
if
(
!
isset
(
TableConstant
::
$table_list
[
$db_name
.
TableConstant
::
CONNECTOR_TAG
.
$table_name
]))
{
throw
new
Exception
(
'hash table is not defined'
);
}
}
}
classes/fpf/cache/
Bas
eIntf.php
→
classes/fpf/cache/
HashTabl
eIntf.php
View file @
d1b186b0
...
...
@@ -2,7 +2,8 @@
namespace
fpf\cache
;
interface
Bas
eIntf
interface
HashTabl
eIntf
{
public
function
getTableKey
(
$prefix_tag
,
$table
,
$key
);
public
function
getHashTable
(
$db_name
,
$table_name
);
public
function
checkTable
(
$table_name
);
}
\ No newline at end of file
classes/fpf/cache/SimpleTableIntf.php
0 → 100644
View file @
d1b186b0
<?php
namespace
fpf\cache
;
interface
SimpleTableIntf
{
public
function
getHashTableKey
(
$db_name
,
$table_name
,
$key
);
public
function
checkTable
(
$table_name
);
}
\ No newline at end of file
classes/fpf/cache/TableConst.php
View file @
d1b186b0
...
...
@@ -7,15 +7,22 @@ namespace fpf\cache;
class
TableConstant
{
const
CONNECTOR_TAG
=
'_'
;
const
HASH_BTC
=
'BTC'
;
const
HASH_USDT
=
'USDT'
;
const
SIMPLE_USD_CNY_RATE
=
'USD_CNY_RATE'
;
const
MARKET_SERVICE_TABLE_PREFIX
=
'market-service:'
;
public
static
$hash_table
=
[
TableConstant
::
HASH_BTC
=>
true
,
TableConstant
::
HASH_USDT
=>
true
,
];
public
static
$simple_table
=
[
TableConstant
::
SIMPLE_USD_CNY_RATE
=>
true
,
/**
* table list
*/
const
TABLE_HASH_RISE_FALL_BTC
=
'RISE_FALL_BTC'
;
const
TABLE_HASH_RISE_FALL_USDT
=
'RISE_FALL_USDT'
;
const
TABLE_SIMPLE_USD_CNY_RATE
=
'USD_CNY_RATE'
;
/**
* db name list
*/
const
DB_MARKET_SERVICE
=
'market-service'
;
/**
* table check
*/
public
static
$table_list
=
[
self
::
DB_MARKET_SERVICE
.
self
::
CONNECTOR_TAG
.
self
::
TABLE_HASH_RISE_FALL_BTC
=>
true
,
self
::
DB_MARKET_SERVICE
.
self
::
CONNECTOR_TAG
.
self
::
TABLE_HASH_RISE_FALL_USDT
=>
true
,
self
::
DB_MARKET_SERVICE
.
self
::
CONNECTOR_TAG
.
self
::
TABLE_SIMPLE_USD_CNY_RATE
=>
true
,
];
}
classes/fpf/cache/YiiTraitHashTable.php
0 → 100644
View file @
d1b186b0
<?php
namespace
fpf\cache
;
use
fpf\cache\DefaultBaseImpl
;
trait
YiiTraitHashTable
{
public
static
function
getHashTable
(
$db_name
,
$table_name
)
{
return
DefaultBaseImpl
::
getHashTable
(
$db_name
,
$table_name
);
}
public
static
function
getByTable
(
$table
)
{
self
::
checkTable
(
self
::
DB_NAME
,
$table
);
$real_table
=
self
::
getHashTable
(
self
::
DB_NAME
,
$table
);
$ret
=
Yii
::
$app
->
redis
->
hkeys
(
$real_table
);
if
(
empty
(
$ret
))
{
return
[];
}
return
self
::
getByTableKeys
(
$table
,
$ret
);
}
public
static
function
getKeysByTable
(
$table
)
{
self
::
checkTable
(
self
::
DB_NAME
,
$table
);
$table
=
self
::
getHashTable
(
self
::
DB_NAME
,
$table
);
return
Yii
::
$app
->
redis
->
hkeys
(
$table
);
}
public
static
function
getByTableKeys
(
$table
,
$keys
)
{
self
::
checkTable
(
self
::
DB_NAME
,
$table
);
$table
=
self
::
getHashTable
(
self
::
DB_NAME
,
$table
);
return
Yii
::
$app
->
redis
->
hmget
(
$table
,
...
$keys
);
}
public
static
function
getByTableKey
(
$table
,
$key
)
{
self
::
checkTable
(
self
::
DB_NAME
,
$table
);
$table
=
self
::
getHashTable
(
self
::
DB_NAME
,
$table
);
return
Yii
::
$app
->
redis
->
hget
(
$table
,
$key
);
}
public
static
function
setByTableKey
(
$table
,
$key
,
$value
)
{
self
::
checkTable
(
self
::
DB_NAME
,
$table
);
$table
=
self
::
getHashTable
(
self
::
DB_NAME
,
$table
);
return
Yii
::
$app
->
redis
->
hset
(
$table
,
$key
,
$value
);
}
private
static
function
checkTable
(
$db_name
,
$table
)
{
DefaultBaseImpl
::
checkTable
(
$db_name
,
$table
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment