This commit is contained in:
parent
c3d0b64d72
commit
3488eab401
243
.idea/workspace.xml
generated
243
.idea/workspace.xml
generated
@ -4,13 +4,11 @@
|
||||
<bookmark url="file://$PROJECT_DIR$/var.go" line="12" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" readonly="true" id="03ed5703-81a1-441b-849c-c426276586b7" name="Default" comment="工具">
|
||||
<change beforePath="" afterPath="$PROJECT_DIR$/cache" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
|
||||
<change beforePath="$PROJECT_DIR$/cache_memory.go" afterPath="$PROJECT_DIR$/cache_memory.go" />
|
||||
<change beforePath="$PROJECT_DIR$/cache_redis.go" afterPath="$PROJECT_DIR$/cache_redis.go" />
|
||||
<list default="true" readonly="true" id="03ed5703-81a1-441b-849c-c426276586b7" name="Default" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/cache_redis.go" afterPath="$PROJECT_DIR$/cache/cache_redis.go" />
|
||||
<change beforePath="$PROJECT_DIR$/example/config/config.json" afterPath="$PROJECT_DIR$/example/config/config.json" />
|
||||
<change beforePath="$PROJECT_DIR$/example/main.go" afterPath="$PROJECT_DIR$/example/main.go" />
|
||||
<change beforePath="$PROJECT_DIR$/type.go" afterPath="$PROJECT_DIR$/type.go" />
|
||||
</list>
|
||||
<ignored path=".idea/dataSources.local.xml" />
|
||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||
@ -31,8 +29,52 @@
|
||||
<file leaf-file-name="main.go" pinned="false" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/example/main.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="375">
|
||||
<caret line="32" column="17" lean-forward="true" selection-start-line="32" selection-start-column="17" selection-end-line="32" selection-end-column="17" />
|
||||
<state relative-caret-position="330">
|
||||
<caret line="49" column="17" lean-forward="true" selection-start-line="49" selection-start-column="17" selection-end-line="49" selection-end-column="17" />
|
||||
<folding>
|
||||
<element signature="e#14#167#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="type.go" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/type.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="165">
|
||||
<caret line="11" column="4" lean-forward="false" selection-start-line="11" selection-start-column="4" selection-end-line="11" selection-end-column="4" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="cache_redis.go" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/cache/cache_redis.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="286">
|
||||
<caret line="110" column="50" lean-forward="false" selection-start-line="110" selection-start-column="50" selection-end-line="110" selection-end-column="50" />
|
||||
<folding>
|
||||
<element signature="e#15#106#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="strings.go" pinned="false" current-in-tab="false">
|
||||
<entry file="file://D:/app/go/src/strings/strings.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="203">
|
||||
<caret line="92" column="15" lean-forward="true" selection-start-line="92" selection-start-column="15" selection-end-line="92" selection-end-column="15" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="objtoobj.go" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/objtoobj.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="158">
|
||||
<caret line="204" column="5" lean-forward="false" selection-start-line="204" selection-start-column="5" selection-end-line="204" selection-end-column="5" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
@ -41,8 +83,8 @@
|
||||
<file leaf-file-name="cache_memory.go" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/cache_memory.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="133">
|
||||
<caret line="60" column="0" lean-forward="false" selection-start-line="60" selection-start-column="0" selection-end-line="102" selection-end-column="21" />
|
||||
<state relative-caret-position="915">
|
||||
<caret line="64" column="23" lean-forward="true" selection-start-line="64" selection-start-column="23" selection-end-line="64" selection-end-column="23" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
@ -51,18 +93,38 @@
|
||||
<file leaf-file-name="config.json" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/example/config/config.json">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="135">
|
||||
<caret line="9" column="32" lean-forward="false" selection-start-line="9" selection-start-column="32" selection-end-line="9" selection-end-column="32" />
|
||||
<state relative-caret-position="225">
|
||||
<caret line="15" column="26" lean-forward="true" selection-start-line="15" selection-start-column="26" selection-end-line="15" selection-end-column="26" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="cache_redis.go" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/cache_redis.go">
|
||||
<file leaf-file-name="cache_db.go" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/cache_db.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="90">
|
||||
<caret line="10" column="14" lean-forward="true" selection-start-line="10" selection-start-column="14" selection-end-line="10" selection-end-column="14" />
|
||||
<state relative-caret-position="-795">
|
||||
<caret line="10" column="10" lean-forward="true" selection-start-line="10" selection-start-column="10" selection-end-line="10" selection-end-column="10" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="db.go" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/db.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="615">
|
||||
<caret line="331" column="27" lean-forward="true" selection-start-line="331" selection-start-column="27" selection-end-line="331" selection-end-column="27" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="context_base.go" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/context_base.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="195">
|
||||
<caret line="13" column="16" lean-forward="true" selection-start-line="13" selection-start-column="16" selection-end-line="13" selection-end-column="16" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
@ -124,7 +186,6 @@
|
||||
<option value="$PROJECT_DIR$/dri/upload/upload.go" />
|
||||
<option value="$PROJECT_DIR$/cache_groupcache.go" />
|
||||
<option value="$PROJECT_DIR$/application.go" />
|
||||
<option value="$PROJECT_DIR$/type.go" />
|
||||
<option value="$PROJECT_DIR$/session.go" />
|
||||
<option value="$PROJECT_DIR$/example/tpt/index.html" />
|
||||
<option value="$PROJECT_DIR$/map.go" />
|
||||
@ -132,8 +193,10 @@
|
||||
<option value="$PROJECT_DIR$/func.go" />
|
||||
<option value="$PROJECT_DIR$/error.go" />
|
||||
<option value="$PROJECT_DIR$/cache_memory.go" />
|
||||
<option value="$PROJECT_DIR$/example/config/config.json" />
|
||||
<option value="$PROJECT_DIR$/cache_redis.go" />
|
||||
<option value="$PROJECT_DIR$/type.go" />
|
||||
<option value="$PROJECT_DIR$/example/config/config.json" />
|
||||
<option value="$PROJECT_DIR$/cache/cache_redis.go" />
|
||||
<option value="$PROJECT_DIR$/example/main.go" />
|
||||
</list>
|
||||
</option>
|
||||
@ -178,6 +241,22 @@
|
||||
<item name="hotime" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="hotime" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
<path>
|
||||
<item name="hotime" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="hotime" type="462c0819:PsiDirectoryNode" />
|
||||
<item name="cache" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
<path>
|
||||
<item name="hotime" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="hotime" type="462c0819:PsiDirectoryNode" />
|
||||
<item name="example" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
<path>
|
||||
<item name="hotime" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="hotime" type="462c0819:PsiDirectoryNode" />
|
||||
<item name="example" type="462c0819:PsiDirectoryNode" />
|
||||
<item name="config" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
</expand>
|
||||
<select />
|
||||
</subPane>
|
||||
@ -198,13 +277,14 @@
|
||||
<property name="DefaultHtmlFileTemplate" value="HTML File" />
|
||||
</component>
|
||||
<component name="RecentsManager">
|
||||
<key name="CopyFile.RECENT_KEYS">
|
||||
<recent name="E:\gopath1\trunk\src\go.hoteas.com\hotime\dri" />
|
||||
<recent name="D:\golang\path\trunk\src\hoteas\hotime" />
|
||||
</key>
|
||||
<key name="MoveFile.RECENT_KEYS">
|
||||
<recent name="E:\gopath1\trunk\src\go.hoteas.com\hotime\example" />
|
||||
</key>
|
||||
<key name="CopyFile.RECENT_KEYS">
|
||||
<recent name="D:\golang\path\trunk\src\go.hoteas.com\hotime\cache" />
|
||||
<recent name="E:\gopath1\trunk\src\go.hoteas.com\hotime\dri" />
|
||||
<recent name="D:\golang\path\trunk\src\hoteas\hotime" />
|
||||
</key>
|
||||
</component>
|
||||
<component name="RunDashboard">
|
||||
<option name="ruleStates">
|
||||
@ -386,7 +466,7 @@
|
||||
<workItem from="1522771122447" duration="2480000" />
|
||||
<workItem from="1522778115746" duration="44000" />
|
||||
<workItem from="1522778659126" duration="455000" />
|
||||
<workItem from="1522779789231" duration="1641000" />
|
||||
<workItem from="1522779789231" duration="6991000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001">
|
||||
<created>1500458878821</created>
|
||||
@ -577,11 +657,18 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1508808698714</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="28" />
|
||||
<task id="LOCAL-00028" summary="工具">
|
||||
<created>1522782970484</created>
|
||||
<option name="number" value="00028" />
|
||||
<option name="presentableId" value="LOCAL-00028" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1522782970484</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="29" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TimeTrackingManager">
|
||||
<option name="totallyTimeSpent" value="95320000" />
|
||||
<option name="totallyTimeSpent" value="100670000" />
|
||||
</component>
|
||||
<component name="TodoView">
|
||||
<todo-panel id="selected-file">
|
||||
@ -604,7 +691,7 @@
|
||||
<window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.6329114" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32911393" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32805908" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32805908" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Capture Tool" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Designer" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.36900166" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
|
||||
@ -650,7 +737,9 @@
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="270">
|
||||
<caret line="18" column="29" lean-forward="false" selection-start-line="18" selection-start-column="29" selection-end-line="18" selection-end-column="29" />
|
||||
<folding />
|
||||
<folding>
|
||||
<element signature="e#14#167#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
@ -666,7 +755,9 @@
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="0">
|
||||
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
|
||||
<folding />
|
||||
<folding>
|
||||
<element signature="e#14#167#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
@ -678,22 +769,6 @@
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/config/config.json">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="135">
|
||||
<caret line="9" column="32" lean-forward="false" selection-start-line="9" selection-start-column="32" selection-end-line="9" selection-end-column="32" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/cache_memory.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="133">
|
||||
<caret line="60" column="0" lean-forward="false" selection-start-line="60" selection-start-column="0" selection-end-line="102" selection-end-column="21" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/cache_redis.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="90">
|
||||
@ -702,11 +777,87 @@
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/context_base.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="195">
|
||||
<caret line="13" column="16" lean-forward="true" selection-start-line="13" selection-start-column="16" selection-end-line="13" selection-end-column="16" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/cache_memory.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="915">
|
||||
<caret line="64" column="23" lean-forward="true" selection-start-line="64" selection-start-column="23" selection-end-line="64" selection-end-column="23" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/objtoobj.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="158">
|
||||
<caret line="204" column="5" lean-forward="false" selection-start-line="204" selection-start-column="5" selection-end-line="204" selection-end-column="5" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://D:/app/go/src/strings/strings.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="203">
|
||||
<caret line="92" column="15" lean-forward="true" selection-start-line="92" selection-start-column="15" selection-end-line="92" selection-end-column="15" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/type.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="165">
|
||||
<caret line="11" column="4" lean-forward="false" selection-start-line="11" selection-start-column="4" selection-end-line="11" selection-end-column="4" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/cache/cache_redis.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="286">
|
||||
<caret line="110" column="50" lean-forward="false" selection-start-line="110" selection-start-column="50" selection-end-line="110" selection-end-column="50" />
|
||||
<folding>
|
||||
<element signature="e#15#106#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/config/config.json">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="225">
|
||||
<caret line="15" column="26" lean-forward="true" selection-start-line="15" selection-start-column="26" selection-end-line="15" selection-end-column="26" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/cache_db.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="-795">
|
||||
<caret line="10" column="10" lean-forward="true" selection-start-line="10" selection-start-column="10" selection-end-line="10" selection-end-column="10" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/db.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="615">
|
||||
<caret line="331" column="27" lean-forward="true" selection-start-line="331" selection-start-column="27" selection-end-line="331" selection-end-column="27" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/main.go">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="375">
|
||||
<caret line="32" column="17" lean-forward="true" selection-start-line="32" selection-start-column="17" selection-end-line="32" selection-end-column="17" />
|
||||
<folding />
|
||||
<state relative-caret-position="330">
|
||||
<caret line="49" column="17" lean-forward="true" selection-start-line="49" selection-start-column="17" selection-end-line="49" selection-end-column="17" />
|
||||
<folding>
|
||||
<element signature="e#14#167#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
|
124
cache/cache_redis.go
vendored
Normal file
124
cache/cache_redis.go
vendored
Normal file
@ -0,0 +1,124 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"time"
|
||||
"github.com/garyburd/redigo/redis"
|
||||
. "go.hoteas.com/hotime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type CacheRedis struct {
|
||||
Host string
|
||||
Pwd string
|
||||
Time int64
|
||||
conn redis.Conn
|
||||
tag int64
|
||||
Error
|
||||
}
|
||||
|
||||
//唯一标志
|
||||
func (this *CacheRedis) GetTag() int64 {
|
||||
|
||||
if this.tag == int64(0) {
|
||||
this.tag = time.Now().UnixNano()
|
||||
}
|
||||
return this.tag
|
||||
}
|
||||
|
||||
func (this *CacheRedis) reCon()bool{
|
||||
var err error
|
||||
this.conn,err=redis.Dial("tcp",this.Host)
|
||||
if err!=nil{
|
||||
this.conn=nil
|
||||
this.Error.SetError(err)
|
||||
return false
|
||||
}
|
||||
|
||||
_,err=this.conn.Do("AUTH",this.Pwd)
|
||||
if err!=nil{
|
||||
this.conn=nil
|
||||
this.Error.SetError(err)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (this *CacheRedis) Cache(key string, data ...interface{}) *Obj {
|
||||
reData:= &Obj{}
|
||||
var err error
|
||||
if this.conn==nil{
|
||||
re:=this.reCon()
|
||||
if !re{
|
||||
return reData
|
||||
}
|
||||
}
|
||||
//查询缓存
|
||||
if len(data) == 0 {
|
||||
|
||||
reData.Data, err = redis.String(this.conn.Do("GET", key))
|
||||
if err != nil {
|
||||
reData.Data=nil
|
||||
if !strings.Contains(err.Error(), "nil returned") {
|
||||
this.Error.SetError(err)
|
||||
_, err = this.conn.Do("PING")
|
||||
if err != nil {
|
||||
if this.reCon() {
|
||||
reData.Data, err = redis.String(this.conn.Do("GET", key))
|
||||
}
|
||||
}
|
||||
|
||||
return reData
|
||||
}
|
||||
}
|
||||
return reData
|
||||
|
||||
}
|
||||
tim := int64(0)
|
||||
//删除缓存
|
||||
if len(data) == 1 && data[0] == nil {
|
||||
|
||||
_,err=this.conn.Do("DEL",key)
|
||||
if err!=nil{
|
||||
this.Error.SetError(err)
|
||||
_,err=this.conn.Do("PING")
|
||||
if err!=nil{
|
||||
if this.reCon(){
|
||||
_,err=this.conn.Do("DEL",key)
|
||||
}
|
||||
}
|
||||
}
|
||||
return reData
|
||||
}
|
||||
//添加缓存
|
||||
if len(data) == 1 {
|
||||
|
||||
if this.Time == 0 {
|
||||
this.Time = Config.GetInt64("cacheShortTime")
|
||||
}
|
||||
|
||||
tim += this.Time
|
||||
}
|
||||
if len(data) == 2 {
|
||||
this.Error.SetError(nil)
|
||||
tempt := ObjToInt64(data[1], &this.Error)
|
||||
if this.GetError() == nil {
|
||||
|
||||
tim = tim + tempt
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
_,err=this.conn.Do("SET",key,ObjToStr(data[0]),"EX",ObjToStr(tim))
|
||||
if err!=nil{
|
||||
|
||||
this.Error.SetError(err)
|
||||
_,err=this.conn.Do("PING")
|
||||
if err!=nil{
|
||||
if this.reCon(){
|
||||
_,err=this.conn.Do("SET",key,ObjToStr(data[0]),"EX",ObjToStr(tim))
|
||||
}
|
||||
}
|
||||
}
|
||||
return reData
|
||||
|
||||
}
|
@ -30,6 +30,24 @@ func (this *CacheMemory) get(key string) interface{} {
|
||||
return data.data
|
||||
}
|
||||
|
||||
func (this *CacheMemory)refreshMap(){
|
||||
|
||||
go func() {
|
||||
this.mutex.Lock()
|
||||
defer this.mutex.Unlock()
|
||||
for key,v:=range this.Map{
|
||||
data:=v.(cacheData)
|
||||
if data.time <= time.Now().Unix() {
|
||||
delete(this.Map, key)
|
||||
}
|
||||
}
|
||||
|
||||
}()
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//key value ,时间为时间戳
|
||||
func (this *CacheMemory) set(key string, value interface{}, time int64) {
|
||||
this.Error.SetError(nil)
|
||||
@ -58,6 +76,11 @@ func (this *CacheMemory) delete(key string) {
|
||||
|
||||
func (this *CacheMemory) Cache(key string, data ...interface{}) *Obj {
|
||||
|
||||
|
||||
x:=RandX(1,100000)
|
||||
if x>99950{
|
||||
this.refreshMap()
|
||||
}
|
||||
if this.mutex==nil{
|
||||
this.mutex=&sync.RWMutex{}
|
||||
}
|
||||
|
@ -1,59 +0,0 @@
|
||||
package hotime
|
||||
|
||||
import (
|
||||
"time"
|
||||
"sync"
|
||||
"github.com/garyburd/redigo/redis"
|
||||
)
|
||||
|
||||
type CacheRedis struct {
|
||||
Time int64
|
||||
redis.Conn
|
||||
contextBase
|
||||
}
|
||||
|
||||
func (this *CacheRedis) Cache(key string, data ...interface{}) *Obj {
|
||||
|
||||
redis.Dial()
|
||||
|
||||
reData:= &Obj{}
|
||||
|
||||
|
||||
if len(data) == 0 {
|
||||
this.mutex.RLock()
|
||||
reData.Data=this.get(key)
|
||||
this.mutex.RUnlock()
|
||||
return reData
|
||||
}
|
||||
tim := time.Now().Unix()
|
||||
|
||||
if len(data) == 1 && data[0] == nil {
|
||||
this.mutex.Lock()
|
||||
this.delete(key)
|
||||
this.mutex.Unlock()
|
||||
return reData
|
||||
}
|
||||
|
||||
if len(data) == 1 {
|
||||
|
||||
if this.Time == 0 {
|
||||
this.Time = Config.GetInt64("cacheShortTime")
|
||||
}
|
||||
|
||||
tim += this.Time
|
||||
}
|
||||
if len(data) == 2 {
|
||||
this.Error.SetError(nil)
|
||||
tempt := ObjToInt64(data[1], &this.Error)
|
||||
if this.GetError() == nil {
|
||||
|
||||
tim = tim + tempt
|
||||
|
||||
}
|
||||
}
|
||||
this.mutex.Lock()
|
||||
this.set(key, data[0], tim)
|
||||
this.mutex.Unlock()
|
||||
return reData
|
||||
|
||||
}
|
@ -6,9 +6,6 @@
|
||||
"dbPort": "3306",
|
||||
"dbPwd": "root",
|
||||
"dbUser": "root",
|
||||
"redisPort":"6379",
|
||||
"redisHost":"192.168.6.254",
|
||||
"redisPwd":"9rusdfjk482fjdfo2e023",
|
||||
"defFile": [
|
||||
"index.html",
|
||||
"index.htm"
|
||||
@ -16,6 +13,9 @@
|
||||
"error": {},
|
||||
"logLevel": 0,
|
||||
"port": "80",
|
||||
"redisHost": "192.168.6.254:6379",
|
||||
"redisPort": "6379",
|
||||
"redisPwd": "9rusdfjk482fjdfo2e023",
|
||||
"sessionName": "HOTIME",
|
||||
"tpt": "example/tpt"
|
||||
}
|
@ -5,13 +5,20 @@ import (
|
||||
"fmt"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"go.hoteas.com/hotime"
|
||||
"go.hoteas.com/hotime/cache"
|
||||
"golang.org/x/net/websocket"
|
||||
"github.com/garyburd/redigo/redis"
|
||||
)
|
||||
|
||||
func main() {
|
||||
hotime.CacheRedis{nil,redis.Dial()}
|
||||
|
||||
|
||||
|
||||
|
||||
appIns := hotime.Application{}
|
||||
|
||||
|
||||
|
||||
|
||||
i := 0
|
||||
|
||||
appIns.SetConnectListener(func(context *hotime.Context) bool {
|
||||
@ -23,6 +30,16 @@ func main() {
|
||||
|
||||
//手动模式,
|
||||
appIns.SetConfig("example/config/config.json")
|
||||
|
||||
|
||||
ca:=hotime.CacheIns(&cache.CacheRedis{Host:appIns.Config.GetString("redisHost"),Pwd:appIns.Config.GetString("redisPwd"),Time:appIns.Config.GetCeilInt64("cacheLongTime")})
|
||||
|
||||
ca.Cache("x",hotime.Map{"1":"2132"})
|
||||
fmt.Println(ca.Cache("x").ToMap())
|
||||
fmt.Println(ca.Cache("x",nil).Data)
|
||||
fmt.Println(ca.Cache("x",nil).Data)
|
||||
fmt.Println(ca.Cache("x").Data)
|
||||
fmt.Println(ca.Cache("x").Data)
|
||||
appIns.SetConnectDB(func(err ...*hotime.Error) *sql.DB {
|
||||
query := appIns.Config.GetString("dbUser") + ":" + appIns.Config.GetString("dbPwd") +
|
||||
"@tcp(" + appIns.Config.GetString("dbHost") + ":" + appIns.Config.GetString("dbPort") + ")/" + appIns.Config.GetString("dbName") + "?charset=utf8"
|
||||
|
6
type.go
6
type.go
@ -6,9 +6,9 @@ type Proj map[string]Ctr
|
||||
type Router map[string]Proj
|
||||
|
||||
type CacheIns interface {
|
||||
set(key string, value interface{}, time int64)
|
||||
get(key string) interface{}
|
||||
delete(key string)
|
||||
//set(key string, value interface{}, time int64)
|
||||
//get(key string) interface{}
|
||||
//delete(key string)
|
||||
Cache(key string, data ...interface{}) *Obj
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user