Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
439120c6
Commit
439120c6
authored
Sep 06, 2017
by
antirez
Browse files
Streams: implement stream object release.
parent
ec9bbe96
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/object.c
View file @
439120c6
...
...
@@ -310,6 +310,10 @@ void freeModuleObject(robj *o) {
zfree
(
mv
);
}
void
freeStreamObject
(
robj
*
o
)
{
freeStream
(
o
->
ptr
);
}
void
incrRefCount
(
robj
*
o
)
{
if
(
o
->
refcount
!=
OBJ_SHARED_REFCOUNT
)
o
->
refcount
++
;
}
...
...
@@ -323,6 +327,7 @@ void decrRefCount(robj *o) {
case
OBJ_ZSET
:
freeZsetObject
(
o
);
break
;
case
OBJ_HASH
:
freeHashObject
(
o
);
break
;
case
OBJ_MODULE
:
freeModuleObject
(
o
);
break
;
case
OBJ_STREAM
:
freeStreamObject
(
o
);
break
;
default:
serverPanic
(
"Unknown object type"
);
break
;
}
zfree
(
o
);
...
...
src/rax.c
View file @
439120c6
...
...
@@ -1093,28 +1093,36 @@ int raxRemove(rax *rax, unsigned char *s, size_t len, void **old) {
/* This is the core of raxFree(): performs a depth-first scan of the
* tree and releases all the nodes found. */
void
raxRecursiveFree
(
rax
*
rax
,
raxNode
*
n
)
{
void
raxRecursiveFree
(
rax
*
rax
,
raxNode
*
n
,
void
(
*
free_callback
)(
void
*
)
)
{
debugnode
(
"free traversing"
,
n
);
int
numchildren
=
n
->
iscompr
?
1
:
n
->
size
;
raxNode
**
cp
=
raxNodeLastChildPtr
(
n
);
while
(
numchildren
--
)
{
raxNode
*
child
;
memcpy
(
&
child
,
cp
,
sizeof
(
child
));
raxRecursiveFree
(
rax
,
child
);
raxRecursiveFree
(
rax
,
child
,
free_callback
);
cp
--
;
}
debugnode
(
"free depth-first"
,
n
);
if
(
free_callback
&&
n
->
iskey
&&
!
n
->
isnull
)
free_callback
(
raxGetData
(
n
));
rax_free
(
n
);
rax
->
numnodes
--
;
}
/* Free a whole radix tree. */
void
raxFree
(
rax
*
rax
)
{
raxRecursiveFree
(
rax
,
rax
->
head
);
/* Free a whole radix tree, calling the specified callback in order to
* free the auxiliary data. */
void
raxFreeWithCallback
(
rax
*
rax
,
void
(
*
free_callback
)(
void
*
))
{
raxRecursiveFree
(
rax
,
rax
->
head
,
free_callback
);
assert
(
rax
->
numnodes
==
0
);
rax_free
(
rax
);
}
/* Free a whole radix tree. */
void
raxFree
(
rax
*
rax
)
{
raxFreeWithCallback
(
rax
,
NULL
);
}
/* ------------------------------- Iterator --------------------------------- */
/* Initialize a Rax iterator. This call should be performed a single time
...
...
src/rax.h
View file @
439120c6
...
...
@@ -148,6 +148,7 @@ int raxInsert(rax *rax, unsigned char *s, size_t len, void *data, void **old);
int
raxRemove
(
rax
*
rax
,
unsigned
char
*
s
,
size_t
len
,
void
**
old
);
void
*
raxFind
(
rax
*
rax
,
unsigned
char
*
s
,
size_t
len
);
void
raxFree
(
rax
*
rax
);
void
raxFreeWithCallback
(
rax
*
rax
,
void
(
*
free_callback
)(
void
*
));
void
raxStart
(
raxIterator
*
it
,
rax
*
rt
);
int
raxSeek
(
raxIterator
*
it
,
const
char
*
op
,
unsigned
char
*
ele
,
size_t
len
);
int
raxNext
(
raxIterator
*
it
);
...
...
src/server.h
View file @
439120c6
...
...
@@ -1419,6 +1419,7 @@ void signalListAsReady(redisDb *db, robj *key);
/* Stream data type. */
stream
*
streamNew
(
void
);
void
freeStream
(
stream
*
s
);
/* MULTI/EXEC/WATCH... */
void
unwatchAllKeys
(
client
*
c
);
...
...
src/t_stream.c
View file @
439120c6
...
...
@@ -51,6 +51,11 @@ stream *streamNew(void) {
return
s
;
}
/* Free a stream, including the listpacks stored inside the radix tree. */
void
freeStream
(
stream
*
s
)
{
raxFreeWithCallback
(
s
->
rax
,(
void
(
*
)(
void
*
))
lpFree
);
}
/* Generate the next stream item ID given the previous one. If the current
* milliseconds Unix time is greater than the previous one, just use this
* as time part and start with sequence part of zero. Otherwise we use the
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment