Skip to content
This repository has been archived by the owner on Oct 27, 2021. It is now read-only.

Commit

Permalink
fix redis cache, Closes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
medcl committed Oct 9, 2020
1 parent 1bbc58b commit f12817b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 43 deletions.
2 changes: 0 additions & 2 deletions api/index_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ func (handler *API) handleRead(w http.ResponseWriter, req *http.Request, body []
var hash string

if handler.cacheConfig.CacheEnabled {

hash = getHash(handler.cacheConfig.KeyPrefix, req, body)

cache, err := handler.cacheHandler.Get(hash)
if len(cache) > 0 && err == nil {
if global.Env().IsDebug {
Expand Down
13 changes: 8 additions & 5 deletions api/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ type CacheHandler struct {
config *CacheConfig
client *redis.Client
}
var client *redis.Client

func (handler CacheHandler) Init() {

client := redis.NewClient(&redis.Options{
client = redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%s", handler.config.RedisConfig.Host, handler.config.RedisConfig.Port),
Password: handler.config.RedisConfig.Password,
DB: handler.config.RedisConfig.DB,
})

handler.client=client
_, err := client.Ping().Result()
if err != nil {
log.Error("cache server is not ready: ", err)
Expand All @@ -37,11 +38,13 @@ func (handler CacheHandler) Init() {
}

func (handler CacheHandler) Get(key string) ([]byte, error) {
return nil, nil
data,err:= client.Get(key).Bytes()
return data,err
}

func (handler CacheHandler) Set(string, []byte, int64) (bool, error) {
return false, nil
func (handler CacheHandler) Set(key string,data []byte,ttl int64) (bool, error) {
err:=client.Set(key,data, time.Duration(ttl)*time.Millisecond).Err()
return err==nil,err
}

type RedisConfig struct {
Expand Down
3 changes: 1 addition & 2 deletions modules/floating_ip/floating_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package floating_ip

import (
log "github.com/cihub/seelog"
"infini.sh/framework/core/api"
"infini.sh/framework/core/config"
"infini.sh/framework/core/env"
"infini.sh/framework/core/net"
Expand Down Expand Up @@ -58,7 +57,7 @@ func (module FloatingIPPlugin) Start() error {
panic(err)
}

apiConfig := &api.APIConfig{}
apiConfig := &config.APIConfig{}
env.ParseConfig("api", apiConfig)
log.Infof("high availability address: %s://%s:%s", apiConfig.GetSchema(), floatingIPConfig.IP, apiConfig.NetworkConfig.GetBindingPort())
return nil
Expand Down
37 changes: 3 additions & 34 deletions proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ api:
network:
binding: 0.0.0.0:2900
tls:
enabled: true
enabled: false

elasticsearch:
- name: default
Expand All @@ -32,8 +32,7 @@ cache:
plugins:
- name: proxy
enabled: true
ui_enabled: false
pass_through: ["_update","_search", "_count", "_analyze", "_mget", "_doc", "_mtermvectors", "_msearch", "_search_shards", "_suggest", "_validate", "_explain", "_field_caps", "_rank_eval", "_aliases"]
pass_through: []
upstream:
- name: primary
enabled: true
Expand All @@ -45,16 +44,9 @@ plugins:
max_queue_depth: -1
timeout: 60s
elasticsearch: default
- name: backup
enabled: false
cache_enabled: false
queue_name: backup
max_queue_depth: -1
timeout: 60s
elasticsearch: default

- name: floating_ip
enabled: true
enabled: false
ip: 192.168.1.222
netmask: 255.255.255.0
interface: en0
Expand All @@ -69,14 +61,6 @@ pipelines:
error:
joint: logging
enabled: true
- name: backup
start:
joint: index
enabled: true
process: []
error:
joint: logging
enabled: true


modules:
Expand All @@ -87,13 +71,6 @@ modules:
store_enabled: true
orm_enabled: true

- name: web
enabled: false
tls:
enabled: true
network:
binding: 127.0.0.1:9000

- name: pipeline
enabled: true
runners:
Expand All @@ -104,11 +81,3 @@ modules:
threshold_in_ms: 0
timeout_in_ms: 5000
pipeline_id: primary

- name: backup
enabled: true
input_queue: backup
max_go_routine: 1
threshold_in_ms: 0
timeout_in_ms: 5000
pipeline_id: backup

0 comments on commit f12817b

Please sign in to comment.