Commit 97d58ad0 authored by jan.koester's avatar jan.koester
Browse files

importend fix

parent d703a35a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -36,14 +36,14 @@ namespace blogi {
        Store(){};
        virtual ~Store(){};
        virtual void save(const std::string key,const std::vector<char> value)=0;
        virtual void load(const std::string key,std::string &value) =0;
        virtual void load(const std::string key,std::vector<char> &value) =0;
    };

    class RedisStore : public Store {
    public:
        RedisStore(const char *host,int port,const char *password=nullptr);
        void save(const std::string key,const std::vector<char> value) override;
        void load(const std::string key,std::string &value) override;
        void load(const std::string key,std::vector<char>  &value) override;
    private:
        bool reconnect();
        redisContext *_RedisCTX;
+2 −2
Original line number Diff line number Diff line
@@ -531,11 +531,11 @@ namespace blogi {

                if(n>0){
                    try{
                        std::string value;
                        std::vector<char> value;
                        _store->load(suuid,value);
                        curres.setContentType(res[0][0]);
                        curres.setState(HTTP200);
                        curres.send(req, value.c_str(), value.length());
                        curres.send(req, value.data(), value.size());
                    }catch(...){
                        curres.setState(HTTP404);
                        curres.send(req,nullptr,0);
+2 −3
Original line number Diff line number Diff line
@@ -67,12 +67,11 @@ REDISSAVE:
    }
}

void blogi::RedisStore::load(const std::string key,std::string &value) {
void blogi::RedisStore::load(const std::string key,std::vector<char> &value) {
REDISLOAD:
    redisReply* reply = (redisReply*) redisCommand(_RedisCTX, "GET %s",key.c_str());
    if(reply && reply->type!=REDIS_REPLY_ERROR){
        value.resize(reply->len);
        value.insert(0,reply->str,reply->len);
        std::copy(reply->str,reply->str+reply->len,std::inserter<std::vector<char>>(value,value.begin()));
    }else{
        if(reconnect())
            goto REDISLOAD;