/* Checks if user is in the database. */ bool cfDatabase::isInDatabase(std::string uid) { connectDatabase(); std::string input = "SELECT * FROM users;"; if(sqlite3_exec(db, input.c_str(), callback, 0, &errMsg) == 1) std::cout << "[ERROR]:" << sqlite3_errmsg(db) << "\n"; for(unsigned long int i(0); i != users.uCount; i++) { if(users.uid.at(i) == uid) { disconnectDatabase(); return true; } } disconnectDatabase(); return false; }
void cfDatabase::addUser(std::string uid, std::string name) { connectDatabase(); std::string input = "INSERT INTO users(uid, name) VALUES(\""+uid+"\", \""+name+"\");"; if(sqlite3_exec(db, input.c_str(), callback, 0, &errMsg) == 1) std::cout << "[ERROR]:" << sqlite3_errmsg(db) << "\n"; disconnectDatabase(); }
void *__db_function(void* thread_input){ char * ip = ((thread_struct*)thread_input)->in_ip; int port = ((thread_struct*)thread_input)->in_port; int my_tid = ((thread_struct*)thread_input)->tid; /* *each thread has its own value and cluster struct. */ char* value = (char*)malloc(1024*8); char* key = (char*)malloc(100); clusterInfo *cluster = connectRedis(ip,port); if(cluster!=NULL){ printf("connected to cluster\n"); } else{ printf("cluster==null\n"); exit(0); } int sum = 0; sprintf(key,"key=%d",my_tid); sprintf(value,"%s","aaaaa"); sum += set(cluster,key,value,1,my_tid); sum += get(cluster,key,value,1,my_tid); printf("get %s: %s\n",key,value); sprintf(value,"%s","ffffff"); sum += set(cluster,key,value,1,my_tid); sum += get(cluster,key,value,1,my_tid); printf("get %s:%s\n",key,value); sprintf(value,"%s","aefde"); sum += set(cluster,key,value,1,my_tid); sum += get(cluster,key,value,1,my_tid); printf("get %s: %s\n",key,value); sprintf(value,"%s","abcdefads"); sum += set(cluster,key,value,1,my_tid); sum += get(cluster,key,value,1,my_tid); printf("get %s: %s\n",key,value); if(sum == 0) printf("all operations succeed!\n"); else printf("operation fail\n"); disconnectDatabase(cluster); }
void cfDatabase::modifyUser(std::string id, std::string name) { printFull(); connectDatabase(); std::string input = "UPDATE users SET name=\""+name+"\" WHERE ID="+id+";"; if(sqlite3_exec(db, input.c_str(), callback, 0, &errMsg) == 1) std::cout << "[ERROR]:" << sqlite3_errmsg(db) << "\n"; disconnectDatabase(); }
void cfDatabase::deleteUser(std::string id) { printFull(); connectDatabase(); std::string input = "DELETE FROM users WHERE ID="+id+";"; if(sqlite3_exec(db, input.c_str(), callback, 0, &errMsg) == 1) std::cout << "[ERROR]:" << sqlite3_errmsg(db) << "\n"; disconnectDatabase(); }
void* __thread_pipeline_test(void *thread_input) { char * ip = ((thread_struct*)thread_input)->in_ip; int port = ((thread_struct*)thread_input)->in_port; int my_tid = ((thread_struct*)thread_input)->tid; clusterInfo *cluster = connectRedis("192.168.1.22",6667); if(cluster == NULL) { printf("unable to connect to cluster\n"); }else { printf("connection succeed\n"); } int step = ((thread_struct*)thread_input)->step; //three steps before using a cluster mode pipeline clusterPipe *mypipe = get_pipeline(); set_pipeline_count(mypipe,PIPE_TEST_COUNT); bind_pipeline_to_cluster(cluster,mypipe); char key[256],value[256]; int count = 0; int init = (my_tid/step - 1)*step; printf("tid=%d start=%d end=%d\n",my_tid,init,my_tid); for(int i=init;i<my_tid;i++) { sprintf(key,"key=%d",i); sprintf(value,"value=%d",i); //we have a key and value here, so we can use the pipeline count++; if(count<PIPE_TEST_COUNT){ cluster_pipeline_set(cluster,mypipe,key,value); }else{ cluster_pipeline_set(cluster,mypipe,key,value); count=0; cluster_pipeline_flushBuffer(cluster,mypipe); int inner = 0; for(;inner<PIPE_TEST_COUNT;inner++) { redisReply *reply = cluster_pipeline_getReply(cluster,mypipe); if(reply == NULL) { printf("NULL reply in %d\n",i); }else{ freeReplyObject(reply); } } cluster_pipeline_complete(cluster,mypipe); reset_pipeline_count(mypipe,PIPE_TEST_COUNT); } } disconnectDatabase(cluster); return (void*)0; }
void cfDatabase::printFull() { connectDatabase(); std::string input = "SELECT * FROM users;"; if(sqlite3_exec(db, input.c_str(), callback, 0, &errMsg) == 1) std::cout << "[ERROR]:" << sqlite3_errmsg(db) << "\n"; std::cout << "USER LIST START:\n\n"; for(unsigned long int i(0); i != users.uCount; i++) { std::cout << "ID:" << users.id.at(i) << " |UID:" << users.uid.at(i) << " |NAME:" << users.name.at(i) << "\n"; } std::cout << "\n\nUSER LIST END:\n\n"; disconnectDatabase(); }
void disconnect_after_connect(){ init_global(); clusterInfo *cluster = connectRedis("127.0.0.1",6667); if(cluster != NULL) { printf("connected to cluster\n"); }else{ printf("panic\n"); } char key[10] = "key"; char value[10] = "value"; set(cluster,key,value,1,1); get(cluster,key,value,1,1); printf("get value= %s\n",value); disconnectDatabase(cluster); release_global(); }
void GTUtilsSharedDatabaseDocument::disconnectDatabase(HI::GUITestOpStatus &os, Document *databaseDoc) { Q_UNUSED(os); GT_CHECK(NULL != databaseDoc, "databaseDoc is NULL"); disconnectDatabase(os, databaseDoc->getName()); }
int main(){ clusterInfo *cluster = connectRedis("192.168.1.22",6667); if(cluster == NULL) { printf("unable to connect to cluster\n"); }else{ printf("connection succeed\n"); } clusterPipe* mypipe = get_pipeline(); set_pipeline_count(mypipe,20); bind_pipeline_to_cluster(cluster,mypipe); cluster_pipeline_get(cluster,mypipe,"k1"); cluster_pipeline_get(cluster,mypipe,"k2"); cluster_pipeline_get(cluster,mypipe,"k3"); cluster_pipeline_get(cluster,mypipe,"k4"); cluster_pipeline_get(cluster,mypipe,"k5"); cluster_pipeline_get(cluster,mypipe,"k6"); cluster_pipeline_get(cluster,mypipe,"k7"); cluster_pipeline_get(cluster,mypipe,"k8"); cluster_pipeline_get(cluster,mypipe,"k9"); cluster_pipeline_get(cluster,mypipe,"k10"); cluster_pipeline_get(cluster,mypipe,"k11"); cluster_pipeline_get(cluster,mypipe,"k12"); cluster_pipeline_get(cluster,mypipe,"k13"); cluster_pipeline_get(cluster,mypipe,"k14"); cluster_pipeline_get(cluster,mypipe,"k15"); cluster_pipeline_get(cluster,mypipe,"k16"); cluster_pipeline_get(cluster,mypipe,"k17"); cluster_pipeline_get(cluster,mypipe,"k18"); cluster_pipeline_get(cluster,mypipe,"k19"); cluster_pipeline_get(cluster,mypipe,"k20"); cluster_pipeline_flushBuffer(cluster,mypipe); int i; for (i=0;i<20;i++) { redisReply* reply = cluster_pipeline_getReply(cluster,mypipe); if(reply == NULL) { printf("NULL reply\n"); continue; } printf("%s\n",reply->str); freeReplyObject(reply); } cluster_pipeline_complete(cluster,mypipe); printf("set a new pipeline hahahaha .......\n"); set_pipeline_count(mypipe,10); cluster_pipeline_get(cluster,mypipe,"k11"); cluster_pipeline_get(cluster,mypipe,"k12"); cluster_pipeline_get(cluster,mypipe,"k13"); cluster_pipeline_get(cluster,mypipe,"k14"); cluster_pipeline_get(cluster,mypipe,"k15"); cluster_pipeline_get(cluster,mypipe,"k16"); cluster_pipeline_get(cluster,mypipe,"k17"); cluster_pipeline_get(cluster,mypipe,"k18"); cluster_pipeline_get(cluster,mypipe,"k19"); cluster_pipeline_get(cluster,mypipe,"k20"); cluster_pipeline_flushBuffer(cluster,mypipe); for (i=0;i<10;i++) { redisReply* reply = cluster_pipeline_getReply(cluster,mypipe); if(reply == NULL) { printf("NULL reply\n"); continue; } printf("%s\n",reply->str); freeReplyObject(reply); } cluster_pipeline_complete(cluster,mypipe); disconnectDatabase(cluster); return 0; }