forked from mrpi/redis-cplusplus-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_distributed_strings.cpp
More file actions
80 lines (65 loc) · 2.2 KB
/
Copy pathtest_distributed_strings.cpp
File metadata and controls
80 lines (65 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "functions.h"
#include "../redisclient.h"
void test_distributed_strings(redis::client & c)
{
redis::distributed_string sh_str1("sh_str1", c);
test("not existing distributed_string");
{
// Check uninitialized/missing string
ASSERT_EQUAL(sh_str1.exists(), false);
ASSERT_EQUAL(sh_str1 == redis::client::missing_value(), true);
ASSERT_EQUAL(sh_str1 != "asdf", true);
}
test("empty distributed_string");
{
// Check initialized empty string
sh_str1 = "";
ASSERT_EQUAL(sh_str1.exists(), true);
ASSERT_EQUAL(sh_str1 == "", true);
ASSERT_EQUAL(sh_str1 != "asdf", true);
}
test("initialized distributed_string");
{
// Check initialized string
sh_str1 = "asdf";
ASSERT_EQUAL(sh_str1.exists(), true);
ASSERT_EQUAL(sh_str1 != redis::client::missing_value(), true);
ASSERT_EQUAL(sh_str1 != "", true);
ASSERT_EQUAL(sh_str1 == "asdf", true);
}
test("append to distributed_string");
{
sh_str1.append("123");
ASSERT_EQUAL(sh_str1 == "asdf123", true);
sh_str1 += "456";
ASSERT_EQUAL(sh_str1 == "asdf123456", true);
}
test("substr on distributed_string");
{
ASSERT_EQUAL(sh_str1.substr(0, 3), string("asdf"));
ASSERT_EQUAL(sh_str1.substr(4, 7), string("1234"));
}
string str1 = sh_str1;
ASSERT_EQUAL(str1, sh_str1.str());
sh_str1.del();
ASSERT_EQUAL(sh_str1.exists(), false);
ASSERT_EQUAL(sh_str1.setnx("asdf"), true);
ASSERT_EQUAL(sh_str1.setnx("asdf123"), false);
cerr << "Time to life of 'sh_str1': " << sh_str1.ttl() << endl;
ASSERT_EQUAL(sh_str1.ttl(), -1);
sh_str1.expire(100);
int ttl = sh_str1.ttl();
ASSERT_EQUAL(ttl > 0, true);
sleep(1);
ASSERT_EQUAL(ttl > sh_str1.ttl(), true);
ASSERT_EQUAL(sh_str1.type(), redis::client::datatype_string);
string oldVal = sh_str1.getset("asdf123");
ASSERT_EQUAL(oldVal, string("asdf"));
ASSERT_EQUAL(sh_str1.str(), string("asdf123"));
redis::distributed_string sh_str2("sh_str2", "asdf123", c);
ASSERT_EQUAL(sh_str1, sh_str2);
sh_str2 = "asdf123456";
ASSERT_NOT_EQUAL(sh_str1, sh_str2);
sh_str1 = sh_str2;
ASSERT_EQUAL(sh_str1, sh_str2);
}