|
3 | 3 |
|
4 | 4 | ## 介绍 |
5 | 5 | 1. 基于boost库的asio异步编程 |
6 | | -1. 支持string、list、set |
| 6 | +1. 支持string、list、set、hash、zset五种数据结构 |
7 | 7 | ## 说明 |
8 | 8 | 1. 使用c++11以及以上编译(若c++11编译不过,请用c++14) |
9 | 9 | ## 使用列子 |
| 10 | +```cpp |
| 11 | +#include <iostream> |
| 12 | +#include <cppredis/client.hpp> |
| 13 | +//string请求 |
| 14 | +cpp_redis::redis_client<cpp_redis::String> client; |
| 15 | +bool falg = client.connect_to(IP地址,端口,redis密码); |
| 16 | +int a = 0; |
| 17 | +falg = client.set_db_num(a); |
| 18 | +falg = client.setex("name", "yinpinghua", 30); |
| 19 | +falg = client.set("name", "yinpinghua"); |
| 20 | +auto result = client.incr("name1"); |
| 21 | +auto result1 = client.decr("name1"); |
| 22 | +falg = client.delete_key("name1"); |
| 23 | +falg = client.is_key_exist("name1"); |
| 24 | +auto value =client.get_reflect_value("name"); |
| 25 | + |
| 26 | +falg = client.expire("name1",30); |
| 27 | +falg = client.expire_at("name", 1587468798); |
| 28 | +client.setex("name4", "112345", 60); |
| 29 | + |
| 30 | +auto expire = client.remainder_ttl("name4"); |
| 31 | + |
| 32 | +std::string str1 = client.get_set_key("name","5678941"); |
| 33 | + |
| 34 | +client.substr_reflect_value("name", 0, 5); |
| 35 | +auto vecs1 =client.multi_get_keys("name"); |
| 36 | +auto vecs2= client.multi_get_keys("name", "name1"); |
| 37 | +auto vecs3 = client.multi_get_keys("name", "name1", "name2"); |
| 38 | + |
| 39 | +client.multi_set_if_not_set("name", "1234", "name1", "456", "name3", "789","name4","562450"); |
| 40 | + |
| 41 | +client.multi_set_keys("name", "1234", "name1", "456", "name3", "789", "name4", "562450"); |
| 42 | +client.append_value("name4", "123456789"); |
| 43 | +client.set("name1234", "456789"); |
| 44 | +client.expire("name1234", 60); |
| 45 | +//list请求 |
| 46 | +cpp_redis::redis_client<cpp_redis::List> client; |
| 47 | +bool falg = client.connect_to(IP地址,端口,redis密码); |
| 48 | +client.list_rpush("name2", "5678945"); |
| 49 | +client.list_lpush("name222", "5678945"); |
| 50 | + |
| 51 | +client.list_size("name2221234"); |
| 52 | +client.list_lpop("name222"); |
| 53 | +client.list_rpush("name22", "12"); |
| 54 | +client.list_rpush("name22", "4562145"); |
| 55 | +client.list_rpush("name22", "56"); |
| 56 | +client.list_rpush("name22", "78"); |
| 57 | + |
| 58 | +client.list_lpush("name22", "78"); |
| 59 | +client.list_lpush("name22", "56"); |
| 60 | +client.list_lpush("name22", "34"); |
| 61 | +client.list_lpush("name22", "12"); |
| 62 | +auto reslut =client.list_rpoplpush("name22", "name"); |
| 63 | +client.list_rpush("name22", "78"); |
| 64 | +client.list_lpop("name22"); |
| 65 | + |
| 66 | +client.list_lpush_if("name22", "12"); |
| 67 | +client.list_del_elem("name22","56",-1); |
| 68 | + |
| 69 | +auto res = client.list_insert_after("name", "98", "123456790"); |
| 70 | + |
| 71 | +auto res = client.list_brpoplpush("name","name2345",20); |
| 72 | +auto err = client.get_current_error(); |
| 73 | + |
| 74 | +//set请求 |
| 75 | +cpp_redis::redis_client<cpp_redis::Set> client; |
| 76 | +bool falg = client.connect_to(IP地址,端口,redis密码); |
| 77 | +auto res = client.set_add("name", "1234", "5678","910245","78945"); |
| 78 | +auto res1 = client.set_delete_elem("name", "1234", "5678"); |
| 79 | +auto res = client.set_is_member("name", "78945"); |
| 80 | +auto res1 = client.set_rand_elem("name111",2); |
| 81 | + |
| 82 | +auto res1 = client.set_move_elem("name", "name1", "7894511111"); |
| 83 | + |
| 84 | +auto res1 = client.set_get_size("name111"); |
| 85 | + |
| 86 | +auto res1 = client.set_sinter("name","name1"); |
| 87 | + |
| 88 | +auto res1 = client.set_union_store("name3","name","name2"); |
| 89 | + |
| 90 | +auto res12 = client.set_diff( "name", "name2"); |
| 91 | + |
| 92 | +auto res1 = client.set_diff_store("name4","name", "name1"); |
| 93 | + |
| 94 | +//Zset请求 |
| 95 | +cpp_redis::redis_client<cpp_redis::ZSet> client; |
| 96 | +bool falg = client.connect_to(IP地址,端口,redis密码); |
| 97 | + |
| 98 | +auto res = client.zset_add("name", 1, "12345", 2, 56); |
| 99 | +std::string store = "yinpinghua"; |
| 100 | +auto res2 = client.zset_incrby("name",2,"yinpinghua"); |
| 101 | +std::string error = client.get_current_error(); |
| 102 | +int i = client.zset_count("name"); |
| 103 | +auto count = client.zset_range_counts("name", 1, 4); |
| 104 | +auto res1 = client.zset_range("name", 1, 2,false); |
| 105 | +auto res1 = client.zset_revrrank("name", 0, 1); |
| 106 | + |
| 107 | +auto res1 = client.zset_range_score("name",0,1,false,true); |
| 108 | + |
| 109 | +auto res1 = client.zset_revrange_score("name", 7, 0,true); |
| 110 | + |
| 111 | +auto res1 = client.zset_rank("name","sp1"); |
| 112 | +auto res = client.zset_rank("name", "yinpinghua"); |
| 113 | +auto res1 = client.zset_revrank("name", "yinpinghua"); |
| 114 | + |
| 115 | +auto res1 = client.zset_rem("name", "yinpinghua","sp",1); |
| 116 | + |
| 117 | +std::string str = "yinpinghua"; |
| 118 | +auto res1 = client.zset_add("name",1, &str[0], 2, "sp", 1.25, "shagua"); |
| 119 | + |
| 120 | +auto res = client.zset_remrangeby_rank("name", 1, 2); |
| 121 | + |
| 122 | +auto res = client.zset_remrangebyscore("name", 1, 2); |
| 123 | +std::string str = "yinpinghua"; |
| 124 | +auto res1 = client.zset_add("name", 1, &str[0], 2, "sp", 1.25, "shagua"); |
| 125 | + |
| 126 | +auto res = client.zset_rangebylex("name1","[1", "[3"); |
| 127 | +auto res = client.zset_lexcount("name1", "[1", "[3"); |
| 128 | + |
| 129 | +auto res = client.zset_remrangebylex("name1", "[1", "[3"); |
| 130 | +auto res = client.zset_union_store("name4", 2, cpp_redis::aggregate_mothod::agg_sum,0,1,"name", "name2"); |
| 131 | +auto res = client.zset_inter_store("name6", 2, cpp_redis::aggregate_mothod::agg_sum, 0, 1, "name", "name2"; |
| 132 | + |
| 133 | +//hash请求 |
| 134 | +cpp_redis::redis_client<cpp_redis::Hash> client; |
| 135 | +bool falg = client.connect_to(IP地址,端口,redis密码); |
| 136 | + |
| 137 | +auto res = client.hash_set("name", false, "123456"); |
| 138 | +auto res = client.hash_setx("name", 12, "123456"); |
| 139 | + |
| 140 | +auto res = client.hash_setx("name", 12, "123456"); |
| 141 | + |
| 142 | +auto res = client.hash_exists("name", false); |
| 143 | + |
| 144 | +std::string field; |
| 145 | +auto res = client.hash_get("name", 1); |
| 146 | + |
| 147 | +auto res1 = client.hash_set("db", 123, "redis.com"); |
| 148 | +auto res = client.hash_del("name", false); |
| 149 | + |
| 150 | +auto res = client.hash_len("db"); |
| 151 | + |
| 152 | +std::string key = "db"; |
| 153 | +std::string files = "123"; |
| 154 | + |
| 155 | +auto res = client.hash_strlen(std::move(key), files); |
| 156 | + |
| 157 | +auto res = client.hash_incrby(std::move(key), files, 40); |
| 158 | +auto res1 = client.hash_incrby(std::move(key), false, 40); |
| 159 | + |
| 160 | +auto res112 = client.hash_incrby_float(std::move(key), 456, 1.22f); |
| 161 | +float f = 1.23f; |
| 162 | +auto res = client.hash_mset(std::move(key), "123456", 23, 4, 56, false, f); |
| 163 | + |
| 164 | +auto res = client.hash_mget(std::move(key), 1, 4, false, 123456); |
| 165 | +auto res = client.hash_keys(std::move(key)); |
| 166 | +auto res = client.hash_vals(std::move(key)); |
| 167 | + |
| 168 | +auto res = client.hash_get_all(std::move(key)); |
0 commit comments