forked from RedisLabs/memtier_benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
item.cpp
153 lines (127 loc) · 2.94 KB
/
item.cpp
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* Copyright (C) 2011-2017 Redis Labs Ltd.
*
* This file is part of memtier_benchmark.
*
* memtier_benchmark is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
*
* memtier_benchmark is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with memtier_benchmark. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include "item.h"
memcache_item::memcache_item(unsigned int dumpflags, time_t time,
time_t exptime,
unsigned short flags,
unsigned int nsuffix,
unsigned int clsid) :
m_dumpflags(dumpflags), m_time(time), m_exptime(exptime),
m_flags(flags), m_nsuffix(nsuffix), m_clsid(clsid),
m_version(0)
{
m_key = NULL;
m_data = NULL;
}
memcache_item::~memcache_item()
{
if (m_key != NULL)
free(m_key);
if (m_data != NULL)
free(m_data);
}
/** \brief set a memcache_item's key.
* \param key pointer to malloc() allocated key data.
* \param nkey length of key.
*/
void memcache_item::set_key(char *key, unsigned int nkey)
{
if (m_key != NULL)
free(m_key);
m_nkey = nkey;
m_key = key;
}
/** \brief set a memcache_item's data.
* \param data pointer to malloc() allocated data.
* \param nbytes length of data.
*/
void memcache_item::set_data(char *data, unsigned int nbytes)
{
if (m_data != NULL)
free(m_data);
m_nbytes = nbytes;
m_data = data;
}
char* memcache_item::get_key(void)
{
return m_key;
}
unsigned int memcache_item::get_nkey(void)
{
return m_nkey;
}
char* memcache_item::get_data(void)
{
return m_data;
}
unsigned int memcache_item::get_nbytes(void)
{
return m_nbytes;
}
void memcache_item::set_version(unsigned long int version)
{
m_version = version;
}
unsigned long int memcache_item::get_version(void)
{
return m_version;
}
time_t memcache_item::get_time(void)
{
return m_time;
}
time_t memcache_item::get_exptime(void)
{
return m_exptime;
}
unsigned int memcache_item::get_dumpflags(void)
{
return m_dumpflags;
}
unsigned short memcache_item::get_flags(void)
{
return m_flags;
}
unsigned int memcache_item::get_nsuffix(void)
{
return m_nsuffix;
}
unsigned int memcache_item::get_clsid(void)
{
return m_clsid;
}
bool memcache_item::is_expired(void)
{
return ((m_dumpflags & ITEM_DUMPFLAGS_EXPIRED) == ITEM_DUMPFLAGS_EXPIRED);
}
int memcache_item::operator<(const memcache_item& a)
{
if (this->m_time < a.m_time)
return 1;
else
return 0;
}
int memcache_item_ptr_cmp(memcache_item *a, memcache_item *b)
{
return (*a < *b);
}