Skip to content

Commit

Permalink
add return value for zadd
Browse files Browse the repository at this point in the history
  • Loading branch information
HustXrb authored and jobs committed Apr 21, 2017
1 parent 7dde711 commit d890337
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 6 deletions.
8 changes: 6 additions & 2 deletions hustdb/db/server/module/hustdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2722,6 +2722,8 @@ int hustdb_t::hustdb_zadd (
const char * key,
size_t key_len,
int64_t score,
std::string * & rsp,
int & rsp_len,
int opt,
uint32_t & ver,
uint32_t ttl,
Expand All @@ -2741,10 +2743,8 @@ int hustdb_t::hustdb_zadd (
char val21[ 32 ] = { };
uint32_t cur_ver = 0;
int64_t cur_score = 0;
int rsp_len = 0;
bool has_been = false;
item_ctxt_t * ctxt = NULL;
std::string * rsp = NULL;
is_version_error = false;

if ( unlikely ( ! tb_name_check ( table, table_len ) ||
Expand Down Expand Up @@ -2911,6 +2911,10 @@ int hustdb_t::hustdb_zadd (
LOG_ERROR ( "[hustdb][db_zadd][key=%p][key_len=%d]zadd return %d", key, ( int ) key_len, r );
return r;
}

rsp = m_mdb->buffer ( conn );
fast_memcpy ( ( char * ) & ( * rsp ) [ 0 ], val, val_len );
rsp_len = val_len;

return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions hustdb/db/server/module/hustdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,8 @@ class hustdb_t
const char * key,
size_t key_len,
int64_t score,
std::string * & rsp,
int & rsp_len,
int opt,
uint32_t & ver,
uint32_t ttl,
Expand Down
36 changes: 33 additions & 3 deletions hustdb/doc/doc/en/api/hustdb/hustdb/zadd.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,45 @@
**Result A2:**

HTTP/1.1 200 OK
Version: 1
VerError: false
Content-Length: 3
Content-Type: text/plain

100

**Sample B:**

curl -i -X GET "http://localhost:8085/hustdb/zadd?tb=test_table&score=101&key=test_key&ver=2"
curl -i -X GET "http://localhost:8085/hustdb/zadd?tb=test_table&score=10&key=test_key&opt=1"

**Result B1:**

HTTP/1.1 200 OK
Version: 2
VerError: false
Content-Length: 3
Content-Type: text/plain

110 //if original value of test_key is 100, 100 + 10 = 110

**Sample C:**

curl -i -X GET "http://localhost:8085/hustdb/zadd?tb=test_table&score=50&key=test_key&opt=-1"

**Result C1:**

HTTP/1.1 200 OK
Version: 3
VerError: false
Content-Length: 3
Content-Type: text/plain

110 //if original value of test_key is 110, 110 - 50 = 60

**Sample D:**

curl -i -X GET "http://localhost:8085/hustdb/zadd?tb=test_table&score=101&key=test_key&ver=2"

**Result D1:**

HTTP/1.1 401 Unauthorized
Version: 1
VerError: true
Expand Down
34 changes: 33 additions & 1 deletion hustdb/doc/doc/zh/api/hustdb/hustdb/zadd.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,45 @@
HTTP/1.1 200 OK
Version: 1
VerError: false
Content-Length: 3
Content-Type: text/plain

100

**使用范例B:**

curl -i -X GET "http://localhost:8085/hustdb/zadd?tb=test_table&score=101&key=test_key&ver=2"
curl -i -X GET "http://localhost:8085/hustdb/zadd?tb=test_table&score=10&key=test_key&opt=1"

**结果范例B1:**

HTTP/1.1 200 OK
Version: 2
VerError: false
Content-Length: 3
Content-Type: text/plain

110 //if original value of test_key is 100, 100 + 10 = 110

**使用范例C:**

curl -i -X GET "http://localhost:8085/hustdb/zadd?tb=test_table&score=50&key=test_key&opt=-1"

**结果范例C1:**

HTTP/1.1 200 OK
Version: 3
VerError: false
Content-Length: 3
Content-Type: text/plain

110 //if original value of test_key is 110, 110 - 50 = 60

**使用范例D:**

curl -i -X GET "http://localhost:8085/hustdb/zadd?tb=test_table&score=101&key=test_key&ver=2"

**结果范例D1:**

HTTP/1.1 401 Unauthorized
Version: 1
VerError: true
Expand Down

0 comments on commit d890337

Please sign in to comment.