2012-11-08 12:25:23 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2009-2012, Salvatore Sanfilippo <antirez at gmail dot com>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* * Neither the name of Redis nor the names of its contributors may be used
|
|
|
|
* to endorse or promote products derived from this software without
|
|
|
|
* specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2015-07-26 09:14:57 -04:00
|
|
|
#include "server.h"
|
2013-10-09 09:37:20 -04:00
|
|
|
#include "cluster.h"
|
2015-09-28 04:47:45 -04:00
|
|
|
#include "atomicvar.h"
|
2010-06-21 18:07:48 -04:00
|
|
|
|
|
|
|
#include <signal.h>
|
2011-11-09 10:51:19 -05:00
|
|
|
#include <ctype.h>
|
2010-06-21 18:07:48 -04:00
|
|
|
|
2020-12-02 06:56:11 -05:00
|
|
|
/* Database backup. */
|
|
|
|
struct dbBackup {
|
|
|
|
redisDb *dbarray;
|
|
|
|
rax *slots_to_keys;
|
|
|
|
uint64_t slots_keys_count[CLUSTER_SLOTS];
|
|
|
|
};
|
|
|
|
|
2010-06-21 18:07:48 -04:00
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
* C-level DB API
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
|
2018-10-19 06:00:57 -04:00
|
|
|
int keyIsExpired(redisDb *db, robj *key);
|
|
|
|
|
2017-10-15 08:17:55 -04:00
|
|
|
/* Update LFU when an object is accessed.
|
|
|
|
* Firstly, decrement the counter if the decrement time is reached.
|
|
|
|
* Then logarithmically increment the counter, and update the access time. */
|
|
|
|
void updateLFU(robj *val) {
|
|
|
|
unsigned long counter = LFUDecrAndReturn(val);
|
|
|
|
counter = LFULogIncr(counter);
|
|
|
|
val->lru = (LFUGetTimeInMinutes()<<8) | counter;
|
|
|
|
}
|
|
|
|
|
2016-06-14 09:33:59 -04:00
|
|
|
/* Low level key lookup API, not actually called directly from commands
|
|
|
|
* implementations that should instead rely on lookupKeyRead(),
|
|
|
|
* lookupKeyWrite() and lookupKeyReadWithFlags(). */
|
|
|
|
robj *lookupKey(redisDb *db, robj *key, int flags) {
|
2010-06-21 18:07:48 -04:00
|
|
|
dictEntry *de = dictFind(db->dict,key->ptr);
|
|
|
|
if (de) {
|
2011-11-08 11:07:55 -05:00
|
|
|
robj *val = dictGetVal(de);
|
2010-06-21 18:07:48 -04:00
|
|
|
|
2013-01-16 12:00:20 -05:00
|
|
|
/* Update the access time for the ageing algorithm.
|
2010-11-02 13:59:48 -04:00
|
|
|
* Don't do it if we have a saving child, as this will trigger
|
|
|
|
* a copy on write madness. */
|
2019-09-27 06:03:09 -04:00
|
|
|
if (!hasActiveChildProcess() && !(flags & LOOKUP_NOTOUCH)){
|
2016-07-15 06:12:52 -04:00
|
|
|
if (server.maxmemory_policy & MAXMEMORY_FLAG_LFU) {
|
2017-10-15 08:17:55 -04:00
|
|
|
updateLFU(val);
|
2016-07-15 06:12:52 -04:00
|
|
|
} else {
|
|
|
|
val->lru = LRU_CLOCK();
|
|
|
|
}
|
2016-06-14 09:33:59 -04:00
|
|
|
}
|
2010-06-21 18:07:48 -04:00
|
|
|
return val;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-14 09:33:59 -04:00
|
|
|
/* Lookup a key for read operations, or return NULL if the key is not found
|
|
|
|
* in the specified DB.
|
|
|
|
*
|
|
|
|
* As a side effect of calling this function:
|
|
|
|
* 1. A key gets expired if it reached it's TTL.
|
|
|
|
* 2. The key last access time is updated.
|
|
|
|
* 3. The global keys hits/misses stats are updated (reported in INFO).
|
2019-03-21 14:33:11 -04:00
|
|
|
* 4. If keyspace notifications are enabled, a "keymiss" notification is fired.
|
2016-06-14 09:33:59 -04:00
|
|
|
*
|
|
|
|
* This API should not be used when we write to the key after obtaining
|
|
|
|
* the object linked to the key, but only for read only operations.
|
|
|
|
*
|
|
|
|
* Flags change the behavior of this command:
|
|
|
|
*
|
|
|
|
* LOOKUP_NONE (or zero): no special flags are passed.
|
|
|
|
* LOOKUP_NOTOUCH: don't alter the last access time of the key.
|
|
|
|
*
|
2018-06-21 10:08:09 -04:00
|
|
|
* Note: this function also returns NULL if the key is logically expired
|
2016-06-14 09:33:59 -04:00
|
|
|
* but still existing, in case this is a slave, since this API is called only
|
|
|
|
* for read operations. Even if the key expiry is master-driven, we can
|
|
|
|
* correctly report a key is expired on slaves even if the master is lagging
|
|
|
|
* expiring our key via DELs in the replication link. */
|
|
|
|
robj *lookupKeyReadWithFlags(redisDb *db, robj *key, int flags) {
|
2012-02-01 15:47:41 -05:00
|
|
|
robj *val;
|
|
|
|
|
Better read-only behavior for expired keys in slaves.
Slaves key expire is orchestrated by the master. Sometimes the master
will send the synthesized DEL to expire keys on the slave with a non
trivial delay (when the key is not accessed, only the incremental expiry
algorithm will expire it in background).
During that time, a key is logically expired, but slaves still return
the key if you GET (or whatever) it. This is a bad behavior.
However we can't simply trust the slave view of the key, since we need
the master to be able to send write commands to update the slave data
set, and DELs should only happen when the key is expired in the master
in order to ensure consistency.
However 99.99% of the issues with this behavior is when a client which
is not a master sends a read only command. In this case we are safe and
can consider the key as non existing.
This commit does a few changes in order to make this sane:
1. lookupKeyRead() is modified in order to return NULL if the above
conditions are met.
2. Calls to lookupKeyRead() in commands actually writing to the data set
are repliaced with calls to lookupKeyWrite().
There are redundand checks, so for example, if in "2" something was
overlooked, we should be still safe, since anyway, when the master
writes the behavior is to don't care about what expireIfneeded()
returns.
This commit is related to #1768, #1770, #2131.
2014-12-10 10:10:21 -05:00
|
|
|
if (expireIfNeeded(db,key) == 1) {
|
|
|
|
/* Key expired. If we are in the context of a master, expireIfNeeded()
|
2017-06-13 04:35:51 -04:00
|
|
|
* returns 0 only when the key does not exist at all, so it's safe
|
Better read-only behavior for expired keys in slaves.
Slaves key expire is orchestrated by the master. Sometimes the master
will send the synthesized DEL to expire keys on the slave with a non
trivial delay (when the key is not accessed, only the incremental expiry
algorithm will expire it in background).
During that time, a key is logically expired, but slaves still return
the key if you GET (or whatever) it. This is a bad behavior.
However we can't simply trust the slave view of the key, since we need
the master to be able to send write commands to update the slave data
set, and DELs should only happen when the key is expired in the master
in order to ensure consistency.
However 99.99% of the issues with this behavior is when a client which
is not a master sends a read only command. In this case we are safe and
can consider the key as non existing.
This commit does a few changes in order to make this sane:
1. lookupKeyRead() is modified in order to return NULL if the above
conditions are met.
2. Calls to lookupKeyRead() in commands actually writing to the data set
are repliaced with calls to lookupKeyWrite().
There are redundand checks, so for example, if in "2" something was
overlooked, we should be still safe, since anyway, when the master
writes the behavior is to don't care about what expireIfneeded()
returns.
This commit is related to #1768, #1770, #2131.
2014-12-10 10:10:21 -05:00
|
|
|
* to return NULL ASAP. */
|
2020-11-18 04:16:21 -05:00
|
|
|
if (server.masterhost == NULL)
|
|
|
|
goto keymiss;
|
Better read-only behavior for expired keys in slaves.
Slaves key expire is orchestrated by the master. Sometimes the master
will send the synthesized DEL to expire keys on the slave with a non
trivial delay (when the key is not accessed, only the incremental expiry
algorithm will expire it in background).
During that time, a key is logically expired, but slaves still return
the key if you GET (or whatever) it. This is a bad behavior.
However we can't simply trust the slave view of the key, since we need
the master to be able to send write commands to update the slave data
set, and DELs should only happen when the key is expired in the master
in order to ensure consistency.
However 99.99% of the issues with this behavior is when a client which
is not a master sends a read only command. In this case we are safe and
can consider the key as non existing.
This commit does a few changes in order to make this sane:
1. lookupKeyRead() is modified in order to return NULL if the above
conditions are met.
2. Calls to lookupKeyRead() in commands actually writing to the data set
are repliaced with calls to lookupKeyWrite().
There are redundand checks, so for example, if in "2" something was
overlooked, we should be still safe, since anyway, when the master
writes the behavior is to don't care about what expireIfneeded()
returns.
This commit is related to #1768, #1770, #2131.
2014-12-10 10:10:21 -05:00
|
|
|
|
|
|
|
/* However if we are in the context of a slave, expireIfNeeded() will
|
|
|
|
* not really try to expire the key, it only returns information
|
|
|
|
* about the "logical" status of the key: key expiring is up to the
|
|
|
|
* master in order to have a consistent view of master's data set.
|
|
|
|
*
|
|
|
|
* However, if the command caller is not the master, and as additional
|
|
|
|
* safety measure, the command invoked is a read-only command, we can
|
|
|
|
* safely return NULL here, and provide a more consistent behavior
|
Squash merging 125 typo/grammar/comment/doc PRs (#7773)
List of squashed commits or PRs
===============================
commit 66801ea
Author: hwware <wen.hui.ware@gmail.com>
Date: Mon Jan 13 00:54:31 2020 -0500
typo fix in acl.c
commit 46f55db
Author: Itamar Haber <itamar@redislabs.com>
Date: Sun Sep 6 18:24:11 2020 +0300
Updates a couple of comments
Specifically:
* RM_AutoMemory completed instead of pointing to docs
* Updated link to custom type doc
commit 61a2aa0
Author: xindoo <xindoo@qq.com>
Date: Tue Sep 1 19:24:59 2020 +0800
Correct errors in code comments
commit a5871d1
Author: yz1509 <pro-756@qq.com>
Date: Tue Sep 1 18:36:06 2020 +0800
fix typos in module.c
commit 41eede7
Author: bookug <bookug@qq.com>
Date: Sat Aug 15 01:11:33 2020 +0800
docs: fix typos in comments
commit c303c84
Author: lazy-snail <ws.niu@outlook.com>
Date: Fri Aug 7 11:15:44 2020 +0800
fix spelling in redis.conf
commit 1eb76bf
Author: zhujian <zhujianxyz@gmail.com>
Date: Thu Aug 6 15:22:10 2020 +0800
add a missing 'n' in comment
commit 1530ec2
Author: Daniel Dai <764122422@qq.com>
Date: Mon Jul 27 00:46:35 2020 -0400
fix spelling in tracking.c
commit e517b31
Author: Hunter-Chen <huntcool001@gmail.com>
Date: Fri Jul 17 22:33:32 2020 +0800
Update redis.conf
Co-authored-by: Itamar Haber <itamar@redislabs.com>
commit c300eff
Author: Hunter-Chen <huntcool001@gmail.com>
Date: Fri Jul 17 22:33:23 2020 +0800
Update redis.conf
Co-authored-by: Itamar Haber <itamar@redislabs.com>
commit 4c058a8
Author: 陈浩鹏 <chenhaopeng@heytea.com>
Date: Thu Jun 25 19:00:56 2020 +0800
Grammar fix and clarification
commit 5fcaa81
Author: bodong.ybd <bodong.ybd@alibaba-inc.com>
Date: Fri Jun 19 10:09:00 2020 +0800
Fix typos
commit 4caca9a
Author: Pruthvi P <pruthvi@ixigo.com>
Date: Fri May 22 00:33:22 2020 +0530
Fix typo eviciton => eviction
commit b2a25f6
Author: Brad Dunbar <dunbarb2@gmail.com>
Date: Sun May 17 12:39:59 2020 -0400
Fix a typo.
commit 12842ae
Author: hwware <wen.hui.ware@gmail.com>
Date: Sun May 3 17:16:59 2020 -0400
fix spelling in redis conf
commit ddba07c
Author: Chris Lamb <chris@chris-lamb.co.uk>
Date: Sat May 2 23:25:34 2020 +0100
Correct a "conflicts" spelling error.
commit 8fc7bf2
Author: Nao YONASHIRO <yonashiro@r.recruit.co.jp>
Date: Thu Apr 30 10:25:27 2020 +0900
docs: fix EXPIRE_FAST_CYCLE_DURATION to ACTIVE_EXPIRE_CYCLE_FAST_DURATION
commit 9b2b67a
Author: Brad Dunbar <dunbarb2@gmail.com>
Date: Fri Apr 24 11:46:22 2020 -0400
Fix a typo.
commit 0746f10
Author: devilinrust <63737265+devilinrust@users.noreply.github.com>
Date: Thu Apr 16 00:17:53 2020 +0200
Fix typos in server.c
commit 92b588d
Author: benjessop12 <56115861+benjessop12@users.noreply.github.com>
Date: Mon Apr 13 13:43:55 2020 +0100
Fix spelling mistake in lazyfree.c
commit 1da37aa
Merge: 2d4ba28 af347a8
Author: hwware <wen.hui.ware@gmail.com>
Date: Thu Mar 5 22:41:31 2020 -0500
Merge remote-tracking branch 'upstream/unstable' into expiretypofix
commit 2d4ba28
Author: hwware <wen.hui.ware@gmail.com>
Date: Mon Mar 2 00:09:40 2020 -0500
fix typo in expire.c
commit 1a746f7
Author: SennoYuki <minakami1yuki@gmail.com>
Date: Thu Feb 27 16:54:32 2020 +0800
fix typo
commit 8599b1a
Author: dongheejeong <donghee950403@gmail.com>
Date: Sun Feb 16 20:31:43 2020 +0000
Fix typo in server.c
commit f38d4e8
Author: hwware <wen.hui.ware@gmail.com>
Date: Sun Feb 2 22:58:38 2020 -0500
fix typo in evict.c
commit fe143fc
Author: Leo Murillo <leonardo.murillo@gmail.com>
Date: Sun Feb 2 01:57:22 2020 -0600
Fix a few typos in redis.conf
commit 1ab4d21
Author: viraja1 <anchan.viraj@gmail.com>
Date: Fri Dec 27 17:15:58 2019 +0530
Fix typo in Latency API docstring
commit ca1f70e
Author: gosth <danxuedexing@qq.com>
Date: Wed Dec 18 15:18:02 2019 +0800
fix typo in sort.c
commit a57c06b
Author: ZYunH <zyunhjob@163.com>
Date: Mon Dec 16 22:28:46 2019 +0800
fix-zset-typo
commit b8c92b5
Author: git-hulk <hulk.website@gmail.com>
Date: Mon Dec 16 15:51:42 2019 +0800
FIX: typo in cluster.c, onformation->information
commit 9dd981c
Author: wujm2007 <jim.wujm@gmail.com>
Date: Mon Dec 16 09:37:52 2019 +0800
Fix typo
commit e132d7a
Author: Sebastien Williams-Wynn <s.williamswynn.mail@gmail.com>
Date: Fri Nov 15 00:14:07 2019 +0000
Minor typo change
commit 47f44d5
Author: happynote3966 <01ssrmikururudevice01@gmail.com>
Date: Mon Nov 11 22:08:48 2019 +0900
fix comment typo in redis-cli.c
commit b8bdb0d
Author: fulei <fulei@kuaishou.com>
Date: Wed Oct 16 18:00:17 2019 +0800
Fix a spelling mistake of comments in defragDictBucketCallback
commit 0def46a
Author: fulei <fulei@kuaishou.com>
Date: Wed Oct 16 13:09:27 2019 +0800
fix some spelling mistakes of comments in defrag.c
commit f3596fd
Author: Phil Rajchgot <tophil@outlook.com>
Date: Sun Oct 13 02:02:32 2019 -0400
Typo and grammar fixes
Redis and its documentation are great -- just wanted to submit a few corrections in the spirit of Hacktoberfest. Thanks for all your work on this project. I use it all the time and it works beautifully.
commit 2b928cd
Author: KangZhiDong <worldkzd@gmail.com>
Date: Sun Sep 1 07:03:11 2019 +0800
fix typos
commit 33aea14
Author: Axlgrep <axlgrep@gmail.com>
Date: Tue Aug 27 11:02:18 2019 +0800
Fixed eviction spelling issues
commit e282a80
Author: Simen Flatby <simen@oms.no>
Date: Tue Aug 20 15:25:51 2019 +0200
Update comments to reflect prop name
In the comments the prop is referenced as replica-validity-factor,
but it is really named cluster-replica-validity-factor.
commit 74d1f9a
Author: Jim Green <jimgreen2013@qq.com>
Date: Tue Aug 20 20:00:31 2019 +0800
fix comment error, the code is ok
commit eea1407
Author: Liao Tonglang <liaotonglang@gmail.com>
Date: Fri May 31 10:16:18 2019 +0800
typo fix
fix cna't to can't
commit 0da553c
Author: KAWACHI Takashi <tkawachi@gmail.com>
Date: Wed Jul 17 00:38:16 2019 +0900
Fix typo
commit 7fc8fb6
Author: Michael Prokop <mika@grml.org>
Date: Tue May 28 17:58:42 2019 +0200
Typo fixes
s/familar/familiar/
s/compatiblity/compatibility/
s/ ot / to /
s/itsef/itself/
commit 5f46c9d
Author: zhumoing <34539422+zhumoing@users.noreply.github.com>
Date: Tue May 21 21:16:50 2019 +0800
typo-fixes
typo-fixes
commit 321dfe1
Author: wxisme <850885154@qq.com>
Date: Sat Mar 16 15:10:55 2019 +0800
typo fix
commit b4fb131
Merge: 267e0e6 3df1eb8
Author: Nikitas Bastas <nikitasbst@gmail.com>
Date: Fri Feb 8 22:55:45 2019 +0200
Merge branch 'unstable' of antirez/redis into unstable
commit 267e0e6
Author: Nikitas Bastas <nikitasbst@gmail.com>
Date: Wed Jan 30 21:26:04 2019 +0200
Minor typo fix
commit 30544e7
Author: inshal96 <39904558+inshal96@users.noreply.github.com>
Date: Fri Jan 4 16:54:50 2019 +0500
remove an extra 'a' in the comments
commit 337969d
Author: BrotherGao <yangdongheng11@gmail.com>
Date: Sat Dec 29 12:37:29 2018 +0800
fix typo in redis.conf
commit 9f4b121
Merge: 423a030 e504583
Author: BrotherGao <yangdongheng@xiaomi.com>
Date: Sat Dec 29 11:41:12 2018 +0800
Merge branch 'unstable' of antirez/redis into unstable
commit 423a030
Merge: 42b02b7 46a51cd
Author: 杨东衡 <yangdongheng@xiaomi.com>
Date: Tue Dec 4 23:56:11 2018 +0800
Merge branch 'unstable' of antirez/redis into unstable
commit 42b02b7
Merge: 68c0e6e b8febe6
Author: Dongheng Yang <yangdongheng11@gmail.com>
Date: Sun Oct 28 15:54:23 2018 +0800
Merge pull request #1 from antirez/unstable
update local data
commit 714b589
Author: Christian <crifei93@gmail.com>
Date: Fri Dec 28 01:17:26 2018 +0100
fix typo "resulution"
commit e23259d
Author: garenchan <1412950785@qq.com>
Date: Wed Dec 26 09:58:35 2018 +0800
fix typo: segfauls -> segfault
commit a9359f8
Author: xjp <jianping_xie@aliyun.com>
Date: Tue Dec 18 17:31:44 2018 +0800
Fixed REDISMODULE_H spell bug
commit a12c3e4
Author: jdiaz <jrd.palacios@gmail.com>
Date: Sat Dec 15 23:39:52 2018 -0600
Fixes hyperloglog hash function comment block description
commit 770eb11
Author: 林上耀 <1210tom@163.com>
Date: Sun Nov 25 17:16:10 2018 +0800
fix typo
commit fd97fbb
Author: Chris Lamb <chris@chris-lamb.co.uk>
Date: Fri Nov 23 17:14:01 2018 +0100
Correct "unsupported" typo.
commit a85522d
Author: Jungnam Lee <jungnam.lee@oracle.com>
Date: Thu Nov 8 23:01:29 2018 +0900
fix typo in test comments
commit ade8007
Author: Arun Kumar <palerdot@users.noreply.github.com>
Date: Tue Oct 23 16:56:35 2018 +0530
Fixed grammatical typo
Fixed typo for word 'dictionary'
commit 869ee39
Author: Hamid Alaei <hamid.a85@gmail.com>
Date: Sun Aug 12 16:40:02 2018 +0430
fix documentations: (ThreadSafeContextStart/Stop -> ThreadSafeContextLock/Unlock), minor typo
commit f89d158
Author: Mayank Jain <mayankjain255@gmail.com>
Date: Tue Jul 31 23:01:21 2018 +0530
Updated README.md with some spelling corrections.
Made correction in spelling of some misspelled words.
commit 892198e
Author: dsomeshwar <someshwar.dhayalan@gmail.com>
Date: Sat Jul 21 23:23:04 2018 +0530
typo fix
commit 8a4d780
Author: Itamar Haber <itamar@redislabs.com>
Date: Mon Apr 30 02:06:52 2018 +0300
Fixes some typos
commit e3acef6
Author: Noah Rosamilia <ivoahivoah@gmail.com>
Date: Sat Mar 3 23:41:21 2018 -0500
Fix typo in /deps/README.md
commit 04442fb
Author: WuYunlong <xzsyeb@126.com>
Date: Sat Mar 3 10:32:42 2018 +0800
Fix typo in readSyncBulkPayload() comment.
commit 9f36880
Author: WuYunlong <xzsyeb@126.com>
Date: Sat Mar 3 10:20:37 2018 +0800
replication.c comment: run_id -> replid.
commit f866b4a
Author: Francesco 'makevoid' Canessa <makevoid@gmail.com>
Date: Thu Feb 22 22:01:56 2018 +0000
fix comment typo in server.c
commit 0ebc69b
Author: 줍 <jubee0124@gmail.com>
Date: Mon Feb 12 16:38:48 2018 +0900
Fix typo in redis.conf
Fix `five behaviors` to `eight behaviors` in [this sentence ](antirez/redis@unstable/redis.conf#L564)
commit b50a620
Author: martinbroadhurst <martinbroadhurst@users.noreply.github.com>
Date: Thu Dec 28 12:07:30 2017 +0000
Fix typo in valgrind.sup
commit 7d8f349
Author: Peter Boughton <peter@sorcerersisle.com>
Date: Mon Nov 27 19:52:19 2017 +0000
Update CONTRIBUTING; refer doc updates to redis-doc repo.
commit 02dec7e
Author: Klauswk <klauswk1@hotmail.com>
Date: Tue Oct 24 16:18:38 2017 -0200
Fix typo in comment
commit e1efbc8
Author: chenshi <baiwfg2@gmail.com>
Date: Tue Oct 3 18:26:30 2017 +0800
Correct two spelling errors of comments
commit 93327d8
Author: spacewander <spacewanderlzx@gmail.com>
Date: Wed Sep 13 16:47:24 2017 +0800
Update the comment for OBJ_ENCODING_EMBSTR_SIZE_LIMIT's value
The value of OBJ_ENCODING_EMBSTR_SIZE_LIMIT is 44 now instead of 39.
commit 63d361f
Author: spacewander <spacewanderlzx@gmail.com>
Date: Tue Sep 12 15:06:42 2017 +0800
Fix <prevlen> related doc in ziplist.c
According to the definition of ZIP_BIG_PREVLEN and other related code,
the guard of single byte <prevlen> should be 254 instead of 255.
commit ebe228d
Author: hanael80 <hanael80@gmail.com>
Date: Tue Aug 15 09:09:40 2017 +0900
Fix typo
commit 6b696e6
Author: Matt Robenolt <matt@ydekproductions.com>
Date: Mon Aug 14 14:50:47 2017 -0700
Fix typo in LATENCY DOCTOR output
commit a2ec6ae
Author: caosiyang <caosiyang@qiyi.com>
Date: Tue Aug 15 14:15:16 2017 +0800
Fix a typo: form => from
commit 3ab7699
Author: caosiyang <caosiyang@qiyi.com>
Date: Thu Aug 10 18:40:33 2017 +0800
Fix a typo: replicationFeedSlavesFromMaster() => replicationFeedSlavesFromMasterStream()
commit 72d43ef
Author: caosiyang <caosiyang@qiyi.com>
Date: Tue Aug 8 15:57:25 2017 +0800
fix a typo: servewr => server
commit 707c958
Author: Bo Cai <charpty@gmail.com>
Date: Wed Jul 26 21:49:42 2017 +0800
redis-cli.c typo: conut -> count.
Signed-off-by: Bo Cai <charpty@gmail.com>
commit b9385b2
Author: JackDrogon <jack.xsuperman@gmail.com>
Date: Fri Jun 30 14:22:31 2017 +0800
Fix some spell problems
commit 20d9230
Author: akosel <aaronjkosel@gmail.com>
Date: Sun Jun 4 19:35:13 2017 -0500
Fix typo
commit b167bfc
Author: Krzysiek Witkowicz <krzysiekwitkowicz@gmail.com>
Date: Mon May 22 21:32:27 2017 +0100
Fix #4008 small typo in comment
commit 2b78ac8
Author: Jake Clarkson <jacobwclarkson@gmail.com>
Date: Wed Apr 26 15:49:50 2017 +0100
Correct typo in tests/unit/hyperloglog.tcl
commit b0f1cdb
Author: Qi Luo <qiluo-msft@users.noreply.github.com>
Date: Wed Apr 19 14:25:18 2017 -0700
Fix typo
commit a90b0f9
Author: charsyam <charsyam@naver.com>
Date: Thu Mar 16 18:19:53 2017 +0900
fix typos
fix typos
fix typos
commit 8430a79
Author: Richard Hart <richardhart92@gmail.com>
Date: Mon Mar 13 22:17:41 2017 -0400
Fixed log message typo in listenToPort.
commit 481a1c2
Author: Vinod Kumar <kumar003vinod@gmail.com>
Date: Sun Jan 15 23:04:51 2017 +0530
src/db.c: Correct "save" -> "safe" typo
commit 586b4d3
Author: wangshaonan <wshn13@gmail.com>
Date: Wed Dec 21 20:28:27 2016 +0800
Fix typo they->the in helloworld.c
commit c1c4b5e
Author: Jenner <hypxm@qq.com>
Date: Mon Dec 19 16:39:46 2016 +0800
typo error
commit 1ee1a3f
Author: tielei <43289893@qq.com>
Date: Mon Jul 18 13:52:25 2016 +0800
fix some comments
commit 11a41fb
Author: Otto Kekäläinen <otto@seravo.fi>
Date: Sun Jul 3 10:23:55 2016 +0100
Fix spelling in documentation and comments
commit 5fb5d82
Author: francischan <f1ancis621@gmail.com>
Date: Tue Jun 28 00:19:33 2016 +0800
Fix outdated comments about redis.c file.
It should now refer to server.c file.
commit 6b254bc
Author: lmatt-bit <lmatt123n@gmail.com>
Date: Thu Apr 21 21:45:58 2016 +0800
Refine the comment of dictRehashMilliseconds func
SLAVECONF->REPLCONF in comment - by andyli029
commit ee9869f
Author: clark.kang <charsyam@naver.com>
Date: Tue Mar 22 11:09:51 2016 +0900
fix typos
commit f7b3b11
Author: Harisankar H <harisankarh@gmail.com>
Date: Wed Mar 9 11:49:42 2016 +0530
Typo correction: "faield" --> "failed"
Typo correction: "faield" --> "failed"
commit 3fd40fc
Author: Itamar Haber <itamar@redislabs.com>
Date: Thu Feb 25 10:31:51 2016 +0200
Fixes a typo in comments
commit 621c160
Author: Prayag Verma <prayag.verma@gmail.com>
Date: Mon Feb 1 12:36:20 2016 +0530
Fix typo in Readme.md
Spelling mistakes -
`eviciton` > `eviction`
`familar` > `familiar`
commit d7d07d6
Author: WonCheol Lee <toctoc21c@gmail.com>
Date: Wed Dec 30 15:11:34 2015 +0900
Typo fixed
commit a4dade7
Author: Felix Bünemann <buenemann@louis.info>
Date: Mon Dec 28 11:02:55 2015 +0100
[ci skip] Improve supervised upstart config docs
This mentions that "expect stop" is required for supervised upstart
to work correctly. See http://upstart.ubuntu.com/cookbook/#expect-stop
for an explanation.
commit d9caba9
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:30:03 2015 +1100
README: Remove trailing whitespace
commit 72d42e5
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:29:32 2015 +1100
README: Fix typo. th => the
commit dd6e957
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:29:20 2015 +1100
README: Fix typo. familar => familiar
commit 3a12b23
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:28:54 2015 +1100
README: Fix typo. eviciton => eviction
commit 2d1d03b
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:21:45 2015 +1100
README: Fix typo. sever => server
commit 3973b06
Author: Itamar Haber <itamar@garantiadata.com>
Date: Sat Dec 19 17:01:20 2015 +0200
Typo fix
commit 4f2e460
Author: Steve Gao <fu@2token.com>
Date: Fri Dec 4 10:22:05 2015 +0800
Update README - fix typos
commit b21667c
Author: binyan <binbin.yan@nokia.com>
Date: Wed Dec 2 22:48:37 2015 +0800
delete redundancy color judge in sdscatcolor
commit 88894c7
Author: binyan <binbin.yan@nokia.com>
Date: Wed Dec 2 22:14:42 2015 +0800
the example output shoule be HelloWorld
commit 2763470
Author: binyan <binbin.yan@nokia.com>
Date: Wed Dec 2 17:41:39 2015 +0800
modify error word keyevente
Signed-off-by: binyan <binbin.yan@nokia.com>
commit 0847b3d
Author: Bruno Martins <bscmartins@gmail.com>
Date: Wed Nov 4 11:37:01 2015 +0000
typo
commit bbb9e9e
Author: dawedawe <dawedawe@gmx.de>
Date: Fri Mar 27 00:46:41 2015 +0100
typo: zimap -> zipmap
commit 5ed297e
Author: Axel Advento <badwolf.bloodseeker.rev@gmail.com>
Date: Tue Mar 3 15:58:29 2015 +0800
Fix 'salve' typos to 'slave'
commit edec9d6
Author: LudwikJaniuk <ludvig.janiuk@gmail.com>
Date: Wed Jun 12 14:12:47 2019 +0200
Update README.md
Co-Authored-By: Qix <Qix-@users.noreply.github.com>
commit 692a7af
Author: LudwikJaniuk <ludvig.janiuk@gmail.com>
Date: Tue May 28 14:32:04 2019 +0200
grammar
commit d962b0a
Author: Nick Frost <nickfrostatx@gmail.com>
Date: Wed Jul 20 15:17:12 2016 -0700
Minor grammar fix
commit 24fff01aaccaf5956973ada8c50ceb1462e211c6 (typos)
Author: Chad Miller <chadm@squareup.com>
Date: Tue Sep 8 13:46:11 2020 -0400
Fix faulty comment about operation of unlink()
commit 3cd5c1f3326c52aa552ada7ec797c6bb16452355
Author: Kevin <kevin.xgr@gmail.com>
Date: Wed Nov 20 00:13:50 2019 +0800
Fix typo in server.c.
From a83af59 Mon Sep 17 00:00:00 2001
From: wuwo <wuwo@wacai.com>
Date: Fri, 17 Mar 2017 20:37:45 +0800
Subject: [PATCH] falure to failure
From c961896 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B7=A6=E6=87=B6?= <veficos@gmail.com>
Date: Sat, 27 May 2017 15:33:04 +0800
Subject: [PATCH] fix typo
From e600ef2 Mon Sep 17 00:00:00 2001
From: "rui.zou" <rui.zou@yunify.com>
Date: Sat, 30 Sep 2017 12:38:15 +0800
Subject: [PATCH] fix a typo
From c7d07fa Mon Sep 17 00:00:00 2001
From: Alexandre Perrin <alex@kaworu.ch>
Date: Thu, 16 Aug 2018 10:35:31 +0200
Subject: [PATCH] deps README.md typo
From b25cb67 Mon Sep 17 00:00:00 2001
From: Guy Korland <gkorland@gmail.com>
Date: Wed, 26 Sep 2018 10:55:37 +0300
Subject: [PATCH 1/2] fix typos in header
From ad28ca6 Mon Sep 17 00:00:00 2001
From: Guy Korland <gkorland@gmail.com>
Date: Wed, 26 Sep 2018 11:02:36 +0300
Subject: [PATCH 2/2] fix typos
commit 34924cdedd8552466fc22c1168d49236cb7ee915
Author: Adrian Lynch <adi_ady_ade@hotmail.com>
Date: Sat Apr 4 21:59:15 2015 +0100
Typos fixed
commit fd2a1e7
Author: Jan <jsteemann@users.noreply.github.com>
Date: Sat Oct 27 19:13:01 2018 +0200
Fix typos
Fix typos
commit e14e47c1a234b53b0e103c5f6a1c61481cbcbb02
Author: Andy Lester <andy@petdance.com>
Date: Fri Aug 2 22:30:07 2019 -0500
Fix multiple misspellings of "following"
commit 79b948ce2dac6b453fe80995abbcaac04c213d5a
Author: Andy Lester <andy@petdance.com>
Date: Fri Aug 2 22:24:28 2019 -0500
Fix misspelling of create-cluster
commit 1fffde52666dc99ab35efbd31071a4c008cb5a71
Author: Andy Lester <andy@petdance.com>
Date: Wed Jul 31 17:57:56 2019 -0500
Fix typos
commit 204c9ba9651e9e05fd73936b452b9a30be456cfe
Author: Xiaobo Zhu <xiaobo.zhu@shopee.com>
Date: Tue Aug 13 22:19:25 2019 +0800
fix typos
Squashed commit of the following:
commit 1d9aaf8
Author: danmedani <danmedani@gmail.com>
Date: Sun Aug 2 11:40:26 2015 -0700
README typo fix.
Squashed commit of the following:
commit 32bfa7c
Author: Erik Dubbelboer <erik@dubbelboer.com>
Date: Mon Jul 6 21:15:08 2015 +0200
Fixed grammer
Squashed commit of the following:
commit b24f69c
Author: Sisir Koppaka <sisir.koppaka@gmail.com>
Date: Mon Mar 2 22:38:45 2015 -0500
utils/hashtable/rehashing.c: Fix typos
Squashed commit of the following:
commit 4e04082
Author: Erik Dubbelboer <erik@dubbelboer.com>
Date: Mon Mar 23 08:22:21 2015 +0000
Small config file documentation improvements
Squashed commit of the following:
commit acb8773
Author: ctd1500 <ctd1500@gmail.com>
Date: Fri May 8 01:52:48 2015 -0700
Typo and grammar fixes in readme
commit 2eb75b6
Author: ctd1500 <ctd1500@gmail.com>
Date: Fri May 8 01:36:18 2015 -0700
fixed redis.conf comment
Squashed commit of the following:
commit a8249a2
Author: Masahiko Sawada <sawada.mshk@gmail.com>
Date: Fri Dec 11 11:39:52 2015 +0530
Revise correction of typos.
Squashed commit of the following:
commit 3c02028
Author: zhaojun11 <zhaojun11@jd.com>
Date: Wed Jan 17 19:05:28 2018 +0800
Fix typos include two code typos in cluster.c and latency.c
Squashed commit of the following:
commit 9dba47c
Author: q191201771 <191201771@qq.com>
Date: Sat Jan 4 11:31:04 2020 +0800
fix function listCreate comment in adlist.c
Update src/server.c
commit 2c7c2cb536e78dd211b1ac6f7bda00f0f54faaeb
Author: charpty <charpty@gmail.com>
Date: Tue May 1 23:16:59 2018 +0800
server.c typo: modules system dictionary type comment
Signed-off-by: charpty <charpty@gmail.com>
commit a8395323fb63cb59cb3591cb0f0c8edb7c29a680
Author: Itamar Haber <itamar@redislabs.com>
Date: Sun May 6 00:25:18 2018 +0300
Updates test_helper.tcl's help with undocumented options
Specifically:
* Host
* Port
* Client
commit bde6f9ced15755cd6407b4af7d601b030f36d60b
Author: wxisme <850885154@qq.com>
Date: Wed Aug 8 15:19:19 2018 +0800
fix comments in deps files
commit 3172474ba991532ab799ee1873439f3402412331
Author: wxisme <850885154@qq.com>
Date: Wed Aug 8 14:33:49 2018 +0800
fix some comments
commit 01b6f2b6858b5cf2ce4ad5092d2c746e755f53f0
Author: Thor Juhasz <thor@juhasz.pro>
Date: Sun Nov 18 14:37:41 2018 +0100
Minor fixes to comments
Found some parts a little unclear on a first read, which prompted me to have a better look at the file and fix some minor things I noticed.
Fixing minor typos and grammar. There are no changes to configuration options.
These changes are only meant to help the user better understand the explanations to the various configuration options
2020-09-10 06:43:38 -04:00
|
|
|
* to clients accessing expired values in a read-only fashion, that
|
2018-07-01 01:24:50 -04:00
|
|
|
* will say the key as non existing.
|
Better read-only behavior for expired keys in slaves.
Slaves key expire is orchestrated by the master. Sometimes the master
will send the synthesized DEL to expire keys on the slave with a non
trivial delay (when the key is not accessed, only the incremental expiry
algorithm will expire it in background).
During that time, a key is logically expired, but slaves still return
the key if you GET (or whatever) it. This is a bad behavior.
However we can't simply trust the slave view of the key, since we need
the master to be able to send write commands to update the slave data
set, and DELs should only happen when the key is expired in the master
in order to ensure consistency.
However 99.99% of the issues with this behavior is when a client which
is not a master sends a read only command. In this case we are safe and
can consider the key as non existing.
This commit does a few changes in order to make this sane:
1. lookupKeyRead() is modified in order to return NULL if the above
conditions are met.
2. Calls to lookupKeyRead() in commands actually writing to the data set
are repliaced with calls to lookupKeyWrite().
There are redundand checks, so for example, if in "2" something was
overlooked, we should be still safe, since anyway, when the master
writes the behavior is to don't care about what expireIfneeded()
returns.
This commit is related to #1768, #1770, #2131.
2014-12-10 10:10:21 -05:00
|
|
|
*
|
|
|
|
* Notably this covers GETs when slaves are used to scale reads. */
|
|
|
|
if (server.current_client &&
|
|
|
|
server.current_client != server.master &&
|
|
|
|
server.current_client->cmd &&
|
2015-07-27 03:41:48 -04:00
|
|
|
server.current_client->cmd->flags & CMD_READONLY)
|
Better read-only behavior for expired keys in slaves.
Slaves key expire is orchestrated by the master. Sometimes the master
will send the synthesized DEL to expire keys on the slave with a non
trivial delay (when the key is not accessed, only the incremental expiry
algorithm will expire it in background).
During that time, a key is logically expired, but slaves still return
the key if you GET (or whatever) it. This is a bad behavior.
However we can't simply trust the slave view of the key, since we need
the master to be able to send write commands to update the slave data
set, and DELs should only happen when the key is expired in the master
in order to ensure consistency.
However 99.99% of the issues with this behavior is when a client which
is not a master sends a read only command. In this case we are safe and
can consider the key as non existing.
This commit does a few changes in order to make this sane:
1. lookupKeyRead() is modified in order to return NULL if the above
conditions are met.
2. Calls to lookupKeyRead() in commands actually writing to the data set
are repliaced with calls to lookupKeyWrite().
There are redundand checks, so for example, if in "2" something was
overlooked, we should be still safe, since anyway, when the master
writes the behavior is to don't care about what expireIfneeded()
returns.
This commit is related to #1768, #1770, #2131.
2014-12-10 10:10:21 -05:00
|
|
|
{
|
2020-11-18 04:16:21 -05:00
|
|
|
goto keymiss;
|
Better read-only behavior for expired keys in slaves.
Slaves key expire is orchestrated by the master. Sometimes the master
will send the synthesized DEL to expire keys on the slave with a non
trivial delay (when the key is not accessed, only the incremental expiry
algorithm will expire it in background).
During that time, a key is logically expired, but slaves still return
the key if you GET (or whatever) it. This is a bad behavior.
However we can't simply trust the slave view of the key, since we need
the master to be able to send write commands to update the slave data
set, and DELs should only happen when the key is expired in the master
in order to ensure consistency.
However 99.99% of the issues with this behavior is when a client which
is not a master sends a read only command. In this case we are safe and
can consider the key as non existing.
This commit does a few changes in order to make this sane:
1. lookupKeyRead() is modified in order to return NULL if the above
conditions are met.
2. Calls to lookupKeyRead() in commands actually writing to the data set
are repliaced with calls to lookupKeyWrite().
There are redundand checks, so for example, if in "2" something was
overlooked, we should be still safe, since anyway, when the master
writes the behavior is to don't care about what expireIfneeded()
returns.
This commit is related to #1768, #1770, #2131.
2014-12-10 10:10:21 -05:00
|
|
|
}
|
|
|
|
}
|
2016-06-14 09:33:59 -04:00
|
|
|
val = lookupKey(db,key,flags);
|
2020-11-18 04:16:21 -05:00
|
|
|
if (val == NULL)
|
|
|
|
goto keymiss;
|
|
|
|
server.stat_keyspace_hits++;
|
|
|
|
return val;
|
|
|
|
|
|
|
|
keymiss:
|
|
|
|
if (!(flags & LOOKUP_NONOTIFY)) {
|
2012-02-01 15:47:41 -05:00
|
|
|
server.stat_keyspace_misses++;
|
2019-03-21 14:33:11 -04:00
|
|
|
notifyKeyspaceEvent(NOTIFY_KEY_MISS, "keymiss", key, db->id);
|
2019-03-19 07:11:37 -04:00
|
|
|
}
|
2020-11-18 04:16:21 -05:00
|
|
|
return NULL;
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
|
2016-06-14 09:33:59 -04:00
|
|
|
/* Like lookupKeyReadWithFlags(), but does not use any flag, which is the
|
|
|
|
* common case. */
|
|
|
|
robj *lookupKeyRead(redisDb *db, robj *key) {
|
|
|
|
return lookupKeyReadWithFlags(db,key,LOOKUP_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lookup a key for write operations, and as a side effect, if needed, expires
|
|
|
|
* the key if its TTL is reached.
|
|
|
|
*
|
|
|
|
* Returns the linked value object if the key exists or NULL if the key
|
|
|
|
* does not exist in the specified DB. */
|
2019-10-23 04:53:15 -04:00
|
|
|
robj *lookupKeyWriteWithFlags(redisDb *db, robj *key, int flags) {
|
2010-08-02 12:13:39 -04:00
|
|
|
expireIfNeeded(db,key);
|
2019-10-23 04:53:15 -04:00
|
|
|
return lookupKey(db,key,flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
robj *lookupKeyWrite(redisDb *db, robj *key) {
|
|
|
|
return lookupKeyWriteWithFlags(db, key, LOOKUP_NONE);
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
|
2015-07-26 09:20:46 -04:00
|
|
|
robj *lookupKeyReadOrReply(client *c, robj *key, robj *reply) {
|
2010-06-21 18:07:48 -04:00
|
|
|
robj *o = lookupKeyRead(c->db, key);
|
|
|
|
if (!o) addReply(c,reply);
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2015-07-26 09:20:46 -04:00
|
|
|
robj *lookupKeyWriteOrReply(client *c, robj *key, robj *reply) {
|
2010-06-21 18:07:48 -04:00
|
|
|
robj *o = lookupKeyWrite(c->db, key);
|
|
|
|
if (!o) addReply(c,reply);
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2011-06-14 09:34:27 -04:00
|
|
|
/* Add the key to the DB. It's up to the caller to increment the reference
|
2013-01-16 12:00:20 -05:00
|
|
|
* counter of the value if needed.
|
2011-06-14 09:34:27 -04:00
|
|
|
*
|
|
|
|
* The program is aborted if the key already exists. */
|
|
|
|
void dbAdd(redisDb *db, robj *key, robj *val) {
|
|
|
|
sds copy = sdsdup(key->ptr);
|
|
|
|
int retval = dictAdd(db->dict, copy, val);
|
|
|
|
|
2016-04-25 09:49:57 -04:00
|
|
|
serverAssertWithInfo(NULL,key,retval == DICT_OK);
|
2020-08-11 01:18:09 -04:00
|
|
|
signalKeyAsReady(db, key, val->type);
|
2020-04-09 04:24:10 -04:00
|
|
|
if (server.cluster_enabled) slotToKeyAdd(key->ptr);
|
2017-09-06 09:43:28 -04:00
|
|
|
}
|
2011-06-14 09:34:27 -04:00
|
|
|
|
2020-04-09 10:21:48 -04:00
|
|
|
/* This is a special version of dbAdd() that is used only when loading
|
|
|
|
* keys from the RDB file: the key is passed as an SDS string that is
|
|
|
|
* retained by the function (and not freed by the caller).
|
|
|
|
*
|
|
|
|
* Moreover this function will not abort if the key is already busy, to
|
|
|
|
* give more control to the caller, nor will signal the key as ready
|
|
|
|
* since it is not useful in this context.
|
|
|
|
*
|
|
|
|
* The function returns 1 if the key was added to the database, taking
|
|
|
|
* ownership of the SDS string, otherwise 0 is returned, and is up to the
|
|
|
|
* caller to free the SDS string. */
|
|
|
|
int dbAddRDBLoad(redisDb *db, sds key, robj *val) {
|
|
|
|
int retval = dictAdd(db->dict, key, val);
|
|
|
|
if (retval != DICT_OK) return 0;
|
|
|
|
if (server.cluster_enabled) slotToKeyAdd(key);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-06-14 09:34:27 -04:00
|
|
|
/* Overwrite an existing key with a new value. Incrementing the reference
|
|
|
|
* count of the new value is up to the caller.
|
|
|
|
* This function does not modify the expire time of the existing key.
|
|
|
|
*
|
|
|
|
* The program is aborted if the key was not already present. */
|
|
|
|
void dbOverwrite(redisDb *db, robj *key, robj *val) {
|
2014-03-20 11:20:37 -04:00
|
|
|
dictEntry *de = dictFind(db->dict,key->ptr);
|
2014-06-26 12:48:40 -04:00
|
|
|
|
2015-07-26 09:29:53 -04:00
|
|
|
serverAssertWithInfo(NULL,key,de != NULL);
|
2018-07-31 00:07:57 -04:00
|
|
|
dictEntry auxentry = *de;
|
|
|
|
robj *old = dictGetVal(de);
|
2016-07-18 07:49:31 -04:00
|
|
|
if (server.maxmemory_policy & MAXMEMORY_FLAG_LFU) {
|
2018-07-31 00:07:57 -04:00
|
|
|
val->lru = old->lru;
|
|
|
|
}
|
2020-11-16 03:34:04 -05:00
|
|
|
/* Although the key is not really deleted from the database, we regard
|
|
|
|
overwrite as two steps of unlink+add, so we still need to call the unlink
|
|
|
|
callback of the module. */
|
|
|
|
moduleNotifyKeyUnlink(key,val);
|
2018-07-31 00:07:57 -04:00
|
|
|
dictSetVal(db->dict, de, val);
|
|
|
|
|
|
|
|
if (server.lazyfree_lazy_server_del) {
|
2020-11-16 03:34:04 -05:00
|
|
|
freeObjAsync(key,old);
|
2018-07-31 00:07:57 -04:00
|
|
|
dictSetVal(db->dict, &auxentry, NULL);
|
2016-07-18 07:49:31 -04:00
|
|
|
}
|
2018-07-31 00:07:57 -04:00
|
|
|
|
|
|
|
dictFreeVal(db->dict, &auxentry);
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
|
2011-06-14 09:34:27 -04:00
|
|
|
/* High level Set operation. This function can be used in order to set
|
|
|
|
* a key, whatever it was existing or not, to a new object.
|
2010-06-21 18:07:48 -04:00
|
|
|
*
|
2011-06-14 09:34:27 -04:00
|
|
|
* 1) The ref count of the value object is incremented.
|
|
|
|
* 2) clients WATCHing for the destination key notified.
|
2019-12-18 05:58:02 -05:00
|
|
|
* 3) The expire time of the key is reset (the key is made persistent),
|
|
|
|
* unless 'keepttl' is true.
|
Replication: fix the infamous key leakage of writable slaves + EXPIRE.
BACKGROUND AND USE CASEj
Redis slaves are normally write only, however the supprot a "writable"
mode which is very handy when scaling reads on slaves, that actually
need write operations in order to access data. For instance imagine
having slaves replicating certain Sets keys from the master. When
accessing the data on the slave, we want to peform intersections between
such Sets values. However we don't want to intersect each time: to cache
the intersection for some time often is a good idea.
To do so, it is possible to setup a slave as a writable slave, and
perform the intersection on the slave side, perhaps setting a TTL on the
resulting key so that it will expire after some time.
THE BUG
Problem: in order to have a consistent replication, expiring of keys in
Redis replication is up to the master, that synthesize DEL operations to
send in the replication stream. However slaves logically expire keys
by hiding them from read attempts from clients so that if the master did
not promptly sent a DEL, the client still see logically expired keys
as non existing.
Because slaves don't actively expire keys by actually evicting them but
just masking from the POV of read operations, if a key is created in a
writable slave, and an expire is set, the key will be leaked forever:
1. No DEL will be received from the master, which does not know about
such a key at all.
2. No eviction will be performed by the slave, since it needs to disable
eviction because it's up to masters, otherwise consistency of data is
lost.
THE FIX
In order to fix the problem, the slave should be able to tag keys that
were created in the slave side and have an expire set in some way.
My solution involved using an unique additional dictionary created by
the writable slave only if needed. The dictionary is obviously keyed by
the key name that we need to track: all the keys that are set with an
expire directly by a client writing to the slave are tracked.
The value in the dictionary is a bitmap of all the DBs where such a key
name need to be tracked, so that we can use a single dictionary to track
keys in all the DBs used by the slave (actually this limits the solution
to the first 64 DBs, but the default with Redis is to use 16 DBs).
This solution allows to pay both a small complexity and CPU penalty,
which is zero when the feature is not used, actually. The slave-side
eviction is encapsulated in code which is not coupled with the rest of
the Redis core, if not for the hook to track the keys.
TODO
I'm doing the first smoke tests to see if the feature works as expected:
so far so good. Unit tests should be added before merging into the
4.0 branch.
2016-12-13 04:20:06 -05:00
|
|
|
*
|
2020-04-21 04:51:46 -04:00
|
|
|
* All the new keys in the database should be created via this interface.
|
|
|
|
* The client 'c' argument may be set to NULL if the operation is performed
|
|
|
|
* in a context where there is no clear client performing the operation. */
|
|
|
|
void genericSetKey(client *c, redisDb *db, robj *key, robj *val, int keepttl, int signal) {
|
2011-06-14 09:34:27 -04:00
|
|
|
if (lookupKeyWrite(db,key) == NULL) {
|
|
|
|
dbAdd(db,key,val);
|
2010-06-21 18:07:48 -04:00
|
|
|
} else {
|
2011-06-14 09:34:27 -04:00
|
|
|
dbOverwrite(db,key,val);
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
2011-06-14 09:34:27 -04:00
|
|
|
incrRefCount(val);
|
2019-12-18 01:49:38 -05:00
|
|
|
if (!keepttl) removeExpire(db,key);
|
2020-04-21 04:51:46 -04:00
|
|
|
if (signal) signalModifiedKey(c,db,key);
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
|
2019-12-18 05:58:02 -05:00
|
|
|
/* Common case for genericSetKey() where the TTL is not retained. */
|
2020-04-21 04:51:46 -04:00
|
|
|
void setKey(client *c, redisDb *db, robj *key, robj *val) {
|
|
|
|
genericSetKey(c,db,key,val,0,1);
|
2019-12-18 05:58:02 -05:00
|
|
|
}
|
|
|
|
|
2010-06-21 18:07:48 -04:00
|
|
|
/* Return a random key, in form of a Redis object.
|
|
|
|
* If there are no keys, NULL is returned.
|
|
|
|
*
|
|
|
|
* The function makes sure to return keys not already expired. */
|
|
|
|
robj *dbRandomKey(redisDb *db) {
|
2014-03-20 11:20:37 -04:00
|
|
|
dictEntry *de;
|
2018-06-14 12:08:05 -04:00
|
|
|
int maxtries = 100;
|
|
|
|
int allvolatile = dictSize(db->dict) == dictSize(db->expires);
|
2010-06-21 18:07:48 -04:00
|
|
|
|
|
|
|
while(1) {
|
|
|
|
sds key;
|
|
|
|
robj *keyobj;
|
|
|
|
|
2019-02-19 11:29:51 -05:00
|
|
|
de = dictGetFairRandomKey(db->dict);
|
2010-06-21 18:07:48 -04:00
|
|
|
if (de == NULL) return NULL;
|
|
|
|
|
2011-11-08 11:07:55 -05:00
|
|
|
key = dictGetKey(de);
|
2010-06-21 18:07:48 -04:00
|
|
|
keyobj = createStringObject(key,sdslen(key));
|
|
|
|
if (dictFind(db->expires,key)) {
|
2018-06-14 12:08:05 -04:00
|
|
|
if (allvolatile && server.masterhost && --maxtries == 0) {
|
|
|
|
/* If the DB is composed only of keys with an expire set,
|
|
|
|
* it could happen that all the keys are already logically
|
|
|
|
* expired in the slave, so the function cannot stop because
|
|
|
|
* expireIfNeeded() is false, nor it can stop because
|
|
|
|
* dictGetRandomKey() returns NULL (there are keys to return).
|
|
|
|
* To prevent the infinite loop we do some tries, but if there
|
|
|
|
* are the conditions for an infinite loop, eventually we
|
|
|
|
* return a key name that may be already expired. */
|
|
|
|
return keyobj;
|
|
|
|
}
|
2010-06-21 18:07:48 -04:00
|
|
|
if (expireIfNeeded(db,keyobj)) {
|
|
|
|
decrRefCount(keyobj);
|
|
|
|
continue; /* search for another key. This expired. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return keyobj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete a key, value, and associated expiration entry if any, from the DB */
|
2015-07-30 05:46:31 -04:00
|
|
|
int dbSyncDelete(redisDb *db, robj *key) {
|
2010-06-21 18:07:48 -04:00
|
|
|
/* Deleting an entry from the expires dict will not free the sds of
|
|
|
|
* the key, because it is shared with the main dictionary. */
|
|
|
|
if (dictSize(db->expires) > 0) dictDelete(db->expires,key->ptr);
|
2020-11-16 03:34:04 -05:00
|
|
|
dictEntry *de = dictUnlink(db->dict,key->ptr);
|
|
|
|
if (de) {
|
|
|
|
robj *val = dictGetVal(de);
|
|
|
|
/* Tells the module that the key has been unlinked from the database. */
|
|
|
|
moduleNotifyKeyUnlink(key,val);
|
|
|
|
dictFreeUnlinkedEntry(db->dict,de);
|
2020-04-09 04:24:10 -04:00
|
|
|
if (server.cluster_enabled) slotToKeyDel(key->ptr);
|
2011-04-28 13:00:33 -04:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
|
2015-07-30 05:46:31 -04:00
|
|
|
/* This is a wrapper whose behavior depends on the Redis lazy free
|
|
|
|
* configuration. Deletes the key synchronously or asynchronously. */
|
|
|
|
int dbDelete(redisDb *db, robj *key) {
|
2015-10-02 09:27:57 -04:00
|
|
|
return server.lazyfree_lazy_server_del ? dbAsyncDelete(db,key) :
|
|
|
|
dbSyncDelete(db,key);
|
2015-07-30 05:46:31 -04:00
|
|
|
}
|
|
|
|
|
2014-03-30 12:32:17 -04:00
|
|
|
/* Prepare the string object stored at 'key' to be modified destructively
|
|
|
|
* to implement commands like SETBIT or APPEND.
|
|
|
|
*
|
|
|
|
* An object is usually ready to be modified unless one of the two conditions
|
|
|
|
* are true:
|
|
|
|
*
|
|
|
|
* 1) The object 'o' is shared (refcount > 1), we don't want to affect
|
|
|
|
* other users.
|
|
|
|
* 2) The object encoding is not "RAW".
|
|
|
|
*
|
|
|
|
* If the object is found in one of the above conditions (or both) by the
|
|
|
|
* function, an unshared / not-encoded copy of the string object is stored
|
|
|
|
* at 'key' in the specified 'db'. Otherwise the object 'o' itself is
|
|
|
|
* returned.
|
|
|
|
*
|
|
|
|
* USAGE:
|
|
|
|
*
|
|
|
|
* The object 'o' is what the caller already obtained by looking up 'key'
|
|
|
|
* in 'db', the usage pattern looks like this:
|
|
|
|
*
|
|
|
|
* o = lookupKeyWrite(db,key);
|
2015-07-26 09:28:00 -04:00
|
|
|
* if (checkType(c,o,OBJ_STRING)) return;
|
2014-03-30 12:32:17 -04:00
|
|
|
* o = dbUnshareStringValue(db,key,o);
|
|
|
|
*
|
|
|
|
* At this point the caller is ready to modify the object, for example
|
|
|
|
* using an sdscat() call to append some data, or anything else.
|
|
|
|
*/
|
|
|
|
robj *dbUnshareStringValue(redisDb *db, robj *key, robj *o) {
|
2015-07-26 09:29:53 -04:00
|
|
|
serverAssert(o->type == OBJ_STRING);
|
2015-07-26 09:28:00 -04:00
|
|
|
if (o->refcount != 1 || o->encoding != OBJ_ENCODING_RAW) {
|
2014-03-30 12:32:17 -04:00
|
|
|
robj *decoded = getDecodedObject(o);
|
|
|
|
o = createRawStringObject(decoded->ptr, sdslen(decoded->ptr));
|
|
|
|
decrRefCount(decoded);
|
|
|
|
dbOverwrite(db,key,o);
|
|
|
|
}
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2020-12-02 06:56:11 -05:00
|
|
|
/* Remove all keys from the database(s) structure. The dbarray argument
|
|
|
|
* may not be the server main DBs (could be a backup).
|
|
|
|
*
|
|
|
|
* The dbnum can be -1 if all the DBs should be emptied, or the specified
|
|
|
|
* DB index if we want to empty only a single database.
|
|
|
|
* The function returns the number of keys removed from the database(s). */
|
|
|
|
long long emptyDbStructure(redisDb *dbarray, int dbnum, int async,
|
|
|
|
void(callback)(void*))
|
|
|
|
{
|
|
|
|
long long removed = 0;
|
|
|
|
int startdb, enddb;
|
|
|
|
|
|
|
|
if (dbnum == -1) {
|
|
|
|
startdb = 0;
|
|
|
|
enddb = server.dbnum-1;
|
|
|
|
} else {
|
|
|
|
startdb = enddb = dbnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int j = startdb; j <= enddb; j++) {
|
|
|
|
removed += dictSize(dbarray[j].dict);
|
|
|
|
if (async) {
|
|
|
|
emptyDbAsync(&dbarray[j]);
|
|
|
|
} else {
|
|
|
|
dictEmpty(dbarray[j].dict,callback);
|
|
|
|
dictEmpty(dbarray[j].expires,callback);
|
|
|
|
}
|
|
|
|
/* Because all keys of database are removed, reset average ttl. */
|
|
|
|
dbarray[j].avg_ttl = 0;
|
|
|
|
dbarray[j].expires_cursor = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return removed;
|
|
|
|
}
|
|
|
|
|
2015-09-28 04:47:45 -04:00
|
|
|
/* Remove all keys from all the databases in a Redis server.
|
|
|
|
* If callback is given the function is called from time to time to
|
|
|
|
* signal that work is in progress.
|
|
|
|
*
|
2018-07-01 01:24:50 -04:00
|
|
|
* The dbnum can be -1 if all the DBs should be flushed, or the specified
|
2015-09-28 04:47:45 -04:00
|
|
|
* DB number if we want to flush only a single Redis database number.
|
|
|
|
*
|
|
|
|
* Flags are be EMPTYDB_NO_FLAGS if no special flags are specified or
|
2020-12-02 06:56:11 -05:00
|
|
|
* EMPTYDB_ASYNC if we want the memory to be freed in a different thread
|
2015-09-28 04:47:45 -04:00
|
|
|
* and the function to return ASAP.
|
|
|
|
*
|
Squash merging 125 typo/grammar/comment/doc PRs (#7773)
List of squashed commits or PRs
===============================
commit 66801ea
Author: hwware <wen.hui.ware@gmail.com>
Date: Mon Jan 13 00:54:31 2020 -0500
typo fix in acl.c
commit 46f55db
Author: Itamar Haber <itamar@redislabs.com>
Date: Sun Sep 6 18:24:11 2020 +0300
Updates a couple of comments
Specifically:
* RM_AutoMemory completed instead of pointing to docs
* Updated link to custom type doc
commit 61a2aa0
Author: xindoo <xindoo@qq.com>
Date: Tue Sep 1 19:24:59 2020 +0800
Correct errors in code comments
commit a5871d1
Author: yz1509 <pro-756@qq.com>
Date: Tue Sep 1 18:36:06 2020 +0800
fix typos in module.c
commit 41eede7
Author: bookug <bookug@qq.com>
Date: Sat Aug 15 01:11:33 2020 +0800
docs: fix typos in comments
commit c303c84
Author: lazy-snail <ws.niu@outlook.com>
Date: Fri Aug 7 11:15:44 2020 +0800
fix spelling in redis.conf
commit 1eb76bf
Author: zhujian <zhujianxyz@gmail.com>
Date: Thu Aug 6 15:22:10 2020 +0800
add a missing 'n' in comment
commit 1530ec2
Author: Daniel Dai <764122422@qq.com>
Date: Mon Jul 27 00:46:35 2020 -0400
fix spelling in tracking.c
commit e517b31
Author: Hunter-Chen <huntcool001@gmail.com>
Date: Fri Jul 17 22:33:32 2020 +0800
Update redis.conf
Co-authored-by: Itamar Haber <itamar@redislabs.com>
commit c300eff
Author: Hunter-Chen <huntcool001@gmail.com>
Date: Fri Jul 17 22:33:23 2020 +0800
Update redis.conf
Co-authored-by: Itamar Haber <itamar@redislabs.com>
commit 4c058a8
Author: 陈浩鹏 <chenhaopeng@heytea.com>
Date: Thu Jun 25 19:00:56 2020 +0800
Grammar fix and clarification
commit 5fcaa81
Author: bodong.ybd <bodong.ybd@alibaba-inc.com>
Date: Fri Jun 19 10:09:00 2020 +0800
Fix typos
commit 4caca9a
Author: Pruthvi P <pruthvi@ixigo.com>
Date: Fri May 22 00:33:22 2020 +0530
Fix typo eviciton => eviction
commit b2a25f6
Author: Brad Dunbar <dunbarb2@gmail.com>
Date: Sun May 17 12:39:59 2020 -0400
Fix a typo.
commit 12842ae
Author: hwware <wen.hui.ware@gmail.com>
Date: Sun May 3 17:16:59 2020 -0400
fix spelling in redis conf
commit ddba07c
Author: Chris Lamb <chris@chris-lamb.co.uk>
Date: Sat May 2 23:25:34 2020 +0100
Correct a "conflicts" spelling error.
commit 8fc7bf2
Author: Nao YONASHIRO <yonashiro@r.recruit.co.jp>
Date: Thu Apr 30 10:25:27 2020 +0900
docs: fix EXPIRE_FAST_CYCLE_DURATION to ACTIVE_EXPIRE_CYCLE_FAST_DURATION
commit 9b2b67a
Author: Brad Dunbar <dunbarb2@gmail.com>
Date: Fri Apr 24 11:46:22 2020 -0400
Fix a typo.
commit 0746f10
Author: devilinrust <63737265+devilinrust@users.noreply.github.com>
Date: Thu Apr 16 00:17:53 2020 +0200
Fix typos in server.c
commit 92b588d
Author: benjessop12 <56115861+benjessop12@users.noreply.github.com>
Date: Mon Apr 13 13:43:55 2020 +0100
Fix spelling mistake in lazyfree.c
commit 1da37aa
Merge: 2d4ba28 af347a8
Author: hwware <wen.hui.ware@gmail.com>
Date: Thu Mar 5 22:41:31 2020 -0500
Merge remote-tracking branch 'upstream/unstable' into expiretypofix
commit 2d4ba28
Author: hwware <wen.hui.ware@gmail.com>
Date: Mon Mar 2 00:09:40 2020 -0500
fix typo in expire.c
commit 1a746f7
Author: SennoYuki <minakami1yuki@gmail.com>
Date: Thu Feb 27 16:54:32 2020 +0800
fix typo
commit 8599b1a
Author: dongheejeong <donghee950403@gmail.com>
Date: Sun Feb 16 20:31:43 2020 +0000
Fix typo in server.c
commit f38d4e8
Author: hwware <wen.hui.ware@gmail.com>
Date: Sun Feb 2 22:58:38 2020 -0500
fix typo in evict.c
commit fe143fc
Author: Leo Murillo <leonardo.murillo@gmail.com>
Date: Sun Feb 2 01:57:22 2020 -0600
Fix a few typos in redis.conf
commit 1ab4d21
Author: viraja1 <anchan.viraj@gmail.com>
Date: Fri Dec 27 17:15:58 2019 +0530
Fix typo in Latency API docstring
commit ca1f70e
Author: gosth <danxuedexing@qq.com>
Date: Wed Dec 18 15:18:02 2019 +0800
fix typo in sort.c
commit a57c06b
Author: ZYunH <zyunhjob@163.com>
Date: Mon Dec 16 22:28:46 2019 +0800
fix-zset-typo
commit b8c92b5
Author: git-hulk <hulk.website@gmail.com>
Date: Mon Dec 16 15:51:42 2019 +0800
FIX: typo in cluster.c, onformation->information
commit 9dd981c
Author: wujm2007 <jim.wujm@gmail.com>
Date: Mon Dec 16 09:37:52 2019 +0800
Fix typo
commit e132d7a
Author: Sebastien Williams-Wynn <s.williamswynn.mail@gmail.com>
Date: Fri Nov 15 00:14:07 2019 +0000
Minor typo change
commit 47f44d5
Author: happynote3966 <01ssrmikururudevice01@gmail.com>
Date: Mon Nov 11 22:08:48 2019 +0900
fix comment typo in redis-cli.c
commit b8bdb0d
Author: fulei <fulei@kuaishou.com>
Date: Wed Oct 16 18:00:17 2019 +0800
Fix a spelling mistake of comments in defragDictBucketCallback
commit 0def46a
Author: fulei <fulei@kuaishou.com>
Date: Wed Oct 16 13:09:27 2019 +0800
fix some spelling mistakes of comments in defrag.c
commit f3596fd
Author: Phil Rajchgot <tophil@outlook.com>
Date: Sun Oct 13 02:02:32 2019 -0400
Typo and grammar fixes
Redis and its documentation are great -- just wanted to submit a few corrections in the spirit of Hacktoberfest. Thanks for all your work on this project. I use it all the time and it works beautifully.
commit 2b928cd
Author: KangZhiDong <worldkzd@gmail.com>
Date: Sun Sep 1 07:03:11 2019 +0800
fix typos
commit 33aea14
Author: Axlgrep <axlgrep@gmail.com>
Date: Tue Aug 27 11:02:18 2019 +0800
Fixed eviction spelling issues
commit e282a80
Author: Simen Flatby <simen@oms.no>
Date: Tue Aug 20 15:25:51 2019 +0200
Update comments to reflect prop name
In the comments the prop is referenced as replica-validity-factor,
but it is really named cluster-replica-validity-factor.
commit 74d1f9a
Author: Jim Green <jimgreen2013@qq.com>
Date: Tue Aug 20 20:00:31 2019 +0800
fix comment error, the code is ok
commit eea1407
Author: Liao Tonglang <liaotonglang@gmail.com>
Date: Fri May 31 10:16:18 2019 +0800
typo fix
fix cna't to can't
commit 0da553c
Author: KAWACHI Takashi <tkawachi@gmail.com>
Date: Wed Jul 17 00:38:16 2019 +0900
Fix typo
commit 7fc8fb6
Author: Michael Prokop <mika@grml.org>
Date: Tue May 28 17:58:42 2019 +0200
Typo fixes
s/familar/familiar/
s/compatiblity/compatibility/
s/ ot / to /
s/itsef/itself/
commit 5f46c9d
Author: zhumoing <34539422+zhumoing@users.noreply.github.com>
Date: Tue May 21 21:16:50 2019 +0800
typo-fixes
typo-fixes
commit 321dfe1
Author: wxisme <850885154@qq.com>
Date: Sat Mar 16 15:10:55 2019 +0800
typo fix
commit b4fb131
Merge: 267e0e6 3df1eb8
Author: Nikitas Bastas <nikitasbst@gmail.com>
Date: Fri Feb 8 22:55:45 2019 +0200
Merge branch 'unstable' of antirez/redis into unstable
commit 267e0e6
Author: Nikitas Bastas <nikitasbst@gmail.com>
Date: Wed Jan 30 21:26:04 2019 +0200
Minor typo fix
commit 30544e7
Author: inshal96 <39904558+inshal96@users.noreply.github.com>
Date: Fri Jan 4 16:54:50 2019 +0500
remove an extra 'a' in the comments
commit 337969d
Author: BrotherGao <yangdongheng11@gmail.com>
Date: Sat Dec 29 12:37:29 2018 +0800
fix typo in redis.conf
commit 9f4b121
Merge: 423a030 e504583
Author: BrotherGao <yangdongheng@xiaomi.com>
Date: Sat Dec 29 11:41:12 2018 +0800
Merge branch 'unstable' of antirez/redis into unstable
commit 423a030
Merge: 42b02b7 46a51cd
Author: 杨东衡 <yangdongheng@xiaomi.com>
Date: Tue Dec 4 23:56:11 2018 +0800
Merge branch 'unstable' of antirez/redis into unstable
commit 42b02b7
Merge: 68c0e6e b8febe6
Author: Dongheng Yang <yangdongheng11@gmail.com>
Date: Sun Oct 28 15:54:23 2018 +0800
Merge pull request #1 from antirez/unstable
update local data
commit 714b589
Author: Christian <crifei93@gmail.com>
Date: Fri Dec 28 01:17:26 2018 +0100
fix typo "resulution"
commit e23259d
Author: garenchan <1412950785@qq.com>
Date: Wed Dec 26 09:58:35 2018 +0800
fix typo: segfauls -> segfault
commit a9359f8
Author: xjp <jianping_xie@aliyun.com>
Date: Tue Dec 18 17:31:44 2018 +0800
Fixed REDISMODULE_H spell bug
commit a12c3e4
Author: jdiaz <jrd.palacios@gmail.com>
Date: Sat Dec 15 23:39:52 2018 -0600
Fixes hyperloglog hash function comment block description
commit 770eb11
Author: 林上耀 <1210tom@163.com>
Date: Sun Nov 25 17:16:10 2018 +0800
fix typo
commit fd97fbb
Author: Chris Lamb <chris@chris-lamb.co.uk>
Date: Fri Nov 23 17:14:01 2018 +0100
Correct "unsupported" typo.
commit a85522d
Author: Jungnam Lee <jungnam.lee@oracle.com>
Date: Thu Nov 8 23:01:29 2018 +0900
fix typo in test comments
commit ade8007
Author: Arun Kumar <palerdot@users.noreply.github.com>
Date: Tue Oct 23 16:56:35 2018 +0530
Fixed grammatical typo
Fixed typo for word 'dictionary'
commit 869ee39
Author: Hamid Alaei <hamid.a85@gmail.com>
Date: Sun Aug 12 16:40:02 2018 +0430
fix documentations: (ThreadSafeContextStart/Stop -> ThreadSafeContextLock/Unlock), minor typo
commit f89d158
Author: Mayank Jain <mayankjain255@gmail.com>
Date: Tue Jul 31 23:01:21 2018 +0530
Updated README.md with some spelling corrections.
Made correction in spelling of some misspelled words.
commit 892198e
Author: dsomeshwar <someshwar.dhayalan@gmail.com>
Date: Sat Jul 21 23:23:04 2018 +0530
typo fix
commit 8a4d780
Author: Itamar Haber <itamar@redislabs.com>
Date: Mon Apr 30 02:06:52 2018 +0300
Fixes some typos
commit e3acef6
Author: Noah Rosamilia <ivoahivoah@gmail.com>
Date: Sat Mar 3 23:41:21 2018 -0500
Fix typo in /deps/README.md
commit 04442fb
Author: WuYunlong <xzsyeb@126.com>
Date: Sat Mar 3 10:32:42 2018 +0800
Fix typo in readSyncBulkPayload() comment.
commit 9f36880
Author: WuYunlong <xzsyeb@126.com>
Date: Sat Mar 3 10:20:37 2018 +0800
replication.c comment: run_id -> replid.
commit f866b4a
Author: Francesco 'makevoid' Canessa <makevoid@gmail.com>
Date: Thu Feb 22 22:01:56 2018 +0000
fix comment typo in server.c
commit 0ebc69b
Author: 줍 <jubee0124@gmail.com>
Date: Mon Feb 12 16:38:48 2018 +0900
Fix typo in redis.conf
Fix `five behaviors` to `eight behaviors` in [this sentence ](antirez/redis@unstable/redis.conf#L564)
commit b50a620
Author: martinbroadhurst <martinbroadhurst@users.noreply.github.com>
Date: Thu Dec 28 12:07:30 2017 +0000
Fix typo in valgrind.sup
commit 7d8f349
Author: Peter Boughton <peter@sorcerersisle.com>
Date: Mon Nov 27 19:52:19 2017 +0000
Update CONTRIBUTING; refer doc updates to redis-doc repo.
commit 02dec7e
Author: Klauswk <klauswk1@hotmail.com>
Date: Tue Oct 24 16:18:38 2017 -0200
Fix typo in comment
commit e1efbc8
Author: chenshi <baiwfg2@gmail.com>
Date: Tue Oct 3 18:26:30 2017 +0800
Correct two spelling errors of comments
commit 93327d8
Author: spacewander <spacewanderlzx@gmail.com>
Date: Wed Sep 13 16:47:24 2017 +0800
Update the comment for OBJ_ENCODING_EMBSTR_SIZE_LIMIT's value
The value of OBJ_ENCODING_EMBSTR_SIZE_LIMIT is 44 now instead of 39.
commit 63d361f
Author: spacewander <spacewanderlzx@gmail.com>
Date: Tue Sep 12 15:06:42 2017 +0800
Fix <prevlen> related doc in ziplist.c
According to the definition of ZIP_BIG_PREVLEN and other related code,
the guard of single byte <prevlen> should be 254 instead of 255.
commit ebe228d
Author: hanael80 <hanael80@gmail.com>
Date: Tue Aug 15 09:09:40 2017 +0900
Fix typo
commit 6b696e6
Author: Matt Robenolt <matt@ydekproductions.com>
Date: Mon Aug 14 14:50:47 2017 -0700
Fix typo in LATENCY DOCTOR output
commit a2ec6ae
Author: caosiyang <caosiyang@qiyi.com>
Date: Tue Aug 15 14:15:16 2017 +0800
Fix a typo: form => from
commit 3ab7699
Author: caosiyang <caosiyang@qiyi.com>
Date: Thu Aug 10 18:40:33 2017 +0800
Fix a typo: replicationFeedSlavesFromMaster() => replicationFeedSlavesFromMasterStream()
commit 72d43ef
Author: caosiyang <caosiyang@qiyi.com>
Date: Tue Aug 8 15:57:25 2017 +0800
fix a typo: servewr => server
commit 707c958
Author: Bo Cai <charpty@gmail.com>
Date: Wed Jul 26 21:49:42 2017 +0800
redis-cli.c typo: conut -> count.
Signed-off-by: Bo Cai <charpty@gmail.com>
commit b9385b2
Author: JackDrogon <jack.xsuperman@gmail.com>
Date: Fri Jun 30 14:22:31 2017 +0800
Fix some spell problems
commit 20d9230
Author: akosel <aaronjkosel@gmail.com>
Date: Sun Jun 4 19:35:13 2017 -0500
Fix typo
commit b167bfc
Author: Krzysiek Witkowicz <krzysiekwitkowicz@gmail.com>
Date: Mon May 22 21:32:27 2017 +0100
Fix #4008 small typo in comment
commit 2b78ac8
Author: Jake Clarkson <jacobwclarkson@gmail.com>
Date: Wed Apr 26 15:49:50 2017 +0100
Correct typo in tests/unit/hyperloglog.tcl
commit b0f1cdb
Author: Qi Luo <qiluo-msft@users.noreply.github.com>
Date: Wed Apr 19 14:25:18 2017 -0700
Fix typo
commit a90b0f9
Author: charsyam <charsyam@naver.com>
Date: Thu Mar 16 18:19:53 2017 +0900
fix typos
fix typos
fix typos
commit 8430a79
Author: Richard Hart <richardhart92@gmail.com>
Date: Mon Mar 13 22:17:41 2017 -0400
Fixed log message typo in listenToPort.
commit 481a1c2
Author: Vinod Kumar <kumar003vinod@gmail.com>
Date: Sun Jan 15 23:04:51 2017 +0530
src/db.c: Correct "save" -> "safe" typo
commit 586b4d3
Author: wangshaonan <wshn13@gmail.com>
Date: Wed Dec 21 20:28:27 2016 +0800
Fix typo they->the in helloworld.c
commit c1c4b5e
Author: Jenner <hypxm@qq.com>
Date: Mon Dec 19 16:39:46 2016 +0800
typo error
commit 1ee1a3f
Author: tielei <43289893@qq.com>
Date: Mon Jul 18 13:52:25 2016 +0800
fix some comments
commit 11a41fb
Author: Otto Kekäläinen <otto@seravo.fi>
Date: Sun Jul 3 10:23:55 2016 +0100
Fix spelling in documentation and comments
commit 5fb5d82
Author: francischan <f1ancis621@gmail.com>
Date: Tue Jun 28 00:19:33 2016 +0800
Fix outdated comments about redis.c file.
It should now refer to server.c file.
commit 6b254bc
Author: lmatt-bit <lmatt123n@gmail.com>
Date: Thu Apr 21 21:45:58 2016 +0800
Refine the comment of dictRehashMilliseconds func
SLAVECONF->REPLCONF in comment - by andyli029
commit ee9869f
Author: clark.kang <charsyam@naver.com>
Date: Tue Mar 22 11:09:51 2016 +0900
fix typos
commit f7b3b11
Author: Harisankar H <harisankarh@gmail.com>
Date: Wed Mar 9 11:49:42 2016 +0530
Typo correction: "faield" --> "failed"
Typo correction: "faield" --> "failed"
commit 3fd40fc
Author: Itamar Haber <itamar@redislabs.com>
Date: Thu Feb 25 10:31:51 2016 +0200
Fixes a typo in comments
commit 621c160
Author: Prayag Verma <prayag.verma@gmail.com>
Date: Mon Feb 1 12:36:20 2016 +0530
Fix typo in Readme.md
Spelling mistakes -
`eviciton` > `eviction`
`familar` > `familiar`
commit d7d07d6
Author: WonCheol Lee <toctoc21c@gmail.com>
Date: Wed Dec 30 15:11:34 2015 +0900
Typo fixed
commit a4dade7
Author: Felix Bünemann <buenemann@louis.info>
Date: Mon Dec 28 11:02:55 2015 +0100
[ci skip] Improve supervised upstart config docs
This mentions that "expect stop" is required for supervised upstart
to work correctly. See http://upstart.ubuntu.com/cookbook/#expect-stop
for an explanation.
commit d9caba9
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:30:03 2015 +1100
README: Remove trailing whitespace
commit 72d42e5
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:29:32 2015 +1100
README: Fix typo. th => the
commit dd6e957
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:29:20 2015 +1100
README: Fix typo. familar => familiar
commit 3a12b23
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:28:54 2015 +1100
README: Fix typo. eviciton => eviction
commit 2d1d03b
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:21:45 2015 +1100
README: Fix typo. sever => server
commit 3973b06
Author: Itamar Haber <itamar@garantiadata.com>
Date: Sat Dec 19 17:01:20 2015 +0200
Typo fix
commit 4f2e460
Author: Steve Gao <fu@2token.com>
Date: Fri Dec 4 10:22:05 2015 +0800
Update README - fix typos
commit b21667c
Author: binyan <binbin.yan@nokia.com>
Date: Wed Dec 2 22:48:37 2015 +0800
delete redundancy color judge in sdscatcolor
commit 88894c7
Author: binyan <binbin.yan@nokia.com>
Date: Wed Dec 2 22:14:42 2015 +0800
the example output shoule be HelloWorld
commit 2763470
Author: binyan <binbin.yan@nokia.com>
Date: Wed Dec 2 17:41:39 2015 +0800
modify error word keyevente
Signed-off-by: binyan <binbin.yan@nokia.com>
commit 0847b3d
Author: Bruno Martins <bscmartins@gmail.com>
Date: Wed Nov 4 11:37:01 2015 +0000
typo
commit bbb9e9e
Author: dawedawe <dawedawe@gmx.de>
Date: Fri Mar 27 00:46:41 2015 +0100
typo: zimap -> zipmap
commit 5ed297e
Author: Axel Advento <badwolf.bloodseeker.rev@gmail.com>
Date: Tue Mar 3 15:58:29 2015 +0800
Fix 'salve' typos to 'slave'
commit edec9d6
Author: LudwikJaniuk <ludvig.janiuk@gmail.com>
Date: Wed Jun 12 14:12:47 2019 +0200
Update README.md
Co-Authored-By: Qix <Qix-@users.noreply.github.com>
commit 692a7af
Author: LudwikJaniuk <ludvig.janiuk@gmail.com>
Date: Tue May 28 14:32:04 2019 +0200
grammar
commit d962b0a
Author: Nick Frost <nickfrostatx@gmail.com>
Date: Wed Jul 20 15:17:12 2016 -0700
Minor grammar fix
commit 24fff01aaccaf5956973ada8c50ceb1462e211c6 (typos)
Author: Chad Miller <chadm@squareup.com>
Date: Tue Sep 8 13:46:11 2020 -0400
Fix faulty comment about operation of unlink()
commit 3cd5c1f3326c52aa552ada7ec797c6bb16452355
Author: Kevin <kevin.xgr@gmail.com>
Date: Wed Nov 20 00:13:50 2019 +0800
Fix typo in server.c.
From a83af59 Mon Sep 17 00:00:00 2001
From: wuwo <wuwo@wacai.com>
Date: Fri, 17 Mar 2017 20:37:45 +0800
Subject: [PATCH] falure to failure
From c961896 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B7=A6=E6=87=B6?= <veficos@gmail.com>
Date: Sat, 27 May 2017 15:33:04 +0800
Subject: [PATCH] fix typo
From e600ef2 Mon Sep 17 00:00:00 2001
From: "rui.zou" <rui.zou@yunify.com>
Date: Sat, 30 Sep 2017 12:38:15 +0800
Subject: [PATCH] fix a typo
From c7d07fa Mon Sep 17 00:00:00 2001
From: Alexandre Perrin <alex@kaworu.ch>
Date: Thu, 16 Aug 2018 10:35:31 +0200
Subject: [PATCH] deps README.md typo
From b25cb67 Mon Sep 17 00:00:00 2001
From: Guy Korland <gkorland@gmail.com>
Date: Wed, 26 Sep 2018 10:55:37 +0300
Subject: [PATCH 1/2] fix typos in header
From ad28ca6 Mon Sep 17 00:00:00 2001
From: Guy Korland <gkorland@gmail.com>
Date: Wed, 26 Sep 2018 11:02:36 +0300
Subject: [PATCH 2/2] fix typos
commit 34924cdedd8552466fc22c1168d49236cb7ee915
Author: Adrian Lynch <adi_ady_ade@hotmail.com>
Date: Sat Apr 4 21:59:15 2015 +0100
Typos fixed
commit fd2a1e7
Author: Jan <jsteemann@users.noreply.github.com>
Date: Sat Oct 27 19:13:01 2018 +0200
Fix typos
Fix typos
commit e14e47c1a234b53b0e103c5f6a1c61481cbcbb02
Author: Andy Lester <andy@petdance.com>
Date: Fri Aug 2 22:30:07 2019 -0500
Fix multiple misspellings of "following"
commit 79b948ce2dac6b453fe80995abbcaac04c213d5a
Author: Andy Lester <andy@petdance.com>
Date: Fri Aug 2 22:24:28 2019 -0500
Fix misspelling of create-cluster
commit 1fffde52666dc99ab35efbd31071a4c008cb5a71
Author: Andy Lester <andy@petdance.com>
Date: Wed Jul 31 17:57:56 2019 -0500
Fix typos
commit 204c9ba9651e9e05fd73936b452b9a30be456cfe
Author: Xiaobo Zhu <xiaobo.zhu@shopee.com>
Date: Tue Aug 13 22:19:25 2019 +0800
fix typos
Squashed commit of the following:
commit 1d9aaf8
Author: danmedani <danmedani@gmail.com>
Date: Sun Aug 2 11:40:26 2015 -0700
README typo fix.
Squashed commit of the following:
commit 32bfa7c
Author: Erik Dubbelboer <erik@dubbelboer.com>
Date: Mon Jul 6 21:15:08 2015 +0200
Fixed grammer
Squashed commit of the following:
commit b24f69c
Author: Sisir Koppaka <sisir.koppaka@gmail.com>
Date: Mon Mar 2 22:38:45 2015 -0500
utils/hashtable/rehashing.c: Fix typos
Squashed commit of the following:
commit 4e04082
Author: Erik Dubbelboer <erik@dubbelboer.com>
Date: Mon Mar 23 08:22:21 2015 +0000
Small config file documentation improvements
Squashed commit of the following:
commit acb8773
Author: ctd1500 <ctd1500@gmail.com>
Date: Fri May 8 01:52:48 2015 -0700
Typo and grammar fixes in readme
commit 2eb75b6
Author: ctd1500 <ctd1500@gmail.com>
Date: Fri May 8 01:36:18 2015 -0700
fixed redis.conf comment
Squashed commit of the following:
commit a8249a2
Author: Masahiko Sawada <sawada.mshk@gmail.com>
Date: Fri Dec 11 11:39:52 2015 +0530
Revise correction of typos.
Squashed commit of the following:
commit 3c02028
Author: zhaojun11 <zhaojun11@jd.com>
Date: Wed Jan 17 19:05:28 2018 +0800
Fix typos include two code typos in cluster.c and latency.c
Squashed commit of the following:
commit 9dba47c
Author: q191201771 <191201771@qq.com>
Date: Sat Jan 4 11:31:04 2020 +0800
fix function listCreate comment in adlist.c
Update src/server.c
commit 2c7c2cb536e78dd211b1ac6f7bda00f0f54faaeb
Author: charpty <charpty@gmail.com>
Date: Tue May 1 23:16:59 2018 +0800
server.c typo: modules system dictionary type comment
Signed-off-by: charpty <charpty@gmail.com>
commit a8395323fb63cb59cb3591cb0f0c8edb7c29a680
Author: Itamar Haber <itamar@redislabs.com>
Date: Sun May 6 00:25:18 2018 +0300
Updates test_helper.tcl's help with undocumented options
Specifically:
* Host
* Port
* Client
commit bde6f9ced15755cd6407b4af7d601b030f36d60b
Author: wxisme <850885154@qq.com>
Date: Wed Aug 8 15:19:19 2018 +0800
fix comments in deps files
commit 3172474ba991532ab799ee1873439f3402412331
Author: wxisme <850885154@qq.com>
Date: Wed Aug 8 14:33:49 2018 +0800
fix some comments
commit 01b6f2b6858b5cf2ce4ad5092d2c746e755f53f0
Author: Thor Juhasz <thor@juhasz.pro>
Date: Sun Nov 18 14:37:41 2018 +0100
Minor fixes to comments
Found some parts a little unclear on a first read, which prompted me to have a better look at the file and fix some minor things I noticed.
Fixing minor typos and grammar. There are no changes to configuration options.
These changes are only meant to help the user better understand the explanations to the various configuration options
2020-09-10 06:43:38 -04:00
|
|
|
* On success the function returns the number of keys removed from the
|
2015-09-28 04:47:45 -04:00
|
|
|
* database(s). Otherwise -1 is returned in the specific case the
|
|
|
|
* DB number is out of range, and errno is set to EINVAL. */
|
2020-12-02 06:56:11 -05:00
|
|
|
long long emptyDb(int dbnum, int flags, void(callback)(void*)) {
|
2018-07-25 06:13:34 -04:00
|
|
|
int async = (flags & EMPTYDB_ASYNC);
|
2020-02-03 06:49:00 -05:00
|
|
|
RedisModuleFlushInfoV1 fi = {REDISMODULE_FLUSHINFO_VERSION,!async,dbnum};
|
2010-06-21 18:07:48 -04:00
|
|
|
long long removed = 0;
|
|
|
|
|
2015-09-28 04:47:45 -04:00
|
|
|
if (dbnum < -1 || dbnum >= server.dbnum) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-12-02 06:56:11 -05:00
|
|
|
/* Fire the flushdb modules event. */
|
|
|
|
moduleFireServerEvent(REDISMODULE_EVENT_FLUSHDB,
|
|
|
|
REDISMODULE_SUBEVENT_FLUSHDB_START,
|
|
|
|
&fi);
|
2020-02-03 06:49:00 -05:00
|
|
|
|
2020-12-02 06:56:11 -05:00
|
|
|
/* Make sure the WATCHed keys are affected by the FLUSH* commands.
|
|
|
|
* Note that we need to call the function while the keys are still
|
|
|
|
* there. */
|
|
|
|
signalFlushedDb(dbnum);
|
2019-07-30 05:20:51 -04:00
|
|
|
|
2020-12-02 06:56:11 -05:00
|
|
|
/* Empty redis database structure. */
|
|
|
|
removed = emptyDbStructure(server.db, dbnum, async, callback);
|
|
|
|
|
|
|
|
/* Flush slots to keys map if enable cluster, we can flush entire
|
|
|
|
* slots to keys map whatever dbnum because only support one DB
|
|
|
|
* in cluster mode. */
|
|
|
|
if (server.cluster_enabled) slotToKeyFlush(async);
|
|
|
|
|
|
|
|
if (dbnum == -1) flushSlaveKeysWithExpireList();
|
|
|
|
|
|
|
|
/* Also fire the end event. Note that this event will fire almost
|
|
|
|
* immediately after the start event if the flush is asynchronous. */
|
|
|
|
moduleFireServerEvent(REDISMODULE_EVENT_FLUSHDB,
|
|
|
|
REDISMODULE_SUBEVENT_FLUSHDB_END,
|
|
|
|
&fi);
|
|
|
|
|
|
|
|
return removed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store a backup of the database for later use, and put an empty one
|
|
|
|
* instead of it. */
|
|
|
|
dbBackup *backupDb(void) {
|
|
|
|
dbBackup *backup = zmalloc(sizeof(dbBackup));
|
|
|
|
|
|
|
|
/* Backup main DBs. */
|
|
|
|
backup->dbarray = zmalloc(sizeof(redisDb)*server.dbnum);
|
|
|
|
for (int i=0; i<server.dbnum; i++) {
|
|
|
|
backup->dbarray[i] = server.db[i];
|
|
|
|
server.db[i].dict = dictCreate(&dbDictType,NULL);
|
Limit the main db and expires dictionaries to expand (#7954)
As we know, redis may reject user's requests or evict some keys if
used memory is over maxmemory. Dictionaries expanding may make
things worse, some big dictionaries, such as main db and expires dict,
may eat huge memory at once for allocating a new big hash table and be
far more than maxmemory after expanding.
There are related issues: #4213 #4583
More details, when expand dict in redis, we will allocate a new big
ht[1] that generally is double of ht[0], The size of ht[1] will be
very big if ht[0] already is big. For db dict, if we have more than
64 million keys, we need to cost 1GB for ht[1] when dict expands.
If the sum of used memory and new hash table of dict needed exceeds
maxmemory, we shouldn't allow the dict to expand. Because, if we
enable keys eviction, we still couldn't add much more keys after
eviction and rehashing, what's worse, redis will keep less keys when
redis only remains a little memory for storing new hash table instead
of users' data. Moreover users can't write data in redis if disable
keys eviction.
What this commit changed ?
Add a new member function expandAllowed for dict type, it provide a way
for caller to allow expand or not. We expose two parameters for this
function: more memory needed for expanding and dict current load factor,
users can implement a function to make a decision by them.
For main db dict and expires dict type, these dictionaries may be very
big and cost huge memory for expanding, so we implement a judgement
function: we can stop dict to expand provisionally if used memory will
be over maxmemory after dict expands, but to guarantee the performance
of redis, we still allow dict to expand if dict load factor exceeds the
safe load factor.
Add test cases to verify we don't allow main db to expand when left
memory is not enough, so that avoid keys eviction.
Other changes:
For new hash table size when expand. Before this commit, the size is
that double used of dict and later _dictNextPower. Actually we aim to
control a dict load factor between 0.5 and 1.0. Now we replace *2 with
+1, since the first check is that used >= size, the outcome of before
will usually be the same as _dictNextPower(used+1). The only case where
it'll differ is when dict_can_resize is false during fork, so that later
the _dictNextPower(used*2) will cause the dict to jump to *4 (i.e.
_dictNextPower(1025*2) will return 4096).
Fix rehash test cases due to changing algorithm of new hash table size
when expand.
2020-12-06 04:53:04 -05:00
|
|
|
server.db[i].expires = dictCreate(&dbExpiresDictType,NULL);
|
2018-07-25 10:32:52 -04:00
|
|
|
}
|
2018-07-25 06:13:34 -04:00
|
|
|
|
2020-12-02 06:56:11 -05:00
|
|
|
/* Backup cluster slots to keys map if enable cluster. */
|
|
|
|
if (server.cluster_enabled) {
|
|
|
|
backup->slots_to_keys = server.cluster->slots_to_keys;
|
|
|
|
memcpy(backup->slots_keys_count, server.cluster->slots_keys_count,
|
|
|
|
sizeof(server.cluster->slots_keys_count));
|
|
|
|
server.cluster->slots_to_keys = raxNew();
|
|
|
|
memset(server.cluster->slots_keys_count, 0,
|
|
|
|
sizeof(server.cluster->slots_keys_count));
|
2015-09-28 04:47:45 -04:00
|
|
|
}
|
2020-02-03 06:49:00 -05:00
|
|
|
|
2020-12-02 06:56:11 -05:00
|
|
|
return backup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Discard a previously created backup, this can be slow (similar to FLUSHALL)
|
|
|
|
* Arguments are similar to the ones of emptyDb, see EMPTYDB_ flags. */
|
|
|
|
void discardDbBackup(dbBackup *buckup, int flags, void(callback)(void*)) {
|
|
|
|
int async = (flags & EMPTYDB_ASYNC);
|
2019-10-23 04:22:46 -04:00
|
|
|
|
2020-12-02 06:56:11 -05:00
|
|
|
/* Release main DBs backup . */
|
|
|
|
emptyDbStructure(buckup->dbarray, -1, async, callback);
|
|
|
|
for (int i=0; i<server.dbnum; i++) {
|
|
|
|
dictRelease(buckup->dbarray[i].dict);
|
|
|
|
dictRelease(buckup->dbarray[i].expires);
|
2020-02-03 06:49:00 -05:00
|
|
|
}
|
2019-10-23 04:22:46 -04:00
|
|
|
|
2020-12-02 06:56:11 -05:00
|
|
|
/* Release slots to keys map backup if enable cluster. */
|
|
|
|
if (server.cluster_enabled) freeSlotsToKeysMap(buckup->slots_to_keys, async);
|
|
|
|
|
|
|
|
/* Release buckup. */
|
|
|
|
zfree(buckup->dbarray);
|
|
|
|
zfree(buckup);
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
|
2020-12-02 06:56:11 -05:00
|
|
|
/* Restore the previously created backup (discarding what currently resides
|
|
|
|
* in the db).
|
|
|
|
* This function should be called after the current contents of the database
|
|
|
|
* was emptied with a previous call to emptyDb (possibly using the async mode). */
|
|
|
|
void restoreDbBackup(dbBackup *buckup) {
|
|
|
|
/* Restore main DBs. */
|
|
|
|
for (int i=0; i<server.dbnum; i++) {
|
|
|
|
serverAssert(dictSize(server.db[i].dict) == 0);
|
|
|
|
serverAssert(dictSize(server.db[i].expires) == 0);
|
|
|
|
dictRelease(server.db[i].dict);
|
|
|
|
dictRelease(server.db[i].expires);
|
|
|
|
server.db[i] = buckup->dbarray[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restore slots to keys map backup if enable cluster. */
|
|
|
|
if (server.cluster_enabled) {
|
|
|
|
serverAssert(server.cluster->slots_to_keys->numele == 0);
|
|
|
|
raxFree(server.cluster->slots_to_keys);
|
|
|
|
server.cluster->slots_to_keys = buckup->slots_to_keys;
|
|
|
|
memcpy(server.cluster->slots_keys_count, buckup->slots_keys_count,
|
|
|
|
sizeof(server.cluster->slots_keys_count));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release buckup. */
|
|
|
|
zfree(buckup->dbarray);
|
|
|
|
zfree(buckup);
|
2019-07-01 08:22:29 -04:00
|
|
|
}
|
|
|
|
|
2015-07-26 09:20:46 -04:00
|
|
|
int selectDb(client *c, int id) {
|
2010-06-21 18:07:48 -04:00
|
|
|
if (id < 0 || id >= server.dbnum)
|
2015-07-26 17:17:55 -04:00
|
|
|
return C_ERR;
|
2010-06-21 18:07:48 -04:00
|
|
|
c->db = &server.db[id];
|
2015-07-26 17:17:55 -04:00
|
|
|
return C_OK;
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
|
2019-07-01 08:22:29 -04:00
|
|
|
long long dbTotalServerKeyCount() {
|
|
|
|
long long total = 0;
|
|
|
|
int j;
|
|
|
|
for (j = 0; j < server.dbnum; j++) {
|
|
|
|
total += dictSize(server.db[j].dict);
|
|
|
|
}
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
2010-12-29 13:39:42 -05:00
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
* Hooks for key space changes.
|
|
|
|
*
|
|
|
|
* Every time a key in the database is modified the function
|
|
|
|
* signalModifiedKey() is called.
|
|
|
|
*
|
|
|
|
* Every time a DB is flushed the function signalFlushDb() is called.
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
|
2020-04-21 04:51:46 -04:00
|
|
|
/* Note that the 'c' argument may be NULL if the key was modified out of
|
|
|
|
* a context of a client. */
|
|
|
|
void signalModifiedKey(client *c, redisDb *db, robj *key) {
|
2010-12-29 13:39:42 -05:00
|
|
|
touchWatchedKey(db,key);
|
2020-04-21 04:51:46 -04:00
|
|
|
trackingInvalidateKey(c,key);
|
2010-12-29 13:39:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void signalFlushedDb(int dbid) {
|
|
|
|
touchWatchedKeysOnFlush(dbid);
|
2019-07-22 06:29:54 -04:00
|
|
|
trackingInvalidateKeysOnFlush(dbid);
|
2010-12-29 13:39:42 -05:00
|
|
|
}
|
|
|
|
|
2010-06-21 18:07:48 -04:00
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
* Type agnostic commands operating on the key space
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
|
2015-09-28 05:05:39 -04:00
|
|
|
/* Return the set of flags to use for the emptyDb() call for FLUSHALL
|
|
|
|
* and FLUSHDB commands.
|
|
|
|
*
|
|
|
|
* Currently the command just attempts to parse the "ASYNC" option. It
|
|
|
|
* also checks if the command arity is wrong.
|
|
|
|
*
|
|
|
|
* On success C_OK is returned and the flags are stored in *flags, otherwise
|
|
|
|
* C_ERR is returned and the function sends an error to the client. */
|
|
|
|
int getFlushCommandFlags(client *c, int *flags) {
|
|
|
|
/* Parse the optional ASYNC option. */
|
|
|
|
if (c->argc > 1) {
|
|
|
|
if (c->argc > 2 || strcasecmp(c->argv[1]->ptr,"async")) {
|
|
|
|
addReply(c,shared.syntaxerr);
|
|
|
|
return C_ERR;
|
|
|
|
}
|
|
|
|
*flags = EMPTYDB_ASYNC;
|
|
|
|
} else {
|
|
|
|
*flags = EMPTYDB_NO_FLAGS;
|
|
|
|
}
|
|
|
|
return C_OK;
|
|
|
|
}
|
|
|
|
|
2019-11-03 10:35:35 -05:00
|
|
|
/* Flushes the whole server data set. */
|
|
|
|
void flushAllDataAndResetRDB(int flags) {
|
|
|
|
server.dirty += emptyDb(-1,flags,NULL);
|
|
|
|
if (server.rdb_child_pid != -1) killRDBChild();
|
|
|
|
if (server.saveparamslen > 0) {
|
|
|
|
/* Normally rdbSave() will reset dirty, but we don't want this here
|
|
|
|
* as otherwise FLUSHALL will not be replicated nor put into the AOF. */
|
|
|
|
int saved_dirty = server.dirty;
|
|
|
|
rdbSaveInfo rsi, *rsiptr;
|
|
|
|
rsiptr = rdbPopulateSaveInfo(&rsi);
|
|
|
|
rdbSave(server.rdb_filename,rsiptr);
|
|
|
|
server.dirty = saved_dirty;
|
|
|
|
}
|
|
|
|
server.dirty++;
|
|
|
|
#if defined(USE_JEMALLOC)
|
|
|
|
/* jemalloc 5 doesn't release pages back to the OS when there's no traffic.
|
|
|
|
* for large databases, flushdb blocks for long anyway, so a bit more won't
|
|
|
|
* harm and this way the flush and purge will be synchroneus. */
|
|
|
|
if (!(flags & EMPTYDB_ASYNC))
|
|
|
|
jemalloc_purge();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-09-28 05:05:39 -04:00
|
|
|
/* FLUSHDB [ASYNC]
|
|
|
|
*
|
|
|
|
* Flushes the currently SELECTed Redis DB. */
|
2015-07-26 09:20:46 -04:00
|
|
|
void flushdbCommand(client *c) {
|
2015-09-28 05:05:39 -04:00
|
|
|
int flags;
|
|
|
|
|
|
|
|
if (getFlushCommandFlags(c,&flags) == C_ERR) return;
|
|
|
|
server.dirty += emptyDb(c->db->id,flags,NULL);
|
2010-06-21 18:07:48 -04:00
|
|
|
addReply(c,shared.ok);
|
2019-05-30 05:51:32 -04:00
|
|
|
#if defined(USE_JEMALLOC)
|
|
|
|
/* jemalloc 5 doesn't release pages back to the OS when there's no traffic.
|
|
|
|
* for large databases, flushdb blocks for long anyway, so a bit more won't
|
|
|
|
* harm and this way the flush and purge will be synchroneus. */
|
|
|
|
if (!(flags & EMPTYDB_ASYNC))
|
|
|
|
jemalloc_purge();
|
|
|
|
#endif
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
|
2015-09-28 05:05:39 -04:00
|
|
|
/* FLUSHALL [ASYNC]
|
|
|
|
*
|
|
|
|
* Flushes the whole server data set. */
|
2015-07-26 09:20:46 -04:00
|
|
|
void flushallCommand(client *c) {
|
2015-09-28 05:05:39 -04:00
|
|
|
int flags;
|
|
|
|
if (getFlushCommandFlags(c,&flags) == C_ERR) return;
|
2019-11-03 10:35:35 -05:00
|
|
|
flushAllDataAndResetRDB(flags);
|
2010-06-21 18:07:48 -04:00
|
|
|
addReply(c,shared.ok);
|
|
|
|
}
|
|
|
|
|
2015-07-30 05:46:31 -04:00
|
|
|
/* This command implements DEL and LAZYDEL. */
|
|
|
|
void delGenericCommand(client *c, int lazy) {
|
|
|
|
int numdel = 0, j;
|
2010-06-21 18:07:48 -04:00
|
|
|
|
|
|
|
for (j = 1; j < c->argc; j++) {
|
2014-04-10 17:08:02 -04:00
|
|
|
expireIfNeeded(c->db,c->argv[j]);
|
2015-07-30 05:46:31 -04:00
|
|
|
int deleted = lazy ? dbAsyncDelete(c->db,c->argv[j]) :
|
|
|
|
dbSyncDelete(c->db,c->argv[j]);
|
|
|
|
if (deleted) {
|
2020-04-21 04:51:46 -04:00
|
|
|
signalModifiedKey(c,c->db,c->argv[j]);
|
2015-07-27 03:41:48 -04:00
|
|
|
notifyKeyspaceEvent(NOTIFY_GENERIC,
|
2013-01-25 07:19:08 -05:00
|
|
|
"del",c->argv[j],c->db->id);
|
2010-06-21 18:07:48 -04:00
|
|
|
server.dirty++;
|
2015-07-30 05:46:31 -04:00
|
|
|
numdel++;
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
}
|
2015-07-30 05:46:31 -04:00
|
|
|
addReplyLongLong(c,numdel);
|
|
|
|
}
|
|
|
|
|
|
|
|
void delCommand(client *c) {
|
2019-07-16 23:00:51 -04:00
|
|
|
delGenericCommand(c,server.lazyfree_lazy_user_del);
|
2015-07-30 05:46:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void unlinkCommand(client *c) {
|
|
|
|
delGenericCommand(c,1);
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
|
2015-07-13 12:06:24 -04:00
|
|
|
/* EXISTS key1 key2 ... key_N.
|
|
|
|
* Return value is the number of keys existing. */
|
2015-07-26 09:20:46 -04:00
|
|
|
void existsCommand(client *c) {
|
2015-07-13 12:06:24 -04:00
|
|
|
long long count = 0;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 1; j < c->argc; j++) {
|
2020-11-18 04:16:21 -05:00
|
|
|
if (lookupKeyReadWithFlags(c->db,c->argv[j],LOOKUP_NOTOUCH)) count++;
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
2015-07-13 12:06:24 -04:00
|
|
|
addReplyLongLong(c,count);
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
|
2015-07-26 09:20:46 -04:00
|
|
|
void selectCommand(client *c) {
|
Improve dbid range check for SELECT, MOVE, COPY (#8085)
SELECT used to read the index into a `long` variable, and then pass it to a function
that takes an `int`, possibly causing an overflow before the range check.
Now all these commands use better and cleaner range check, and that also results in
a slight change of the error response in case of an invalid database index.
SELECT:
in the past it would have returned either `-ERR invalid DB index` (if not a number),
or `-ERR DB index is out of range` (if not between 1..16 or alike).
now it'll return either `-ERR value is out of range` (if not a number), or
`-ERR value is out of range, value must between -2147483648 and 2147483647`
(if not in the range for an int), or `-ERR DB index is out of range`
(if not between 0..16 or alike)
MOVE:
in the past it would only fail with `-ERR index out of range` no matter the reason.
now return the same errors as the new ones for SELECT mentioned above.
(i.e. unlike for SELECT even for a value like 17 we changed the error message)
COPY:
doesn't really matter how it behaved in the past (new command), new behavior is
like the above two.
2020-12-01 14:41:26 -05:00
|
|
|
int id;
|
2012-09-11 04:32:04 -04:00
|
|
|
|
Improve dbid range check for SELECT, MOVE, COPY (#8085)
SELECT used to read the index into a `long` variable, and then pass it to a function
that takes an `int`, possibly causing an overflow before the range check.
Now all these commands use better and cleaner range check, and that also results in
a slight change of the error response in case of an invalid database index.
SELECT:
in the past it would have returned either `-ERR invalid DB index` (if not a number),
or `-ERR DB index is out of range` (if not between 1..16 or alike).
now it'll return either `-ERR value is out of range` (if not a number), or
`-ERR value is out of range, value must between -2147483648 and 2147483647`
(if not in the range for an int), or `-ERR DB index is out of range`
(if not between 0..16 or alike)
MOVE:
in the past it would only fail with `-ERR index out of range` no matter the reason.
now return the same errors as the new ones for SELECT mentioned above.
(i.e. unlike for SELECT even for a value like 17 we changed the error message)
COPY:
doesn't really matter how it behaved in the past (new command), new behavior is
like the above two.
2020-12-01 14:41:26 -05:00
|
|
|
if (getIntFromObjectOrReply(c, c->argv[1], &id, NULL) != C_OK)
|
2012-09-11 04:32:04 -04:00
|
|
|
return;
|
2010-06-21 18:07:48 -04:00
|
|
|
|
2011-05-05 12:10:02 -04:00
|
|
|
if (server.cluster_enabled && id != 0) {
|
2011-03-29 11:51:15 -04:00
|
|
|
addReplyError(c,"SELECT is not allowed in cluster mode");
|
|
|
|
return;
|
|
|
|
}
|
2015-07-26 17:17:55 -04:00
|
|
|
if (selectDb(c,id) == C_ERR) {
|
SWAPDB command.
This new command swaps two Redis databases, so that immediately all the
clients connected to a given DB will see the data of the other DB, and
the other way around. Example:
SWAPDB 0 1
This will swap DB 0 with DB 1. All the clients connected with DB 0 will
immediately see the new data, exactly like all the clients connected
with DB 1 will see the data that was formerly of DB 0.
MOTIVATION AND HISTORY
---
The command was recently demanded by Pedro Melo, but was suggested in
the past multiple times, and always refused by me.
The reason why it was asked: Imagine you have clients operating in DB 0.
At the same time, you create a new version of the dataset in DB 1.
When the new version of the dataset is available, you immediately want
to swap the two views, so that the clients will transparently use the
new version of the data. At the same time you'll likely destroy the
DB 1 dataset (that contains the old data) and start to build a new
version, to repeat the process.
This is an interesting pattern, but the reason why I always opposed to
implement this, was that FLUSHDB was a blocking command in Redis before
Redis 4.0 improvements. Now we have FLUSHDB ASYNC that releases the
old data in O(1) from the point of view of the client, to reclaim memory
incrementally in a different thread.
At this point, the pattern can really be supported without latency
spikes, so I'm providing this implementation for the users to comment.
In case a very compelling argument will be made against this new command
it may be removed.
BEHAVIOR WITH BLOCKING OPERATIONS
---
If a client is blocking for a list in a given DB, after the swap it will
still be blocked in the same DB ID, since this is the most logical thing
to do: if I was blocked for a list push to list "foo", even after the
swap I want still a LPUSH to reach the key "foo" in the same DB in order
to unblock.
However an interesting thing happens when a client is, for instance,
blocked waiting for new elements in list "foo" of DB 0. Then the DB
0 and 1 are swapped with SWAPDB. However the DB 1 happened to have
a list called "foo" containing elements. When this happens, this
implementation can correctly unblock the client.
It is possible that there are subtle corner cases that are not covered
in the implementation, but since the command is self-contained from the
POV of the implementation and the Redis core, it cannot cause anything
bad if not used.
Tests and documentation are yet to be provided.
2016-10-14 09:28:04 -04:00
|
|
|
addReplyError(c,"DB index is out of range");
|
2010-06-21 18:07:48 -04:00
|
|
|
} else {
|
|
|
|
addReply(c,shared.ok);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-26 09:20:46 -04:00
|
|
|
void randomkeyCommand(client *c) {
|
2010-06-21 18:07:48 -04:00
|
|
|
robj *key;
|
|
|
|
|
|
|
|
if ((key = dbRandomKey(c->db)) == NULL) {
|
2018-11-30 03:41:54 -05:00
|
|
|
addReplyNull(c);
|
2010-06-21 18:07:48 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
addReplyBulk(c,key);
|
|
|
|
decrRefCount(key);
|
|
|
|
}
|
|
|
|
|
2015-07-26 09:20:46 -04:00
|
|
|
void keysCommand(client *c) {
|
2010-06-21 18:07:48 -04:00
|
|
|
dictIterator *di;
|
|
|
|
dictEntry *de;
|
|
|
|
sds pattern = c->argv[1]->ptr;
|
2010-08-30 05:51:45 -04:00
|
|
|
int plen = sdslen(pattern), allkeys;
|
2010-06-21 18:07:48 -04:00
|
|
|
unsigned long numkeys = 0;
|
2018-11-09 06:59:00 -05:00
|
|
|
void *replylen = addReplyDeferredLen(c);
|
2010-06-21 18:07:48 -04:00
|
|
|
|
2012-04-30 13:16:20 -04:00
|
|
|
di = dictGetSafeIterator(c->db->dict);
|
2020-01-07 14:55:26 -05:00
|
|
|
allkeys = (pattern[0] == '*' && plen == 1);
|
2010-06-21 18:07:48 -04:00
|
|
|
while((de = dictNext(di)) != NULL) {
|
2011-11-08 11:07:55 -05:00
|
|
|
sds key = dictGetKey(de);
|
2010-06-21 18:07:48 -04:00
|
|
|
robj *keyobj;
|
|
|
|
|
2010-08-30 05:51:45 -04:00
|
|
|
if (allkeys || stringmatchlen(pattern,plen,key,sdslen(key),0)) {
|
2010-06-21 18:07:48 -04:00
|
|
|
keyobj = createStringObject(key,sdslen(key));
|
2018-10-19 06:00:57 -04:00
|
|
|
if (!keyIsExpired(c->db,keyobj)) {
|
2010-06-21 18:07:48 -04:00
|
|
|
addReplyBulk(c,keyobj);
|
|
|
|
numkeys++;
|
|
|
|
}
|
|
|
|
decrRefCount(keyobj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dictReleaseIterator(di);
|
2018-11-09 06:59:00 -05:00
|
|
|
setDeferredArrayLen(c,replylen,numkeys);
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
|
2013-10-28 06:11:34 -04:00
|
|
|
/* This callback is used by scanGenericCommand in order to collect elements
|
|
|
|
* returned by the dictionary iterator into a list. */
|
2012-07-09 04:00:26 -04:00
|
|
|
void scanCallback(void *privdata, const dictEntry *de) {
|
2013-10-28 06:11:34 -04:00
|
|
|
void **pd = (void**) privdata;
|
|
|
|
list *keys = pd[0];
|
|
|
|
robj *o = pd[1];
|
|
|
|
robj *key, *val = NULL;
|
|
|
|
|
|
|
|
if (o == NULL) {
|
|
|
|
sds sdskey = dictGetKey(de);
|
|
|
|
key = createStringObject(sdskey, sdslen(sdskey));
|
2015-07-26 09:28:00 -04:00
|
|
|
} else if (o->type == OBJ_SET) {
|
2015-07-31 12:01:23 -04:00
|
|
|
sds keysds = dictGetKey(de);
|
|
|
|
key = createStringObject(keysds,sdslen(keysds));
|
2015-07-26 09:28:00 -04:00
|
|
|
} else if (o->type == OBJ_HASH) {
|
2015-09-22 03:42:46 -04:00
|
|
|
sds sdskey = dictGetKey(de);
|
|
|
|
sds sdsval = dictGetVal(de);
|
2015-09-23 03:33:23 -04:00
|
|
|
key = createStringObject(sdskey,sdslen(sdskey));
|
|
|
|
val = createStringObject(sdsval,sdslen(sdsval));
|
2015-07-26 09:28:00 -04:00
|
|
|
} else if (o->type == OBJ_ZSET) {
|
2015-09-23 03:33:23 -04:00
|
|
|
sds sdskey = dictGetKey(de);
|
|
|
|
key = createStringObject(sdskey,sdslen(sdskey));
|
2014-12-02 12:19:30 -05:00
|
|
|
val = createStringObjectFromLongDouble(*(double*)dictGetVal(de),0);
|
2013-10-28 06:11:34 -04:00
|
|
|
} else {
|
2015-07-27 03:41:48 -04:00
|
|
|
serverPanic("Type not handled in SCAN callback.");
|
2013-10-28 06:11:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
listAddNodeTail(keys, key);
|
|
|
|
if (val) listAddNodeTail(keys, val);
|
2012-07-09 04:00:26 -04:00
|
|
|
}
|
|
|
|
|
2013-11-05 11:23:11 -05:00
|
|
|
/* Try to parse a SCAN cursor stored at object 'o':
|
2013-11-05 09:47:50 -05:00
|
|
|
* if the cursor is valid, store it as unsigned integer into *cursor and
|
2015-07-26 17:17:55 -04:00
|
|
|
* returns C_OK. Otherwise return C_ERR and send an error to the
|
2013-11-05 09:47:50 -05:00
|
|
|
* client. */
|
2015-07-26 09:20:46 -04:00
|
|
|
int parseScanCursorOrReply(client *c, robj *o, unsigned long *cursor) {
|
2013-11-05 09:47:50 -05:00
|
|
|
char *eptr;
|
|
|
|
|
|
|
|
/* Use strtoul() because we need an *unsigned* long, so
|
|
|
|
* getLongLongFromObject() does not cover the whole cursor space. */
|
|
|
|
errno = 0;
|
|
|
|
*cursor = strtoul(o->ptr, &eptr, 10);
|
|
|
|
if (isspace(((char*)o->ptr)[0]) || eptr[0] != '\0' || errno == ERANGE)
|
|
|
|
{
|
|
|
|
addReplyError(c, "invalid cursor");
|
2015-07-26 17:17:55 -04:00
|
|
|
return C_ERR;
|
2013-11-05 09:47:50 -05:00
|
|
|
}
|
2015-07-26 17:17:55 -04:00
|
|
|
return C_OK;
|
2013-11-05 09:47:50 -05:00
|
|
|
}
|
|
|
|
|
2013-10-28 06:11:34 -04:00
|
|
|
/* This command implements SCAN, HSCAN and SSCAN commands.
|
2019-05-22 11:39:04 -04:00
|
|
|
* If object 'o' is passed, then it must be a Hash, Set or Zset object, otherwise
|
2013-10-28 06:11:34 -04:00
|
|
|
* if 'o' is NULL the command will operate on the dictionary associated with
|
|
|
|
* the current database.
|
|
|
|
*
|
|
|
|
* When 'o' is not NULL the function assumes that the first argument in
|
|
|
|
* the client arguments vector is a key so it skips it before iterating
|
|
|
|
* in order to parse options.
|
|
|
|
*
|
2013-12-05 10:35:32 -05:00
|
|
|
* In the case of a Hash object the function returns both the field and value
|
2013-10-28 06:11:34 -04:00
|
|
|
* of every element on the Hash. */
|
2015-07-26 09:20:46 -04:00
|
|
|
void scanGenericCommand(client *c, robj *o, unsigned long cursor) {
|
2012-07-09 04:00:26 -04:00
|
|
|
int i, j;
|
|
|
|
list *keys = listCreate();
|
2013-10-25 05:54:37 -04:00
|
|
|
listNode *node, *nextnode;
|
2013-10-28 06:11:34 -04:00
|
|
|
long count = 10;
|
2014-12-11 22:02:39 -05:00
|
|
|
sds pat = NULL;
|
2019-05-22 11:39:04 -04:00
|
|
|
sds typename = NULL;
|
2014-12-11 22:02:39 -05:00
|
|
|
int patlen = 0, use_pattern = 0;
|
2013-10-28 06:11:34 -04:00
|
|
|
dict *ht;
|
|
|
|
|
|
|
|
/* Object must be NULL (to iterate keys names), or the type of the object
|
|
|
|
* must be Set, Sorted Set, or Hash. */
|
2015-07-26 09:29:53 -04:00
|
|
|
serverAssert(o == NULL || o->type == OBJ_SET || o->type == OBJ_HASH ||
|
2015-07-26 09:28:00 -04:00
|
|
|
o->type == OBJ_ZSET);
|
2013-10-28 06:11:34 -04:00
|
|
|
|
|
|
|
/* Set i to the first option argument. The previous one is the cursor. */
|
|
|
|
i = (o == NULL) ? 2 : 3; /* Skip the key argument if needed. */
|
2012-07-09 04:00:26 -04:00
|
|
|
|
2013-10-28 06:11:34 -04:00
|
|
|
/* Step 1: Parse options. */
|
2012-07-09 04:00:26 -04:00
|
|
|
while (i < c->argc) {
|
|
|
|
j = c->argc - i;
|
|
|
|
if (!strcasecmp(c->argv[i]->ptr, "count") && j >= 2) {
|
2013-10-25 06:01:49 -04:00
|
|
|
if (getLongFromObjectOrReply(c, c->argv[i+1], &count, NULL)
|
2015-07-26 17:17:55 -04:00
|
|
|
!= C_OK)
|
2013-10-25 06:01:49 -04:00
|
|
|
{
|
2012-07-09 04:00:26 -04:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count < 1) {
|
|
|
|
addReply(c,shared.syntaxerr);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
i += 2;
|
2013-10-25 05:45:32 -04:00
|
|
|
} else if (!strcasecmp(c->argv[i]->ptr, "match") && j >= 2) {
|
2012-07-09 04:00:26 -04:00
|
|
|
pat = c->argv[i+1]->ptr;
|
|
|
|
patlen = sdslen(pat);
|
|
|
|
|
2013-10-31 05:35:56 -04:00
|
|
|
/* The pattern always matches if it is exactly "*", so it is
|
|
|
|
* equivalent to disabling it. */
|
|
|
|
use_pattern = !(pat[0] == '*' && patlen == 1);
|
2012-07-09 04:00:26 -04:00
|
|
|
|
|
|
|
i += 2;
|
2019-05-22 11:39:04 -04:00
|
|
|
} else if (!strcasecmp(c->argv[i]->ptr, "type") && o == NULL && j >= 2) {
|
|
|
|
/* SCAN for a particular type only applies to the db dict */
|
|
|
|
typename = c->argv[i+1]->ptr;
|
|
|
|
i+= 2;
|
2012-07-09 04:00:26 -04:00
|
|
|
} else {
|
|
|
|
addReply(c,shared.syntaxerr);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-28 06:11:34 -04:00
|
|
|
/* Step 2: Iterate the collection.
|
|
|
|
*
|
|
|
|
* Note that if the object is encoded with a ziplist, intset, or any other
|
2013-12-05 10:35:32 -05:00
|
|
|
* representation that is not a hash table, we are sure that it is also
|
2013-10-28 06:11:34 -04:00
|
|
|
* composed of a small number of elements. So to avoid taking state we
|
|
|
|
* just return everything inside the object in a single call, setting the
|
|
|
|
* cursor to zero to signal the end of the iteration. */
|
|
|
|
|
2013-12-05 10:35:32 -05:00
|
|
|
/* Handle the case of a hash table. */
|
2013-10-28 06:11:34 -04:00
|
|
|
ht = NULL;
|
|
|
|
if (o == NULL) {
|
|
|
|
ht = c->db->dict;
|
2015-07-26 09:28:00 -04:00
|
|
|
} else if (o->type == OBJ_SET && o->encoding == OBJ_ENCODING_HT) {
|
2013-10-28 06:11:34 -04:00
|
|
|
ht = o->ptr;
|
2015-07-26 09:28:00 -04:00
|
|
|
} else if (o->type == OBJ_HASH && o->encoding == OBJ_ENCODING_HT) {
|
2013-10-28 06:11:34 -04:00
|
|
|
ht = o->ptr;
|
|
|
|
count *= 2; /* We return key / value for this type. */
|
2015-07-26 09:28:00 -04:00
|
|
|
} else if (o->type == OBJ_ZSET && o->encoding == OBJ_ENCODING_SKIPLIST) {
|
2013-10-28 06:11:34 -04:00
|
|
|
zset *zs = o->ptr;
|
|
|
|
ht = zs->dict;
|
|
|
|
count *= 2; /* We return key / value for this type. */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ht) {
|
|
|
|
void *privdata[2];
|
2014-09-09 05:53:30 -04:00
|
|
|
/* We set the max number of iterations to ten times the specified
|
|
|
|
* COUNT, so if the hash table is in a pathological state (very
|
|
|
|
* sparsely populated) we avoid to block too much time at the cost
|
|
|
|
* of returning no or very few elements. */
|
|
|
|
long maxiterations = count*10;
|
2013-10-28 06:11:34 -04:00
|
|
|
|
|
|
|
/* We pass two pointers to the callback: the list to which it will
|
|
|
|
* add new elements, and the object containing the dictionary so that
|
|
|
|
* it is possible to fetch more data in a type-dependent way. */
|
|
|
|
privdata[0] = keys;
|
|
|
|
privdata[1] = o;
|
|
|
|
do {
|
2016-12-29 20:37:52 -05:00
|
|
|
cursor = dictScan(ht, cursor, scanCallback, NULL, privdata);
|
2014-09-09 05:53:30 -04:00
|
|
|
} while (cursor &&
|
|
|
|
maxiterations-- &&
|
|
|
|
listLength(keys) < (unsigned long)count);
|
2015-07-26 09:28:00 -04:00
|
|
|
} else if (o->type == OBJ_SET) {
|
2013-10-28 06:11:34 -04:00
|
|
|
int pos = 0;
|
2013-11-05 05:57:30 -05:00
|
|
|
int64_t ll;
|
2013-10-28 06:11:34 -04:00
|
|
|
|
|
|
|
while(intsetGet(o->ptr,pos++,&ll))
|
|
|
|
listAddNodeTail(keys,createStringObjectFromLongLong(ll));
|
2013-11-05 09:32:21 -05:00
|
|
|
cursor = 0;
|
2015-07-26 09:28:00 -04:00
|
|
|
} else if (o->type == OBJ_HASH || o->type == OBJ_ZSET) {
|
2013-10-28 06:11:34 -04:00
|
|
|
unsigned char *p = ziplistIndex(o->ptr,0);
|
|
|
|
unsigned char *vstr;
|
|
|
|
unsigned int vlen;
|
|
|
|
long long vll;
|
|
|
|
|
|
|
|
while(p) {
|
|
|
|
ziplistGet(p,&vstr,&vlen,&vll);
|
|
|
|
listAddNodeTail(keys,
|
|
|
|
(vstr != NULL) ? createStringObject((char*)vstr,vlen) :
|
|
|
|
createStringObjectFromLongLong(vll));
|
2013-10-28 06:32:34 -04:00
|
|
|
p = ziplistNext(o->ptr,p);
|
2013-10-28 06:11:34 -04:00
|
|
|
}
|
2013-11-05 09:32:21 -05:00
|
|
|
cursor = 0;
|
2013-10-28 06:11:34 -04:00
|
|
|
} else {
|
2015-07-27 03:41:48 -04:00
|
|
|
serverPanic("Not handled encoding in SCAN.");
|
2013-10-28 06:11:34 -04:00
|
|
|
}
|
2012-07-09 04:00:26 -04:00
|
|
|
|
2013-10-28 06:11:34 -04:00
|
|
|
/* Step 3: Filter elements. */
|
2013-10-25 05:54:37 -04:00
|
|
|
node = listFirst(keys);
|
|
|
|
while (node) {
|
|
|
|
robj *kobj = listNodeValue(node);
|
|
|
|
nextnode = listNextNode(node);
|
2013-10-31 05:32:33 -04:00
|
|
|
int filter = 0;
|
|
|
|
|
|
|
|
/* Filter element if it does not match the pattern. */
|
2013-10-31 05:35:56 -04:00
|
|
|
if (!filter && use_pattern) {
|
2013-10-31 05:32:33 -04:00
|
|
|
if (sdsEncodedObject(kobj)) {
|
|
|
|
if (!stringmatchlen(pat, patlen, kobj->ptr, sdslen(kobj->ptr), 0))
|
|
|
|
filter = 1;
|
|
|
|
} else {
|
2015-07-27 03:41:48 -04:00
|
|
|
char buf[LONG_STR_SIZE];
|
2013-10-31 05:32:33 -04:00
|
|
|
int len;
|
|
|
|
|
2015-07-26 09:29:53 -04:00
|
|
|
serverAssert(kobj->encoding == OBJ_ENCODING_INT);
|
2013-10-31 05:32:33 -04:00
|
|
|
len = ll2string(buf,sizeof(buf),(long)kobj->ptr);
|
|
|
|
if (!stringmatchlen(pat, patlen, buf, len, 0)) filter = 1;
|
|
|
|
}
|
|
|
|
}
|
2012-07-09 04:00:26 -04:00
|
|
|
|
2019-05-22 11:39:04 -04:00
|
|
|
/* Filter an element if it isn't the type we want. */
|
|
|
|
if (!filter && o == NULL && typename){
|
2019-06-10 12:41:44 -04:00
|
|
|
robj* typecheck = lookupKeyReadWithFlags(c->db, kobj, LOOKUP_NOTOUCH);
|
2019-07-08 06:04:37 -04:00
|
|
|
char* type = getObjectTypeName(typecheck);
|
2019-05-22 11:39:04 -04:00
|
|
|
if (strcasecmp((char*) typename, type)) filter = 1;
|
|
|
|
}
|
|
|
|
|
2013-10-31 05:32:33 -04:00
|
|
|
/* Filter element if it is an expired key. */
|
|
|
|
if (!filter && o == NULL && expireIfNeeded(c->db, kobj)) filter = 1;
|
|
|
|
|
Squash merging 125 typo/grammar/comment/doc PRs (#7773)
List of squashed commits or PRs
===============================
commit 66801ea
Author: hwware <wen.hui.ware@gmail.com>
Date: Mon Jan 13 00:54:31 2020 -0500
typo fix in acl.c
commit 46f55db
Author: Itamar Haber <itamar@redislabs.com>
Date: Sun Sep 6 18:24:11 2020 +0300
Updates a couple of comments
Specifically:
* RM_AutoMemory completed instead of pointing to docs
* Updated link to custom type doc
commit 61a2aa0
Author: xindoo <xindoo@qq.com>
Date: Tue Sep 1 19:24:59 2020 +0800
Correct errors in code comments
commit a5871d1
Author: yz1509 <pro-756@qq.com>
Date: Tue Sep 1 18:36:06 2020 +0800
fix typos in module.c
commit 41eede7
Author: bookug <bookug@qq.com>
Date: Sat Aug 15 01:11:33 2020 +0800
docs: fix typos in comments
commit c303c84
Author: lazy-snail <ws.niu@outlook.com>
Date: Fri Aug 7 11:15:44 2020 +0800
fix spelling in redis.conf
commit 1eb76bf
Author: zhujian <zhujianxyz@gmail.com>
Date: Thu Aug 6 15:22:10 2020 +0800
add a missing 'n' in comment
commit 1530ec2
Author: Daniel Dai <764122422@qq.com>
Date: Mon Jul 27 00:46:35 2020 -0400
fix spelling in tracking.c
commit e517b31
Author: Hunter-Chen <huntcool001@gmail.com>
Date: Fri Jul 17 22:33:32 2020 +0800
Update redis.conf
Co-authored-by: Itamar Haber <itamar@redislabs.com>
commit c300eff
Author: Hunter-Chen <huntcool001@gmail.com>
Date: Fri Jul 17 22:33:23 2020 +0800
Update redis.conf
Co-authored-by: Itamar Haber <itamar@redislabs.com>
commit 4c058a8
Author: 陈浩鹏 <chenhaopeng@heytea.com>
Date: Thu Jun 25 19:00:56 2020 +0800
Grammar fix and clarification
commit 5fcaa81
Author: bodong.ybd <bodong.ybd@alibaba-inc.com>
Date: Fri Jun 19 10:09:00 2020 +0800
Fix typos
commit 4caca9a
Author: Pruthvi P <pruthvi@ixigo.com>
Date: Fri May 22 00:33:22 2020 +0530
Fix typo eviciton => eviction
commit b2a25f6
Author: Brad Dunbar <dunbarb2@gmail.com>
Date: Sun May 17 12:39:59 2020 -0400
Fix a typo.
commit 12842ae
Author: hwware <wen.hui.ware@gmail.com>
Date: Sun May 3 17:16:59 2020 -0400
fix spelling in redis conf
commit ddba07c
Author: Chris Lamb <chris@chris-lamb.co.uk>
Date: Sat May 2 23:25:34 2020 +0100
Correct a "conflicts" spelling error.
commit 8fc7bf2
Author: Nao YONASHIRO <yonashiro@r.recruit.co.jp>
Date: Thu Apr 30 10:25:27 2020 +0900
docs: fix EXPIRE_FAST_CYCLE_DURATION to ACTIVE_EXPIRE_CYCLE_FAST_DURATION
commit 9b2b67a
Author: Brad Dunbar <dunbarb2@gmail.com>
Date: Fri Apr 24 11:46:22 2020 -0400
Fix a typo.
commit 0746f10
Author: devilinrust <63737265+devilinrust@users.noreply.github.com>
Date: Thu Apr 16 00:17:53 2020 +0200
Fix typos in server.c
commit 92b588d
Author: benjessop12 <56115861+benjessop12@users.noreply.github.com>
Date: Mon Apr 13 13:43:55 2020 +0100
Fix spelling mistake in lazyfree.c
commit 1da37aa
Merge: 2d4ba28 af347a8
Author: hwware <wen.hui.ware@gmail.com>
Date: Thu Mar 5 22:41:31 2020 -0500
Merge remote-tracking branch 'upstream/unstable' into expiretypofix
commit 2d4ba28
Author: hwware <wen.hui.ware@gmail.com>
Date: Mon Mar 2 00:09:40 2020 -0500
fix typo in expire.c
commit 1a746f7
Author: SennoYuki <minakami1yuki@gmail.com>
Date: Thu Feb 27 16:54:32 2020 +0800
fix typo
commit 8599b1a
Author: dongheejeong <donghee950403@gmail.com>
Date: Sun Feb 16 20:31:43 2020 +0000
Fix typo in server.c
commit f38d4e8
Author: hwware <wen.hui.ware@gmail.com>
Date: Sun Feb 2 22:58:38 2020 -0500
fix typo in evict.c
commit fe143fc
Author: Leo Murillo <leonardo.murillo@gmail.com>
Date: Sun Feb 2 01:57:22 2020 -0600
Fix a few typos in redis.conf
commit 1ab4d21
Author: viraja1 <anchan.viraj@gmail.com>
Date: Fri Dec 27 17:15:58 2019 +0530
Fix typo in Latency API docstring
commit ca1f70e
Author: gosth <danxuedexing@qq.com>
Date: Wed Dec 18 15:18:02 2019 +0800
fix typo in sort.c
commit a57c06b
Author: ZYunH <zyunhjob@163.com>
Date: Mon Dec 16 22:28:46 2019 +0800
fix-zset-typo
commit b8c92b5
Author: git-hulk <hulk.website@gmail.com>
Date: Mon Dec 16 15:51:42 2019 +0800
FIX: typo in cluster.c, onformation->information
commit 9dd981c
Author: wujm2007 <jim.wujm@gmail.com>
Date: Mon Dec 16 09:37:52 2019 +0800
Fix typo
commit e132d7a
Author: Sebastien Williams-Wynn <s.williamswynn.mail@gmail.com>
Date: Fri Nov 15 00:14:07 2019 +0000
Minor typo change
commit 47f44d5
Author: happynote3966 <01ssrmikururudevice01@gmail.com>
Date: Mon Nov 11 22:08:48 2019 +0900
fix comment typo in redis-cli.c
commit b8bdb0d
Author: fulei <fulei@kuaishou.com>
Date: Wed Oct 16 18:00:17 2019 +0800
Fix a spelling mistake of comments in defragDictBucketCallback
commit 0def46a
Author: fulei <fulei@kuaishou.com>
Date: Wed Oct 16 13:09:27 2019 +0800
fix some spelling mistakes of comments in defrag.c
commit f3596fd
Author: Phil Rajchgot <tophil@outlook.com>
Date: Sun Oct 13 02:02:32 2019 -0400
Typo and grammar fixes
Redis and its documentation are great -- just wanted to submit a few corrections in the spirit of Hacktoberfest. Thanks for all your work on this project. I use it all the time and it works beautifully.
commit 2b928cd
Author: KangZhiDong <worldkzd@gmail.com>
Date: Sun Sep 1 07:03:11 2019 +0800
fix typos
commit 33aea14
Author: Axlgrep <axlgrep@gmail.com>
Date: Tue Aug 27 11:02:18 2019 +0800
Fixed eviction spelling issues
commit e282a80
Author: Simen Flatby <simen@oms.no>
Date: Tue Aug 20 15:25:51 2019 +0200
Update comments to reflect prop name
In the comments the prop is referenced as replica-validity-factor,
but it is really named cluster-replica-validity-factor.
commit 74d1f9a
Author: Jim Green <jimgreen2013@qq.com>
Date: Tue Aug 20 20:00:31 2019 +0800
fix comment error, the code is ok
commit eea1407
Author: Liao Tonglang <liaotonglang@gmail.com>
Date: Fri May 31 10:16:18 2019 +0800
typo fix
fix cna't to can't
commit 0da553c
Author: KAWACHI Takashi <tkawachi@gmail.com>
Date: Wed Jul 17 00:38:16 2019 +0900
Fix typo
commit 7fc8fb6
Author: Michael Prokop <mika@grml.org>
Date: Tue May 28 17:58:42 2019 +0200
Typo fixes
s/familar/familiar/
s/compatiblity/compatibility/
s/ ot / to /
s/itsef/itself/
commit 5f46c9d
Author: zhumoing <34539422+zhumoing@users.noreply.github.com>
Date: Tue May 21 21:16:50 2019 +0800
typo-fixes
typo-fixes
commit 321dfe1
Author: wxisme <850885154@qq.com>
Date: Sat Mar 16 15:10:55 2019 +0800
typo fix
commit b4fb131
Merge: 267e0e6 3df1eb8
Author: Nikitas Bastas <nikitasbst@gmail.com>
Date: Fri Feb 8 22:55:45 2019 +0200
Merge branch 'unstable' of antirez/redis into unstable
commit 267e0e6
Author: Nikitas Bastas <nikitasbst@gmail.com>
Date: Wed Jan 30 21:26:04 2019 +0200
Minor typo fix
commit 30544e7
Author: inshal96 <39904558+inshal96@users.noreply.github.com>
Date: Fri Jan 4 16:54:50 2019 +0500
remove an extra 'a' in the comments
commit 337969d
Author: BrotherGao <yangdongheng11@gmail.com>
Date: Sat Dec 29 12:37:29 2018 +0800
fix typo in redis.conf
commit 9f4b121
Merge: 423a030 e504583
Author: BrotherGao <yangdongheng@xiaomi.com>
Date: Sat Dec 29 11:41:12 2018 +0800
Merge branch 'unstable' of antirez/redis into unstable
commit 423a030
Merge: 42b02b7 46a51cd
Author: 杨东衡 <yangdongheng@xiaomi.com>
Date: Tue Dec 4 23:56:11 2018 +0800
Merge branch 'unstable' of antirez/redis into unstable
commit 42b02b7
Merge: 68c0e6e b8febe6
Author: Dongheng Yang <yangdongheng11@gmail.com>
Date: Sun Oct 28 15:54:23 2018 +0800
Merge pull request #1 from antirez/unstable
update local data
commit 714b589
Author: Christian <crifei93@gmail.com>
Date: Fri Dec 28 01:17:26 2018 +0100
fix typo "resulution"
commit e23259d
Author: garenchan <1412950785@qq.com>
Date: Wed Dec 26 09:58:35 2018 +0800
fix typo: segfauls -> segfault
commit a9359f8
Author: xjp <jianping_xie@aliyun.com>
Date: Tue Dec 18 17:31:44 2018 +0800
Fixed REDISMODULE_H spell bug
commit a12c3e4
Author: jdiaz <jrd.palacios@gmail.com>
Date: Sat Dec 15 23:39:52 2018 -0600
Fixes hyperloglog hash function comment block description
commit 770eb11
Author: 林上耀 <1210tom@163.com>
Date: Sun Nov 25 17:16:10 2018 +0800
fix typo
commit fd97fbb
Author: Chris Lamb <chris@chris-lamb.co.uk>
Date: Fri Nov 23 17:14:01 2018 +0100
Correct "unsupported" typo.
commit a85522d
Author: Jungnam Lee <jungnam.lee@oracle.com>
Date: Thu Nov 8 23:01:29 2018 +0900
fix typo in test comments
commit ade8007
Author: Arun Kumar <palerdot@users.noreply.github.com>
Date: Tue Oct 23 16:56:35 2018 +0530
Fixed grammatical typo
Fixed typo for word 'dictionary'
commit 869ee39
Author: Hamid Alaei <hamid.a85@gmail.com>
Date: Sun Aug 12 16:40:02 2018 +0430
fix documentations: (ThreadSafeContextStart/Stop -> ThreadSafeContextLock/Unlock), minor typo
commit f89d158
Author: Mayank Jain <mayankjain255@gmail.com>
Date: Tue Jul 31 23:01:21 2018 +0530
Updated README.md with some spelling corrections.
Made correction in spelling of some misspelled words.
commit 892198e
Author: dsomeshwar <someshwar.dhayalan@gmail.com>
Date: Sat Jul 21 23:23:04 2018 +0530
typo fix
commit 8a4d780
Author: Itamar Haber <itamar@redislabs.com>
Date: Mon Apr 30 02:06:52 2018 +0300
Fixes some typos
commit e3acef6
Author: Noah Rosamilia <ivoahivoah@gmail.com>
Date: Sat Mar 3 23:41:21 2018 -0500
Fix typo in /deps/README.md
commit 04442fb
Author: WuYunlong <xzsyeb@126.com>
Date: Sat Mar 3 10:32:42 2018 +0800
Fix typo in readSyncBulkPayload() comment.
commit 9f36880
Author: WuYunlong <xzsyeb@126.com>
Date: Sat Mar 3 10:20:37 2018 +0800
replication.c comment: run_id -> replid.
commit f866b4a
Author: Francesco 'makevoid' Canessa <makevoid@gmail.com>
Date: Thu Feb 22 22:01:56 2018 +0000
fix comment typo in server.c
commit 0ebc69b
Author: 줍 <jubee0124@gmail.com>
Date: Mon Feb 12 16:38:48 2018 +0900
Fix typo in redis.conf
Fix `five behaviors` to `eight behaviors` in [this sentence ](antirez/redis@unstable/redis.conf#L564)
commit b50a620
Author: martinbroadhurst <martinbroadhurst@users.noreply.github.com>
Date: Thu Dec 28 12:07:30 2017 +0000
Fix typo in valgrind.sup
commit 7d8f349
Author: Peter Boughton <peter@sorcerersisle.com>
Date: Mon Nov 27 19:52:19 2017 +0000
Update CONTRIBUTING; refer doc updates to redis-doc repo.
commit 02dec7e
Author: Klauswk <klauswk1@hotmail.com>
Date: Tue Oct 24 16:18:38 2017 -0200
Fix typo in comment
commit e1efbc8
Author: chenshi <baiwfg2@gmail.com>
Date: Tue Oct 3 18:26:30 2017 +0800
Correct two spelling errors of comments
commit 93327d8
Author: spacewander <spacewanderlzx@gmail.com>
Date: Wed Sep 13 16:47:24 2017 +0800
Update the comment for OBJ_ENCODING_EMBSTR_SIZE_LIMIT's value
The value of OBJ_ENCODING_EMBSTR_SIZE_LIMIT is 44 now instead of 39.
commit 63d361f
Author: spacewander <spacewanderlzx@gmail.com>
Date: Tue Sep 12 15:06:42 2017 +0800
Fix <prevlen> related doc in ziplist.c
According to the definition of ZIP_BIG_PREVLEN and other related code,
the guard of single byte <prevlen> should be 254 instead of 255.
commit ebe228d
Author: hanael80 <hanael80@gmail.com>
Date: Tue Aug 15 09:09:40 2017 +0900
Fix typo
commit 6b696e6
Author: Matt Robenolt <matt@ydekproductions.com>
Date: Mon Aug 14 14:50:47 2017 -0700
Fix typo in LATENCY DOCTOR output
commit a2ec6ae
Author: caosiyang <caosiyang@qiyi.com>
Date: Tue Aug 15 14:15:16 2017 +0800
Fix a typo: form => from
commit 3ab7699
Author: caosiyang <caosiyang@qiyi.com>
Date: Thu Aug 10 18:40:33 2017 +0800
Fix a typo: replicationFeedSlavesFromMaster() => replicationFeedSlavesFromMasterStream()
commit 72d43ef
Author: caosiyang <caosiyang@qiyi.com>
Date: Tue Aug 8 15:57:25 2017 +0800
fix a typo: servewr => server
commit 707c958
Author: Bo Cai <charpty@gmail.com>
Date: Wed Jul 26 21:49:42 2017 +0800
redis-cli.c typo: conut -> count.
Signed-off-by: Bo Cai <charpty@gmail.com>
commit b9385b2
Author: JackDrogon <jack.xsuperman@gmail.com>
Date: Fri Jun 30 14:22:31 2017 +0800
Fix some spell problems
commit 20d9230
Author: akosel <aaronjkosel@gmail.com>
Date: Sun Jun 4 19:35:13 2017 -0500
Fix typo
commit b167bfc
Author: Krzysiek Witkowicz <krzysiekwitkowicz@gmail.com>
Date: Mon May 22 21:32:27 2017 +0100
Fix #4008 small typo in comment
commit 2b78ac8
Author: Jake Clarkson <jacobwclarkson@gmail.com>
Date: Wed Apr 26 15:49:50 2017 +0100
Correct typo in tests/unit/hyperloglog.tcl
commit b0f1cdb
Author: Qi Luo <qiluo-msft@users.noreply.github.com>
Date: Wed Apr 19 14:25:18 2017 -0700
Fix typo
commit a90b0f9
Author: charsyam <charsyam@naver.com>
Date: Thu Mar 16 18:19:53 2017 +0900
fix typos
fix typos
fix typos
commit 8430a79
Author: Richard Hart <richardhart92@gmail.com>
Date: Mon Mar 13 22:17:41 2017 -0400
Fixed log message typo in listenToPort.
commit 481a1c2
Author: Vinod Kumar <kumar003vinod@gmail.com>
Date: Sun Jan 15 23:04:51 2017 +0530
src/db.c: Correct "save" -> "safe" typo
commit 586b4d3
Author: wangshaonan <wshn13@gmail.com>
Date: Wed Dec 21 20:28:27 2016 +0800
Fix typo they->the in helloworld.c
commit c1c4b5e
Author: Jenner <hypxm@qq.com>
Date: Mon Dec 19 16:39:46 2016 +0800
typo error
commit 1ee1a3f
Author: tielei <43289893@qq.com>
Date: Mon Jul 18 13:52:25 2016 +0800
fix some comments
commit 11a41fb
Author: Otto Kekäläinen <otto@seravo.fi>
Date: Sun Jul 3 10:23:55 2016 +0100
Fix spelling in documentation and comments
commit 5fb5d82
Author: francischan <f1ancis621@gmail.com>
Date: Tue Jun 28 00:19:33 2016 +0800
Fix outdated comments about redis.c file.
It should now refer to server.c file.
commit 6b254bc
Author: lmatt-bit <lmatt123n@gmail.com>
Date: Thu Apr 21 21:45:58 2016 +0800
Refine the comment of dictRehashMilliseconds func
SLAVECONF->REPLCONF in comment - by andyli029
commit ee9869f
Author: clark.kang <charsyam@naver.com>
Date: Tue Mar 22 11:09:51 2016 +0900
fix typos
commit f7b3b11
Author: Harisankar H <harisankarh@gmail.com>
Date: Wed Mar 9 11:49:42 2016 +0530
Typo correction: "faield" --> "failed"
Typo correction: "faield" --> "failed"
commit 3fd40fc
Author: Itamar Haber <itamar@redislabs.com>
Date: Thu Feb 25 10:31:51 2016 +0200
Fixes a typo in comments
commit 621c160
Author: Prayag Verma <prayag.verma@gmail.com>
Date: Mon Feb 1 12:36:20 2016 +0530
Fix typo in Readme.md
Spelling mistakes -
`eviciton` > `eviction`
`familar` > `familiar`
commit d7d07d6
Author: WonCheol Lee <toctoc21c@gmail.com>
Date: Wed Dec 30 15:11:34 2015 +0900
Typo fixed
commit a4dade7
Author: Felix Bünemann <buenemann@louis.info>
Date: Mon Dec 28 11:02:55 2015 +0100
[ci skip] Improve supervised upstart config docs
This mentions that "expect stop" is required for supervised upstart
to work correctly. See http://upstart.ubuntu.com/cookbook/#expect-stop
for an explanation.
commit d9caba9
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:30:03 2015 +1100
README: Remove trailing whitespace
commit 72d42e5
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:29:32 2015 +1100
README: Fix typo. th => the
commit dd6e957
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:29:20 2015 +1100
README: Fix typo. familar => familiar
commit 3a12b23
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:28:54 2015 +1100
README: Fix typo. eviciton => eviction
commit 2d1d03b
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:21:45 2015 +1100
README: Fix typo. sever => server
commit 3973b06
Author: Itamar Haber <itamar@garantiadata.com>
Date: Sat Dec 19 17:01:20 2015 +0200
Typo fix
commit 4f2e460
Author: Steve Gao <fu@2token.com>
Date: Fri Dec 4 10:22:05 2015 +0800
Update README - fix typos
commit b21667c
Author: binyan <binbin.yan@nokia.com>
Date: Wed Dec 2 22:48:37 2015 +0800
delete redundancy color judge in sdscatcolor
commit 88894c7
Author: binyan <binbin.yan@nokia.com>
Date: Wed Dec 2 22:14:42 2015 +0800
the example output shoule be HelloWorld
commit 2763470
Author: binyan <binbin.yan@nokia.com>
Date: Wed Dec 2 17:41:39 2015 +0800
modify error word keyevente
Signed-off-by: binyan <binbin.yan@nokia.com>
commit 0847b3d
Author: Bruno Martins <bscmartins@gmail.com>
Date: Wed Nov 4 11:37:01 2015 +0000
typo
commit bbb9e9e
Author: dawedawe <dawedawe@gmx.de>
Date: Fri Mar 27 00:46:41 2015 +0100
typo: zimap -> zipmap
commit 5ed297e
Author: Axel Advento <badwolf.bloodseeker.rev@gmail.com>
Date: Tue Mar 3 15:58:29 2015 +0800
Fix 'salve' typos to 'slave'
commit edec9d6
Author: LudwikJaniuk <ludvig.janiuk@gmail.com>
Date: Wed Jun 12 14:12:47 2019 +0200
Update README.md
Co-Authored-By: Qix <Qix-@users.noreply.github.com>
commit 692a7af
Author: LudwikJaniuk <ludvig.janiuk@gmail.com>
Date: Tue May 28 14:32:04 2019 +0200
grammar
commit d962b0a
Author: Nick Frost <nickfrostatx@gmail.com>
Date: Wed Jul 20 15:17:12 2016 -0700
Minor grammar fix
commit 24fff01aaccaf5956973ada8c50ceb1462e211c6 (typos)
Author: Chad Miller <chadm@squareup.com>
Date: Tue Sep 8 13:46:11 2020 -0400
Fix faulty comment about operation of unlink()
commit 3cd5c1f3326c52aa552ada7ec797c6bb16452355
Author: Kevin <kevin.xgr@gmail.com>
Date: Wed Nov 20 00:13:50 2019 +0800
Fix typo in server.c.
From a83af59 Mon Sep 17 00:00:00 2001
From: wuwo <wuwo@wacai.com>
Date: Fri, 17 Mar 2017 20:37:45 +0800
Subject: [PATCH] falure to failure
From c961896 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B7=A6=E6=87=B6?= <veficos@gmail.com>
Date: Sat, 27 May 2017 15:33:04 +0800
Subject: [PATCH] fix typo
From e600ef2 Mon Sep 17 00:00:00 2001
From: "rui.zou" <rui.zou@yunify.com>
Date: Sat, 30 Sep 2017 12:38:15 +0800
Subject: [PATCH] fix a typo
From c7d07fa Mon Sep 17 00:00:00 2001
From: Alexandre Perrin <alex@kaworu.ch>
Date: Thu, 16 Aug 2018 10:35:31 +0200
Subject: [PATCH] deps README.md typo
From b25cb67 Mon Sep 17 00:00:00 2001
From: Guy Korland <gkorland@gmail.com>
Date: Wed, 26 Sep 2018 10:55:37 +0300
Subject: [PATCH 1/2] fix typos in header
From ad28ca6 Mon Sep 17 00:00:00 2001
From: Guy Korland <gkorland@gmail.com>
Date: Wed, 26 Sep 2018 11:02:36 +0300
Subject: [PATCH 2/2] fix typos
commit 34924cdedd8552466fc22c1168d49236cb7ee915
Author: Adrian Lynch <adi_ady_ade@hotmail.com>
Date: Sat Apr 4 21:59:15 2015 +0100
Typos fixed
commit fd2a1e7
Author: Jan <jsteemann@users.noreply.github.com>
Date: Sat Oct 27 19:13:01 2018 +0200
Fix typos
Fix typos
commit e14e47c1a234b53b0e103c5f6a1c61481cbcbb02
Author: Andy Lester <andy@petdance.com>
Date: Fri Aug 2 22:30:07 2019 -0500
Fix multiple misspellings of "following"
commit 79b948ce2dac6b453fe80995abbcaac04c213d5a
Author: Andy Lester <andy@petdance.com>
Date: Fri Aug 2 22:24:28 2019 -0500
Fix misspelling of create-cluster
commit 1fffde52666dc99ab35efbd31071a4c008cb5a71
Author: Andy Lester <andy@petdance.com>
Date: Wed Jul 31 17:57:56 2019 -0500
Fix typos
commit 204c9ba9651e9e05fd73936b452b9a30be456cfe
Author: Xiaobo Zhu <xiaobo.zhu@shopee.com>
Date: Tue Aug 13 22:19:25 2019 +0800
fix typos
Squashed commit of the following:
commit 1d9aaf8
Author: danmedani <danmedani@gmail.com>
Date: Sun Aug 2 11:40:26 2015 -0700
README typo fix.
Squashed commit of the following:
commit 32bfa7c
Author: Erik Dubbelboer <erik@dubbelboer.com>
Date: Mon Jul 6 21:15:08 2015 +0200
Fixed grammer
Squashed commit of the following:
commit b24f69c
Author: Sisir Koppaka <sisir.koppaka@gmail.com>
Date: Mon Mar 2 22:38:45 2015 -0500
utils/hashtable/rehashing.c: Fix typos
Squashed commit of the following:
commit 4e04082
Author: Erik Dubbelboer <erik@dubbelboer.com>
Date: Mon Mar 23 08:22:21 2015 +0000
Small config file documentation improvements
Squashed commit of the following:
commit acb8773
Author: ctd1500 <ctd1500@gmail.com>
Date: Fri May 8 01:52:48 2015 -0700
Typo and grammar fixes in readme
commit 2eb75b6
Author: ctd1500 <ctd1500@gmail.com>
Date: Fri May 8 01:36:18 2015 -0700
fixed redis.conf comment
Squashed commit of the following:
commit a8249a2
Author: Masahiko Sawada <sawada.mshk@gmail.com>
Date: Fri Dec 11 11:39:52 2015 +0530
Revise correction of typos.
Squashed commit of the following:
commit 3c02028
Author: zhaojun11 <zhaojun11@jd.com>
Date: Wed Jan 17 19:05:28 2018 +0800
Fix typos include two code typos in cluster.c and latency.c
Squashed commit of the following:
commit 9dba47c
Author: q191201771 <191201771@qq.com>
Date: Sat Jan 4 11:31:04 2020 +0800
fix function listCreate comment in adlist.c
Update src/server.c
commit 2c7c2cb536e78dd211b1ac6f7bda00f0f54faaeb
Author: charpty <charpty@gmail.com>
Date: Tue May 1 23:16:59 2018 +0800
server.c typo: modules system dictionary type comment
Signed-off-by: charpty <charpty@gmail.com>
commit a8395323fb63cb59cb3591cb0f0c8edb7c29a680
Author: Itamar Haber <itamar@redislabs.com>
Date: Sun May 6 00:25:18 2018 +0300
Updates test_helper.tcl's help with undocumented options
Specifically:
* Host
* Port
* Client
commit bde6f9ced15755cd6407b4af7d601b030f36d60b
Author: wxisme <850885154@qq.com>
Date: Wed Aug 8 15:19:19 2018 +0800
fix comments in deps files
commit 3172474ba991532ab799ee1873439f3402412331
Author: wxisme <850885154@qq.com>
Date: Wed Aug 8 14:33:49 2018 +0800
fix some comments
commit 01b6f2b6858b5cf2ce4ad5092d2c746e755f53f0
Author: Thor Juhasz <thor@juhasz.pro>
Date: Sun Nov 18 14:37:41 2018 +0100
Minor fixes to comments
Found some parts a little unclear on a first read, which prompted me to have a better look at the file and fix some minor things I noticed.
Fixing minor typos and grammar. There are no changes to configuration options.
These changes are only meant to help the user better understand the explanations to the various configuration options
2020-09-10 06:43:38 -04:00
|
|
|
/* Remove the element and its associated value if needed. */
|
2013-10-31 05:32:33 -04:00
|
|
|
if (filter) {
|
2012-07-09 04:00:26 -04:00
|
|
|
decrRefCount(kobj);
|
2013-10-25 05:54:37 -04:00
|
|
|
listDelNode(keys, node);
|
2013-11-05 06:16:29 -05:00
|
|
|
}
|
|
|
|
|
2013-12-05 10:35:32 -05:00
|
|
|
/* If this is a hash or a sorted set, we have a flat list of
|
2013-11-05 06:16:29 -05:00
|
|
|
* key-value elements, so if this element was filtered, remove the
|
|
|
|
* value, or skip it if it was not filtered: we only match keys. */
|
2015-07-26 09:28:00 -04:00
|
|
|
if (o && (o->type == OBJ_ZSET || o->type == OBJ_HASH)) {
|
2013-11-05 06:16:29 -05:00
|
|
|
node = nextnode;
|
2020-08-14 09:05:34 -04:00
|
|
|
serverAssert(node); /* assertion for valgrind (avoid NPD) */
|
2013-11-05 06:16:29 -05:00
|
|
|
nextnode = listNextNode(node);
|
|
|
|
if (filter) {
|
2013-10-28 06:11:34 -04:00
|
|
|
kobj = listNodeValue(node);
|
|
|
|
decrRefCount(kobj);
|
|
|
|
listDelNode(keys, node);
|
|
|
|
}
|
2012-07-09 04:00:26 -04:00
|
|
|
}
|
2013-10-25 05:54:37 -04:00
|
|
|
node = nextnode;
|
2012-07-09 04:00:26 -04:00
|
|
|
}
|
|
|
|
|
2013-10-28 06:11:34 -04:00
|
|
|
/* Step 4: Reply to the client. */
|
2018-11-09 06:59:00 -05:00
|
|
|
addReplyArrayLen(c, 2);
|
2014-08-13 05:44:38 -04:00
|
|
|
addReplyBulkLongLong(c,cursor);
|
2012-07-09 04:00:26 -04:00
|
|
|
|
2018-11-09 06:59:00 -05:00
|
|
|
addReplyArrayLen(c, listLength(keys));
|
2013-10-25 05:54:37 -04:00
|
|
|
while ((node = listFirst(keys)) != NULL) {
|
|
|
|
robj *kobj = listNodeValue(node);
|
2012-07-09 04:00:26 -04:00
|
|
|
addReplyBulk(c, kobj);
|
|
|
|
decrRefCount(kobj);
|
2013-10-25 05:54:37 -04:00
|
|
|
listDelNode(keys, node);
|
2012-07-09 04:00:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2013-10-25 05:58:03 -04:00
|
|
|
listSetFreeMethod(keys,decrRefCountVoid);
|
2012-07-09 04:00:26 -04:00
|
|
|
listRelease(keys);
|
|
|
|
}
|
|
|
|
|
2013-10-28 06:11:34 -04:00
|
|
|
/* The SCAN command completely relies on scanGenericCommand. */
|
2015-07-26 09:20:46 -04:00
|
|
|
void scanCommand(client *c) {
|
2013-11-05 09:47:50 -05:00
|
|
|
unsigned long cursor;
|
2015-07-26 17:17:55 -04:00
|
|
|
if (parseScanCursorOrReply(c,c->argv[1],&cursor) == C_ERR) return;
|
2013-11-05 09:47:50 -05:00
|
|
|
scanGenericCommand(c,NULL,cursor);
|
2013-10-28 06:11:34 -04:00
|
|
|
}
|
|
|
|
|
2015-07-26 09:20:46 -04:00
|
|
|
void dbsizeCommand(client *c) {
|
2010-09-02 08:30:56 -04:00
|
|
|
addReplyLongLong(c,dictSize(c->db->dict));
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
|
2015-07-26 09:20:46 -04:00
|
|
|
void lastsaveCommand(client *c) {
|
2010-09-02 08:30:56 -04:00
|
|
|
addReplyLongLong(c,server.lastsave);
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
|
2019-07-08 06:04:37 -04:00
|
|
|
char* getObjectTypeName(robj *o) {
|
2019-06-10 12:41:44 -04:00
|
|
|
char* type;
|
2010-06-21 18:07:48 -04:00
|
|
|
if (o == NULL) {
|
2010-09-02 13:52:24 -04:00
|
|
|
type = "none";
|
2010-06-21 18:07:48 -04:00
|
|
|
} else {
|
|
|
|
switch(o->type) {
|
2015-07-26 09:28:00 -04:00
|
|
|
case OBJ_STRING: type = "string"; break;
|
|
|
|
case OBJ_LIST: type = "list"; break;
|
|
|
|
case OBJ_SET: type = "set"; break;
|
|
|
|
case OBJ_ZSET: type = "zset"; break;
|
|
|
|
case OBJ_HASH: type = "hash"; break;
|
2017-11-08 16:57:10 -05:00
|
|
|
case OBJ_STREAM: type = "stream"; break;
|
2016-05-18 05:45:40 -04:00
|
|
|
case OBJ_MODULE: {
|
|
|
|
moduleValue *mv = o->ptr;
|
|
|
|
type = mv->type->name;
|
|
|
|
}; break;
|
2010-09-02 13:52:24 -04:00
|
|
|
default: type = "unknown"; break;
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
}
|
2019-06-10 12:41:44 -04:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void typeCommand(client *c) {
|
|
|
|
robj *o;
|
|
|
|
o = lookupKeyReadWithFlags(c->db,c->argv[1],LOOKUP_NOTOUCH);
|
2019-07-08 06:04:37 -04:00
|
|
|
addReplyStatus(c, getObjectTypeName(o));
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
|
2015-07-26 09:20:46 -04:00
|
|
|
void shutdownCommand(client *c) {
|
2011-11-18 08:10:48 -05:00
|
|
|
int flags = 0;
|
|
|
|
|
|
|
|
if (c->argc > 2) {
|
|
|
|
addReply(c,shared.syntaxerr);
|
|
|
|
return;
|
|
|
|
} else if (c->argc == 2) {
|
|
|
|
if (!strcasecmp(c->argv[1]->ptr,"nosave")) {
|
2015-07-27 03:41:48 -04:00
|
|
|
flags |= SHUTDOWN_NOSAVE;
|
2011-11-18 08:10:48 -05:00
|
|
|
} else if (!strcasecmp(c->argv[1]->ptr,"save")) {
|
2015-07-27 03:41:48 -04:00
|
|
|
flags |= SHUTDOWN_SAVE;
|
2011-11-18 08:10:48 -05:00
|
|
|
} else {
|
|
|
|
addReply(c,shared.syntaxerr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-07-26 17:17:55 -04:00
|
|
|
if (prepareForShutdown(flags) == C_OK) exit(0);
|
2010-09-02 13:52:24 -04:00
|
|
|
addReplyError(c,"Errors trying to SHUTDOWN. Check logs.");
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
|
2015-07-26 09:20:46 -04:00
|
|
|
void renameGenericCommand(client *c, int nx) {
|
2010-06-21 18:07:48 -04:00
|
|
|
robj *o;
|
2011-11-09 10:51:19 -05:00
|
|
|
long long expire;
|
2015-02-23 05:24:24 -05:00
|
|
|
int samekey = 0;
|
2010-06-21 18:07:48 -04:00
|
|
|
|
2015-02-23 05:24:24 -05:00
|
|
|
/* When source and dest key is the same, no operation is performed,
|
|
|
|
* if the key exists, however we still return an error on unexisting key. */
|
|
|
|
if (sdscmp(c->argv[1]->ptr,c->argv[2]->ptr) == 0) samekey = 1;
|
2010-06-21 18:07:48 -04:00
|
|
|
|
|
|
|
if ((o = lookupKeyWriteOrReply(c,c->argv[1],shared.nokeyerr)) == NULL)
|
|
|
|
return;
|
|
|
|
|
2015-02-23 05:24:24 -05:00
|
|
|
if (samekey) {
|
|
|
|
addReply(c,nx ? shared.czero : shared.ok);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-21 18:07:48 -04:00
|
|
|
incrRefCount(o);
|
2011-10-10 09:21:19 -04:00
|
|
|
expire = getExpire(c->db,c->argv[1]);
|
2011-06-14 09:34:27 -04:00
|
|
|
if (lookupKeyWrite(c->db,c->argv[2]) != NULL) {
|
2010-06-21 18:07:48 -04:00
|
|
|
if (nx) {
|
|
|
|
decrRefCount(o);
|
|
|
|
addReply(c,shared.czero);
|
|
|
|
return;
|
|
|
|
}
|
2013-01-23 10:44:45 -05:00
|
|
|
/* Overwrite: delete the old key before creating the new one
|
|
|
|
* with the same name. */
|
2011-10-10 09:21:19 -04:00
|
|
|
dbDelete(c->db,c->argv[2]);
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
2011-10-10 09:21:19 -04:00
|
|
|
dbAdd(c->db,c->argv[2],o);
|
Replication: fix the infamous key leakage of writable slaves + EXPIRE.
BACKGROUND AND USE CASEj
Redis slaves are normally write only, however the supprot a "writable"
mode which is very handy when scaling reads on slaves, that actually
need write operations in order to access data. For instance imagine
having slaves replicating certain Sets keys from the master. When
accessing the data on the slave, we want to peform intersections between
such Sets values. However we don't want to intersect each time: to cache
the intersection for some time often is a good idea.
To do so, it is possible to setup a slave as a writable slave, and
perform the intersection on the slave side, perhaps setting a TTL on the
resulting key so that it will expire after some time.
THE BUG
Problem: in order to have a consistent replication, expiring of keys in
Redis replication is up to the master, that synthesize DEL operations to
send in the replication stream. However slaves logically expire keys
by hiding them from read attempts from clients so that if the master did
not promptly sent a DEL, the client still see logically expired keys
as non existing.
Because slaves don't actively expire keys by actually evicting them but
just masking from the POV of read operations, if a key is created in a
writable slave, and an expire is set, the key will be leaked forever:
1. No DEL will be received from the master, which does not know about
such a key at all.
2. No eviction will be performed by the slave, since it needs to disable
eviction because it's up to masters, otherwise consistency of data is
lost.
THE FIX
In order to fix the problem, the slave should be able to tag keys that
were created in the slave side and have an expire set in some way.
My solution involved using an unique additional dictionary created by
the writable slave only if needed. The dictionary is obviously keyed by
the key name that we need to track: all the keys that are set with an
expire directly by a client writing to the slave are tracked.
The value in the dictionary is a bitmap of all the DBs where such a key
name need to be tracked, so that we can use a single dictionary to track
keys in all the DBs used by the slave (actually this limits the solution
to the first 64 DBs, but the default with Redis is to use 16 DBs).
This solution allows to pay both a small complexity and CPU penalty,
which is zero when the feature is not used, actually. The slave-side
eviction is encapsulated in code which is not coupled with the rest of
the Redis core, if not for the hook to track the keys.
TODO
I'm doing the first smoke tests to see if the feature works as expected:
so far so good. Unit tests should be added before merging into the
4.0 branch.
2016-12-13 04:20:06 -05:00
|
|
|
if (expire != -1) setExpire(c,c->db,c->argv[2],expire);
|
2010-06-21 18:07:48 -04:00
|
|
|
dbDelete(c->db,c->argv[1]);
|
2020-04-21 04:51:46 -04:00
|
|
|
signalModifiedKey(c,c->db,c->argv[1]);
|
|
|
|
signalModifiedKey(c,c->db,c->argv[2]);
|
2015-07-27 03:41:48 -04:00
|
|
|
notifyKeyspaceEvent(NOTIFY_GENERIC,"rename_from",
|
2013-01-25 07:19:08 -05:00
|
|
|
c->argv[1],c->db->id);
|
2015-07-27 03:41:48 -04:00
|
|
|
notifyKeyspaceEvent(NOTIFY_GENERIC,"rename_to",
|
2013-01-25 07:19:08 -05:00
|
|
|
c->argv[2],c->db->id);
|
2010-06-21 18:07:48 -04:00
|
|
|
server.dirty++;
|
|
|
|
addReply(c,nx ? shared.cone : shared.ok);
|
|
|
|
}
|
|
|
|
|
2015-07-26 09:20:46 -04:00
|
|
|
void renameCommand(client *c) {
|
2010-06-21 18:07:48 -04:00
|
|
|
renameGenericCommand(c,0);
|
|
|
|
}
|
|
|
|
|
2015-07-26 09:20:46 -04:00
|
|
|
void renamenxCommand(client *c) {
|
2010-06-21 18:07:48 -04:00
|
|
|
renameGenericCommand(c,1);
|
|
|
|
}
|
|
|
|
|
2015-07-26 09:20:46 -04:00
|
|
|
void moveCommand(client *c) {
|
2010-06-21 18:07:48 -04:00
|
|
|
robj *o;
|
|
|
|
redisDb *src, *dst;
|
Improve dbid range check for SELECT, MOVE, COPY (#8085)
SELECT used to read the index into a `long` variable, and then pass it to a function
that takes an `int`, possibly causing an overflow before the range check.
Now all these commands use better and cleaner range check, and that also results in
a slight change of the error response in case of an invalid database index.
SELECT:
in the past it would have returned either `-ERR invalid DB index` (if not a number),
or `-ERR DB index is out of range` (if not between 1..16 or alike).
now it'll return either `-ERR value is out of range` (if not a number), or
`-ERR value is out of range, value must between -2147483648 and 2147483647`
(if not in the range for an int), or `-ERR DB index is out of range`
(if not between 0..16 or alike)
MOVE:
in the past it would only fail with `-ERR index out of range` no matter the reason.
now return the same errors as the new ones for SELECT mentioned above.
(i.e. unlike for SELECT even for a value like 17 we changed the error message)
COPY:
doesn't really matter how it behaved in the past (new command), new behavior is
like the above two.
2020-12-01 14:41:26 -05:00
|
|
|
int srcid, dbid;
|
|
|
|
long long expire;
|
2010-06-21 18:07:48 -04:00
|
|
|
|
2011-03-29 11:51:15 -04:00
|
|
|
if (server.cluster_enabled) {
|
|
|
|
addReplyError(c,"MOVE is not allowed in cluster mode");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-21 18:07:48 -04:00
|
|
|
/* Obtain source and target DB pointers */
|
|
|
|
src = c->db;
|
|
|
|
srcid = c->db->id;
|
2014-08-01 14:55:24 -04:00
|
|
|
|
Improve dbid range check for SELECT, MOVE, COPY (#8085)
SELECT used to read the index into a `long` variable, and then pass it to a function
that takes an `int`, possibly causing an overflow before the range check.
Now all these commands use better and cleaner range check, and that also results in
a slight change of the error response in case of an invalid database index.
SELECT:
in the past it would have returned either `-ERR invalid DB index` (if not a number),
or `-ERR DB index is out of range` (if not between 1..16 or alike).
now it'll return either `-ERR value is out of range` (if not a number), or
`-ERR value is out of range, value must between -2147483648 and 2147483647`
(if not in the range for an int), or `-ERR DB index is out of range`
(if not between 0..16 or alike)
MOVE:
in the past it would only fail with `-ERR index out of range` no matter the reason.
now return the same errors as the new ones for SELECT mentioned above.
(i.e. unlike for SELECT even for a value like 17 we changed the error message)
COPY:
doesn't really matter how it behaved in the past (new command), new behavior is
like the above two.
2020-12-01 14:41:26 -05:00
|
|
|
if (getIntFromObjectOrReply(c, c->argv[2], &dbid, NULL) != C_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (selectDb(c,dbid) == C_ERR) {
|
|
|
|
addReplyError(c,"DB index is out of range");
|
2010-06-21 18:07:48 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
dst = c->db;
|
|
|
|
selectDb(c,srcid); /* Back to the source DB */
|
|
|
|
|
|
|
|
/* If the user is moving using as target the same
|
|
|
|
* DB as the source DB it is probably an error. */
|
|
|
|
if (src == dst) {
|
|
|
|
addReply(c,shared.sameobjecterr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the element exists and get a reference */
|
|
|
|
o = lookupKeyWrite(c->db,c->argv[1]);
|
|
|
|
if (!o) {
|
|
|
|
addReply(c,shared.czero);
|
|
|
|
return;
|
|
|
|
}
|
2015-09-14 06:28:22 -04:00
|
|
|
expire = getExpire(c->db,c->argv[1]);
|
2010-06-21 18:07:48 -04:00
|
|
|
|
2011-06-14 09:34:27 -04:00
|
|
|
/* Return zero if the key already exists in the target DB */
|
|
|
|
if (lookupKeyWrite(dst,c->argv[1]) != NULL) {
|
2010-06-21 18:07:48 -04:00
|
|
|
addReply(c,shared.czero);
|
|
|
|
return;
|
|
|
|
}
|
2011-06-14 09:34:27 -04:00
|
|
|
dbAdd(dst,c->argv[1],o);
|
Replication: fix the infamous key leakage of writable slaves + EXPIRE.
BACKGROUND AND USE CASEj
Redis slaves are normally write only, however the supprot a "writable"
mode which is very handy when scaling reads on slaves, that actually
need write operations in order to access data. For instance imagine
having slaves replicating certain Sets keys from the master. When
accessing the data on the slave, we want to peform intersections between
such Sets values. However we don't want to intersect each time: to cache
the intersection for some time often is a good idea.
To do so, it is possible to setup a slave as a writable slave, and
perform the intersection on the slave side, perhaps setting a TTL on the
resulting key so that it will expire after some time.
THE BUG
Problem: in order to have a consistent replication, expiring of keys in
Redis replication is up to the master, that synthesize DEL operations to
send in the replication stream. However slaves logically expire keys
by hiding them from read attempts from clients so that if the master did
not promptly sent a DEL, the client still see logically expired keys
as non existing.
Because slaves don't actively expire keys by actually evicting them but
just masking from the POV of read operations, if a key is created in a
writable slave, and an expire is set, the key will be leaked forever:
1. No DEL will be received from the master, which does not know about
such a key at all.
2. No eviction will be performed by the slave, since it needs to disable
eviction because it's up to masters, otherwise consistency of data is
lost.
THE FIX
In order to fix the problem, the slave should be able to tag keys that
were created in the slave side and have an expire set in some way.
My solution involved using an unique additional dictionary created by
the writable slave only if needed. The dictionary is obviously keyed by
the key name that we need to track: all the keys that are set with an
expire directly by a client writing to the slave are tracked.
The value in the dictionary is a bitmap of all the DBs where such a key
name need to be tracked, so that we can use a single dictionary to track
keys in all the DBs used by the slave (actually this limits the solution
to the first 64 DBs, but the default with Redis is to use 16 DBs).
This solution allows to pay both a small complexity and CPU penalty,
which is zero when the feature is not used, actually. The slave-side
eviction is encapsulated in code which is not coupled with the rest of
the Redis core, if not for the hook to track the keys.
TODO
I'm doing the first smoke tests to see if the feature works as expected:
so far so good. Unit tests should be added before merging into the
4.0 branch.
2016-12-13 04:20:06 -05:00
|
|
|
if (expire != -1) setExpire(c,dst,c->argv[1],expire);
|
2010-06-21 18:07:48 -04:00
|
|
|
incrRefCount(o);
|
|
|
|
|
|
|
|
/* OK! key moved, free the entry in the source DB */
|
|
|
|
dbDelete(src,c->argv[1]);
|
2020-04-21 04:51:46 -04:00
|
|
|
signalModifiedKey(c,src,c->argv[1]);
|
|
|
|
signalModifiedKey(c,dst,c->argv[1]);
|
2019-11-19 00:02:45 -05:00
|
|
|
notifyKeyspaceEvent(NOTIFY_GENERIC,
|
|
|
|
"move_from",c->argv[1],src->id);
|
|
|
|
notifyKeyspaceEvent(NOTIFY_GENERIC,
|
|
|
|
"move_to",c->argv[1],dst->id);
|
|
|
|
|
2010-06-21 18:07:48 -04:00
|
|
|
server.dirty++;
|
|
|
|
addReply(c,shared.cone);
|
|
|
|
}
|
|
|
|
|
2020-11-17 05:03:05 -05:00
|
|
|
void copyCommand(client *c) {
|
|
|
|
robj *o;
|
|
|
|
redisDb *src, *dst;
|
Improve dbid range check for SELECT, MOVE, COPY (#8085)
SELECT used to read the index into a `long` variable, and then pass it to a function
that takes an `int`, possibly causing an overflow before the range check.
Now all these commands use better and cleaner range check, and that also results in
a slight change of the error response in case of an invalid database index.
SELECT:
in the past it would have returned either `-ERR invalid DB index` (if not a number),
or `-ERR DB index is out of range` (if not between 1..16 or alike).
now it'll return either `-ERR value is out of range` (if not a number), or
`-ERR value is out of range, value must between -2147483648 and 2147483647`
(if not in the range for an int), or `-ERR DB index is out of range`
(if not between 0..16 or alike)
MOVE:
in the past it would only fail with `-ERR index out of range` no matter the reason.
now return the same errors as the new ones for SELECT mentioned above.
(i.e. unlike for SELECT even for a value like 17 we changed the error message)
COPY:
doesn't really matter how it behaved in the past (new command), new behavior is
like the above two.
2020-12-01 14:41:26 -05:00
|
|
|
int srcid, dbid;
|
|
|
|
long long expire;
|
2020-11-17 05:03:05 -05:00
|
|
|
int j, replace = 0, delete = 0;
|
|
|
|
|
|
|
|
/* Obtain source and target DB pointers
|
|
|
|
* Default target DB is the same as the source DB
|
|
|
|
* Parse the REPLACE option and targetDB option. */
|
|
|
|
src = c->db;
|
|
|
|
dst = c->db;
|
|
|
|
srcid = c->db->id;
|
|
|
|
dbid = c->db->id;
|
|
|
|
for (j = 3; j < c->argc; j++) {
|
|
|
|
int additional = c->argc - j - 1;
|
|
|
|
if (!strcasecmp(c->argv[j]->ptr,"replace")) {
|
|
|
|
replace = 1;
|
|
|
|
} else if (!strcasecmp(c->argv[j]->ptr, "db") && additional >= 1) {
|
Improve dbid range check for SELECT, MOVE, COPY (#8085)
SELECT used to read the index into a `long` variable, and then pass it to a function
that takes an `int`, possibly causing an overflow before the range check.
Now all these commands use better and cleaner range check, and that also results in
a slight change of the error response in case of an invalid database index.
SELECT:
in the past it would have returned either `-ERR invalid DB index` (if not a number),
or `-ERR DB index is out of range` (if not between 1..16 or alike).
now it'll return either `-ERR value is out of range` (if not a number), or
`-ERR value is out of range, value must between -2147483648 and 2147483647`
(if not in the range for an int), or `-ERR DB index is out of range`
(if not between 0..16 or alike)
MOVE:
in the past it would only fail with `-ERR index out of range` no matter the reason.
now return the same errors as the new ones for SELECT mentioned above.
(i.e. unlike for SELECT even for a value like 17 we changed the error message)
COPY:
doesn't really matter how it behaved in the past (new command), new behavior is
like the above two.
2020-12-01 14:41:26 -05:00
|
|
|
if (getIntFromObjectOrReply(c, c->argv[j+1], &dbid, NULL) != C_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (selectDb(c, dbid) == C_ERR) {
|
|
|
|
addReplyError(c,"DB index is out of range");
|
2020-11-17 05:03:05 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
dst = c->db;
|
|
|
|
selectDb(c,srcid); /* Back to the source DB */
|
|
|
|
j++; /* Consume additional arg. */
|
|
|
|
} else {
|
|
|
|
addReply(c, shared.syntaxerr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((server.cluster_enabled == 1) && (srcid != 0 || dbid != 0)) {
|
|
|
|
addReplyError(c,"Copying to another database is not allowed in cluster mode");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the user select the same DB as
|
|
|
|
* the source DB and using newkey as the same key
|
|
|
|
* it is probably an error. */
|
|
|
|
robj *key = c->argv[1];
|
|
|
|
robj *newkey = c->argv[2];
|
|
|
|
if (src == dst && (sdscmp(key->ptr, newkey->ptr) == 0)) {
|
|
|
|
addReply(c,shared.sameobjecterr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the element exists and get a reference */
|
|
|
|
o = lookupKeyWrite(c->db, key);
|
|
|
|
if (!o) {
|
|
|
|
addReply(c,shared.czero);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
expire = getExpire(c->db,key);
|
|
|
|
|
|
|
|
/* Return zero if the key already exists in the target DB.
|
|
|
|
* If REPLACE option is selected, delete newkey from targetDB. */
|
|
|
|
if (lookupKeyWrite(dst,newkey) != NULL) {
|
|
|
|
if (replace) {
|
|
|
|
delete = 1;
|
|
|
|
} else {
|
|
|
|
addReply(c,shared.czero);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Duplicate object according to object's type. */
|
|
|
|
robj *newobj;
|
|
|
|
switch(o->type) {
|
|
|
|
case OBJ_STRING: newobj = dupStringObject(o); break;
|
|
|
|
case OBJ_LIST: newobj = listTypeDup(o); break;
|
|
|
|
case OBJ_SET: newobj = setTypeDup(o); break;
|
|
|
|
case OBJ_ZSET: newobj = zsetDup(o); break;
|
|
|
|
case OBJ_HASH: newobj = hashTypeDup(o); break;
|
|
|
|
case OBJ_STREAM: newobj = streamDup(o); break;
|
|
|
|
case OBJ_MODULE:
|
|
|
|
addReplyError(c, "Copying module type object is not supported");
|
|
|
|
return;
|
|
|
|
default: {
|
|
|
|
addReplyError(c, "unknown type object");
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (delete) {
|
|
|
|
dbDelete(dst,newkey);
|
|
|
|
}
|
|
|
|
|
|
|
|
dbAdd(dst,newkey,newobj);
|
|
|
|
if (expire != -1) setExpire(c, dst, newkey, expire);
|
|
|
|
|
|
|
|
/* OK! key copied */
|
|
|
|
signalModifiedKey(c,dst,c->argv[2]);
|
|
|
|
notifyKeyspaceEvent(NOTIFY_GENERIC,"copy_to",c->argv[2],dst->id);
|
|
|
|
|
|
|
|
server.dirty++;
|
|
|
|
addReply(c,shared.cone);
|
|
|
|
}
|
|
|
|
|
SWAPDB command.
This new command swaps two Redis databases, so that immediately all the
clients connected to a given DB will see the data of the other DB, and
the other way around. Example:
SWAPDB 0 1
This will swap DB 0 with DB 1. All the clients connected with DB 0 will
immediately see the new data, exactly like all the clients connected
with DB 1 will see the data that was formerly of DB 0.
MOTIVATION AND HISTORY
---
The command was recently demanded by Pedro Melo, but was suggested in
the past multiple times, and always refused by me.
The reason why it was asked: Imagine you have clients operating in DB 0.
At the same time, you create a new version of the dataset in DB 1.
When the new version of the dataset is available, you immediately want
to swap the two views, so that the clients will transparently use the
new version of the data. At the same time you'll likely destroy the
DB 1 dataset (that contains the old data) and start to build a new
version, to repeat the process.
This is an interesting pattern, but the reason why I always opposed to
implement this, was that FLUSHDB was a blocking command in Redis before
Redis 4.0 improvements. Now we have FLUSHDB ASYNC that releases the
old data in O(1) from the point of view of the client, to reclaim memory
incrementally in a different thread.
At this point, the pattern can really be supported without latency
spikes, so I'm providing this implementation for the users to comment.
In case a very compelling argument will be made against this new command
it may be removed.
BEHAVIOR WITH BLOCKING OPERATIONS
---
If a client is blocking for a list in a given DB, after the swap it will
still be blocked in the same DB ID, since this is the most logical thing
to do: if I was blocked for a list push to list "foo", even after the
swap I want still a LPUSH to reach the key "foo" in the same DB in order
to unblock.
However an interesting thing happens when a client is, for instance,
blocked waiting for new elements in list "foo" of DB 0. Then the DB
0 and 1 are swapped with SWAPDB. However the DB 1 happened to have
a list called "foo" containing elements. When this happens, this
implementation can correctly unblock the client.
It is possible that there are subtle corner cases that are not covered
in the implementation, but since the command is self-contained from the
POV of the implementation and the Redis core, it cannot cause anything
bad if not used.
Tests and documentation are yet to be provided.
2016-10-14 09:28:04 -04:00
|
|
|
/* Helper function for dbSwapDatabases(): scans the list of keys that have
|
2018-06-12 11:28:40 -04:00
|
|
|
* one or more blocked clients for B[LR]POP or other blocking commands
|
|
|
|
* and signal the keys as ready if they are of the right type. See the comment
|
|
|
|
* where the function is used for more info. */
|
SWAPDB command.
This new command swaps two Redis databases, so that immediately all the
clients connected to a given DB will see the data of the other DB, and
the other way around. Example:
SWAPDB 0 1
This will swap DB 0 with DB 1. All the clients connected with DB 0 will
immediately see the new data, exactly like all the clients connected
with DB 1 will see the data that was formerly of DB 0.
MOTIVATION AND HISTORY
---
The command was recently demanded by Pedro Melo, but was suggested in
the past multiple times, and always refused by me.
The reason why it was asked: Imagine you have clients operating in DB 0.
At the same time, you create a new version of the dataset in DB 1.
When the new version of the dataset is available, you immediately want
to swap the two views, so that the clients will transparently use the
new version of the data. At the same time you'll likely destroy the
DB 1 dataset (that contains the old data) and start to build a new
version, to repeat the process.
This is an interesting pattern, but the reason why I always opposed to
implement this, was that FLUSHDB was a blocking command in Redis before
Redis 4.0 improvements. Now we have FLUSHDB ASYNC that releases the
old data in O(1) from the point of view of the client, to reclaim memory
incrementally in a different thread.
At this point, the pattern can really be supported without latency
spikes, so I'm providing this implementation for the users to comment.
In case a very compelling argument will be made against this new command
it may be removed.
BEHAVIOR WITH BLOCKING OPERATIONS
---
If a client is blocking for a list in a given DB, after the swap it will
still be blocked in the same DB ID, since this is the most logical thing
to do: if I was blocked for a list push to list "foo", even after the
swap I want still a LPUSH to reach the key "foo" in the same DB in order
to unblock.
However an interesting thing happens when a client is, for instance,
blocked waiting for new elements in list "foo" of DB 0. Then the DB
0 and 1 are swapped with SWAPDB. However the DB 1 happened to have
a list called "foo" containing elements. When this happens, this
implementation can correctly unblock the client.
It is possible that there are subtle corner cases that are not covered
in the implementation, but since the command is self-contained from the
POV of the implementation and the Redis core, it cannot cause anything
bad if not used.
Tests and documentation are yet to be provided.
2016-10-14 09:28:04 -04:00
|
|
|
void scanDatabaseForReadyLists(redisDb *db) {
|
|
|
|
dictEntry *de;
|
|
|
|
dictIterator *di = dictGetSafeIterator(db->blocking_keys);
|
|
|
|
while((de = dictNext(di)) != NULL) {
|
|
|
|
robj *key = dictGetKey(de);
|
|
|
|
robj *value = lookupKey(db,key,LOOKUP_NOTOUCH);
|
2020-08-11 01:18:09 -04:00
|
|
|
if (value) signalKeyAsReady(db, key, value->type);
|
SWAPDB command.
This new command swaps two Redis databases, so that immediately all the
clients connected to a given DB will see the data of the other DB, and
the other way around. Example:
SWAPDB 0 1
This will swap DB 0 with DB 1. All the clients connected with DB 0 will
immediately see the new data, exactly like all the clients connected
with DB 1 will see the data that was formerly of DB 0.
MOTIVATION AND HISTORY
---
The command was recently demanded by Pedro Melo, but was suggested in
the past multiple times, and always refused by me.
The reason why it was asked: Imagine you have clients operating in DB 0.
At the same time, you create a new version of the dataset in DB 1.
When the new version of the dataset is available, you immediately want
to swap the two views, so that the clients will transparently use the
new version of the data. At the same time you'll likely destroy the
DB 1 dataset (that contains the old data) and start to build a new
version, to repeat the process.
This is an interesting pattern, but the reason why I always opposed to
implement this, was that FLUSHDB was a blocking command in Redis before
Redis 4.0 improvements. Now we have FLUSHDB ASYNC that releases the
old data in O(1) from the point of view of the client, to reclaim memory
incrementally in a different thread.
At this point, the pattern can really be supported without latency
spikes, so I'm providing this implementation for the users to comment.
In case a very compelling argument will be made against this new command
it may be removed.
BEHAVIOR WITH BLOCKING OPERATIONS
---
If a client is blocking for a list in a given DB, after the swap it will
still be blocked in the same DB ID, since this is the most logical thing
to do: if I was blocked for a list push to list "foo", even after the
swap I want still a LPUSH to reach the key "foo" in the same DB in order
to unblock.
However an interesting thing happens when a client is, for instance,
blocked waiting for new elements in list "foo" of DB 0. Then the DB
0 and 1 are swapped with SWAPDB. However the DB 1 happened to have
a list called "foo" containing elements. When this happens, this
implementation can correctly unblock the client.
It is possible that there are subtle corner cases that are not covered
in the implementation, but since the command is self-contained from the
POV of the implementation and the Redis core, it cannot cause anything
bad if not used.
Tests and documentation are yet to be provided.
2016-10-14 09:28:04 -04:00
|
|
|
}
|
|
|
|
dictReleaseIterator(di);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Swap two databases at runtime so that all clients will magically see
|
|
|
|
* the new database even if already connected. Note that the client
|
|
|
|
* structure c->db points to a given DB, so we need to be smarter and
|
|
|
|
* swap the underlying referenced structures, otherwise we would need
|
|
|
|
* to fix all the references to the Redis DB structure.
|
|
|
|
*
|
|
|
|
* Returns C_ERR if at least one of the DB ids are out of range, otherwise
|
|
|
|
* C_OK is returned. */
|
2018-12-31 04:51:03 -05:00
|
|
|
int dbSwapDatabases(long id1, long id2) {
|
SWAPDB command.
This new command swaps two Redis databases, so that immediately all the
clients connected to a given DB will see the data of the other DB, and
the other way around. Example:
SWAPDB 0 1
This will swap DB 0 with DB 1. All the clients connected with DB 0 will
immediately see the new data, exactly like all the clients connected
with DB 1 will see the data that was formerly of DB 0.
MOTIVATION AND HISTORY
---
The command was recently demanded by Pedro Melo, but was suggested in
the past multiple times, and always refused by me.
The reason why it was asked: Imagine you have clients operating in DB 0.
At the same time, you create a new version of the dataset in DB 1.
When the new version of the dataset is available, you immediately want
to swap the two views, so that the clients will transparently use the
new version of the data. At the same time you'll likely destroy the
DB 1 dataset (that contains the old data) and start to build a new
version, to repeat the process.
This is an interesting pattern, but the reason why I always opposed to
implement this, was that FLUSHDB was a blocking command in Redis before
Redis 4.0 improvements. Now we have FLUSHDB ASYNC that releases the
old data in O(1) from the point of view of the client, to reclaim memory
incrementally in a different thread.
At this point, the pattern can really be supported without latency
spikes, so I'm providing this implementation for the users to comment.
In case a very compelling argument will be made against this new command
it may be removed.
BEHAVIOR WITH BLOCKING OPERATIONS
---
If a client is blocking for a list in a given DB, after the swap it will
still be blocked in the same DB ID, since this is the most logical thing
to do: if I was blocked for a list push to list "foo", even after the
swap I want still a LPUSH to reach the key "foo" in the same DB in order
to unblock.
However an interesting thing happens when a client is, for instance,
blocked waiting for new elements in list "foo" of DB 0. Then the DB
0 and 1 are swapped with SWAPDB. However the DB 1 happened to have
a list called "foo" containing elements. When this happens, this
implementation can correctly unblock the client.
It is possible that there are subtle corner cases that are not covered
in the implementation, but since the command is self-contained from the
POV of the implementation and the Redis core, it cannot cause anything
bad if not used.
Tests and documentation are yet to be provided.
2016-10-14 09:28:04 -04:00
|
|
|
if (id1 < 0 || id1 >= server.dbnum ||
|
|
|
|
id2 < 0 || id2 >= server.dbnum) return C_ERR;
|
|
|
|
if (id1 == id2) return C_OK;
|
|
|
|
redisDb aux = server.db[id1];
|
|
|
|
redisDb *db1 = &server.db[id1], *db2 = &server.db[id2];
|
|
|
|
|
|
|
|
/* Swap hash tables. Note that we don't swap blocking_keys,
|
|
|
|
* ready_keys and watched_keys, since we want clients to
|
|
|
|
* remain in the same DB they were. */
|
|
|
|
db1->dict = db2->dict;
|
|
|
|
db1->expires = db2->expires;
|
|
|
|
db1->avg_ttl = db2->avg_ttl;
|
2019-11-14 12:27:37 -05:00
|
|
|
db1->expires_cursor = db2->expires_cursor;
|
SWAPDB command.
This new command swaps two Redis databases, so that immediately all the
clients connected to a given DB will see the data of the other DB, and
the other way around. Example:
SWAPDB 0 1
This will swap DB 0 with DB 1. All the clients connected with DB 0 will
immediately see the new data, exactly like all the clients connected
with DB 1 will see the data that was formerly of DB 0.
MOTIVATION AND HISTORY
---
The command was recently demanded by Pedro Melo, but was suggested in
the past multiple times, and always refused by me.
The reason why it was asked: Imagine you have clients operating in DB 0.
At the same time, you create a new version of the dataset in DB 1.
When the new version of the dataset is available, you immediately want
to swap the two views, so that the clients will transparently use the
new version of the data. At the same time you'll likely destroy the
DB 1 dataset (that contains the old data) and start to build a new
version, to repeat the process.
This is an interesting pattern, but the reason why I always opposed to
implement this, was that FLUSHDB was a blocking command in Redis before
Redis 4.0 improvements. Now we have FLUSHDB ASYNC that releases the
old data in O(1) from the point of view of the client, to reclaim memory
incrementally in a different thread.
At this point, the pattern can really be supported without latency
spikes, so I'm providing this implementation for the users to comment.
In case a very compelling argument will be made against this new command
it may be removed.
BEHAVIOR WITH BLOCKING OPERATIONS
---
If a client is blocking for a list in a given DB, after the swap it will
still be blocked in the same DB ID, since this is the most logical thing
to do: if I was blocked for a list push to list "foo", even after the
swap I want still a LPUSH to reach the key "foo" in the same DB in order
to unblock.
However an interesting thing happens when a client is, for instance,
blocked waiting for new elements in list "foo" of DB 0. Then the DB
0 and 1 are swapped with SWAPDB. However the DB 1 happened to have
a list called "foo" containing elements. When this happens, this
implementation can correctly unblock the client.
It is possible that there are subtle corner cases that are not covered
in the implementation, but since the command is self-contained from the
POV of the implementation and the Redis core, it cannot cause anything
bad if not used.
Tests and documentation are yet to be provided.
2016-10-14 09:28:04 -04:00
|
|
|
|
|
|
|
db2->dict = aux.dict;
|
|
|
|
db2->expires = aux.expires;
|
|
|
|
db2->avg_ttl = aux.avg_ttl;
|
2019-11-14 12:27:37 -05:00
|
|
|
db2->expires_cursor = aux.expires_cursor;
|
SWAPDB command.
This new command swaps two Redis databases, so that immediately all the
clients connected to a given DB will see the data of the other DB, and
the other way around. Example:
SWAPDB 0 1
This will swap DB 0 with DB 1. All the clients connected with DB 0 will
immediately see the new data, exactly like all the clients connected
with DB 1 will see the data that was formerly of DB 0.
MOTIVATION AND HISTORY
---
The command was recently demanded by Pedro Melo, but was suggested in
the past multiple times, and always refused by me.
The reason why it was asked: Imagine you have clients operating in DB 0.
At the same time, you create a new version of the dataset in DB 1.
When the new version of the dataset is available, you immediately want
to swap the two views, so that the clients will transparently use the
new version of the data. At the same time you'll likely destroy the
DB 1 dataset (that contains the old data) and start to build a new
version, to repeat the process.
This is an interesting pattern, but the reason why I always opposed to
implement this, was that FLUSHDB was a blocking command in Redis before
Redis 4.0 improvements. Now we have FLUSHDB ASYNC that releases the
old data in O(1) from the point of view of the client, to reclaim memory
incrementally in a different thread.
At this point, the pattern can really be supported without latency
spikes, so I'm providing this implementation for the users to comment.
In case a very compelling argument will be made against this new command
it may be removed.
BEHAVIOR WITH BLOCKING OPERATIONS
---
If a client is blocking for a list in a given DB, after the swap it will
still be blocked in the same DB ID, since this is the most logical thing
to do: if I was blocked for a list push to list "foo", even after the
swap I want still a LPUSH to reach the key "foo" in the same DB in order
to unblock.
However an interesting thing happens when a client is, for instance,
blocked waiting for new elements in list "foo" of DB 0. Then the DB
0 and 1 are swapped with SWAPDB. However the DB 1 happened to have
a list called "foo" containing elements. When this happens, this
implementation can correctly unblock the client.
It is possible that there are subtle corner cases that are not covered
in the implementation, but since the command is self-contained from the
POV of the implementation and the Redis core, it cannot cause anything
bad if not used.
Tests and documentation are yet to be provided.
2016-10-14 09:28:04 -04:00
|
|
|
|
|
|
|
/* Now we need to handle clients blocked on lists: as an effect
|
|
|
|
* of swapping the two DBs, a client that was waiting for list
|
|
|
|
* X in a given DB, may now actually be unblocked if X happens
|
|
|
|
* to exist in the new version of the DB, after the swap.
|
|
|
|
*
|
|
|
|
* However normally we only do this check for efficiency reasons
|
|
|
|
* in dbAdd() when a list is created. So here we need to rescan
|
|
|
|
* the list of clients blocked on lists and signal lists as ready
|
|
|
|
* if needed. */
|
|
|
|
scanDatabaseForReadyLists(db1);
|
|
|
|
scanDatabaseForReadyLists(db2);
|
|
|
|
return C_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SWAPDB db1 db2 */
|
|
|
|
void swapdbCommand(client *c) {
|
|
|
|
long id1, id2;
|
|
|
|
|
|
|
|
/* Not allowed in cluster mode: we have just DB 0 there. */
|
|
|
|
if (server.cluster_enabled) {
|
|
|
|
addReplyError(c,"SWAPDB is not allowed in cluster mode");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the two DBs indexes. */
|
|
|
|
if (getLongFromObjectOrReply(c, c->argv[1], &id1,
|
|
|
|
"invalid first DB index") != C_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (getLongFromObjectOrReply(c, c->argv[2], &id2,
|
|
|
|
"invalid second DB index") != C_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Swap... */
|
|
|
|
if (dbSwapDatabases(id1,id2) == C_ERR) {
|
|
|
|
addReplyError(c,"DB index is out of range");
|
|
|
|
return;
|
|
|
|
} else {
|
2020-09-20 06:36:20 -04:00
|
|
|
RedisModuleSwapDbInfo si = {REDISMODULE_SWAPDBINFO_VERSION,id1,id2};
|
|
|
|
moduleFireServerEvent(REDISMODULE_EVENT_SWAPDB,0,&si);
|
SWAPDB command.
This new command swaps two Redis databases, so that immediately all the
clients connected to a given DB will see the data of the other DB, and
the other way around. Example:
SWAPDB 0 1
This will swap DB 0 with DB 1. All the clients connected with DB 0 will
immediately see the new data, exactly like all the clients connected
with DB 1 will see the data that was formerly of DB 0.
MOTIVATION AND HISTORY
---
The command was recently demanded by Pedro Melo, but was suggested in
the past multiple times, and always refused by me.
The reason why it was asked: Imagine you have clients operating in DB 0.
At the same time, you create a new version of the dataset in DB 1.
When the new version of the dataset is available, you immediately want
to swap the two views, so that the clients will transparently use the
new version of the data. At the same time you'll likely destroy the
DB 1 dataset (that contains the old data) and start to build a new
version, to repeat the process.
This is an interesting pattern, but the reason why I always opposed to
implement this, was that FLUSHDB was a blocking command in Redis before
Redis 4.0 improvements. Now we have FLUSHDB ASYNC that releases the
old data in O(1) from the point of view of the client, to reclaim memory
incrementally in a different thread.
At this point, the pattern can really be supported without latency
spikes, so I'm providing this implementation for the users to comment.
In case a very compelling argument will be made against this new command
it may be removed.
BEHAVIOR WITH BLOCKING OPERATIONS
---
If a client is blocking for a list in a given DB, after the swap it will
still be blocked in the same DB ID, since this is the most logical thing
to do: if I was blocked for a list push to list "foo", even after the
swap I want still a LPUSH to reach the key "foo" in the same DB in order
to unblock.
However an interesting thing happens when a client is, for instance,
blocked waiting for new elements in list "foo" of DB 0. Then the DB
0 and 1 are swapped with SWAPDB. However the DB 1 happened to have
a list called "foo" containing elements. When this happens, this
implementation can correctly unblock the client.
It is possible that there are subtle corner cases that are not covered
in the implementation, but since the command is self-contained from the
POV of the implementation and the Redis core, it cannot cause anything
bad if not used.
Tests and documentation are yet to be provided.
2016-10-14 09:28:04 -04:00
|
|
|
server.dirty++;
|
|
|
|
addReply(c,shared.ok);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-21 18:07:48 -04:00
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
* Expires API
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
int removeExpire(redisDb *db, robj *key) {
|
|
|
|
/* An expire may only be removed if there is a corresponding entry in the
|
|
|
|
* main dict. Otherwise, the key will never be freed. */
|
2015-07-26 09:29:53 -04:00
|
|
|
serverAssertWithInfo(NULL,key,dictFind(db->dict,key->ptr) != NULL);
|
2010-08-03 08:19:20 -04:00
|
|
|
return dictDelete(db->expires,key->ptr) == DICT_OK;
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
|
Replication: fix the infamous key leakage of writable slaves + EXPIRE.
BACKGROUND AND USE CASEj
Redis slaves are normally write only, however the supprot a "writable"
mode which is very handy when scaling reads on slaves, that actually
need write operations in order to access data. For instance imagine
having slaves replicating certain Sets keys from the master. When
accessing the data on the slave, we want to peform intersections between
such Sets values. However we don't want to intersect each time: to cache
the intersection for some time often is a good idea.
To do so, it is possible to setup a slave as a writable slave, and
perform the intersection on the slave side, perhaps setting a TTL on the
resulting key so that it will expire after some time.
THE BUG
Problem: in order to have a consistent replication, expiring of keys in
Redis replication is up to the master, that synthesize DEL operations to
send in the replication stream. However slaves logically expire keys
by hiding them from read attempts from clients so that if the master did
not promptly sent a DEL, the client still see logically expired keys
as non existing.
Because slaves don't actively expire keys by actually evicting them but
just masking from the POV of read operations, if a key is created in a
writable slave, and an expire is set, the key will be leaked forever:
1. No DEL will be received from the master, which does not know about
such a key at all.
2. No eviction will be performed by the slave, since it needs to disable
eviction because it's up to masters, otherwise consistency of data is
lost.
THE FIX
In order to fix the problem, the slave should be able to tag keys that
were created in the slave side and have an expire set in some way.
My solution involved using an unique additional dictionary created by
the writable slave only if needed. The dictionary is obviously keyed by
the key name that we need to track: all the keys that are set with an
expire directly by a client writing to the slave are tracked.
The value in the dictionary is a bitmap of all the DBs where such a key
name need to be tracked, so that we can use a single dictionary to track
keys in all the DBs used by the slave (actually this limits the solution
to the first 64 DBs, but the default with Redis is to use 16 DBs).
This solution allows to pay both a small complexity and CPU penalty,
which is zero when the feature is not used, actually. The slave-side
eviction is encapsulated in code which is not coupled with the rest of
the Redis core, if not for the hook to track the keys.
TODO
I'm doing the first smoke tests to see if the feature works as expected:
so far so good. Unit tests should be added before merging into the
4.0 branch.
2016-12-13 04:20:06 -05:00
|
|
|
/* Set an expire to the specified key. If the expire is set in the context
|
|
|
|
* of an user calling a command 'c' is the client, otherwise 'c' is set
|
|
|
|
* to NULL. The 'when' parameter is the absolute unix time in milliseconds
|
|
|
|
* after which the key will no longer be considered valid. */
|
|
|
|
void setExpire(client *c, redisDb *db, robj *key, long long when) {
|
2011-11-09 10:51:19 -05:00
|
|
|
dictEntry *kde, *de;
|
2010-06-21 18:07:48 -04:00
|
|
|
|
|
|
|
/* Reuse the sds from the main dict in the expire dict */
|
2011-11-09 10:51:19 -05:00
|
|
|
kde = dictFind(db->dict,key->ptr);
|
2015-07-26 09:29:53 -04:00
|
|
|
serverAssertWithInfo(NULL,key,kde != NULL);
|
2016-09-14 10:43:38 -04:00
|
|
|
de = dictAddOrFind(db->expires,dictGetKey(kde));
|
2011-11-09 10:51:19 -05:00
|
|
|
dictSetSignedIntegerVal(de,when);
|
Replication: fix the infamous key leakage of writable slaves + EXPIRE.
BACKGROUND AND USE CASEj
Redis slaves are normally write only, however the supprot a "writable"
mode which is very handy when scaling reads on slaves, that actually
need write operations in order to access data. For instance imagine
having slaves replicating certain Sets keys from the master. When
accessing the data on the slave, we want to peform intersections between
such Sets values. However we don't want to intersect each time: to cache
the intersection for some time often is a good idea.
To do so, it is possible to setup a slave as a writable slave, and
perform the intersection on the slave side, perhaps setting a TTL on the
resulting key so that it will expire after some time.
THE BUG
Problem: in order to have a consistent replication, expiring of keys in
Redis replication is up to the master, that synthesize DEL operations to
send in the replication stream. However slaves logically expire keys
by hiding them from read attempts from clients so that if the master did
not promptly sent a DEL, the client still see logically expired keys
as non existing.
Because slaves don't actively expire keys by actually evicting them but
just masking from the POV of read operations, if a key is created in a
writable slave, and an expire is set, the key will be leaked forever:
1. No DEL will be received from the master, which does not know about
such a key at all.
2. No eviction will be performed by the slave, since it needs to disable
eviction because it's up to masters, otherwise consistency of data is
lost.
THE FIX
In order to fix the problem, the slave should be able to tag keys that
were created in the slave side and have an expire set in some way.
My solution involved using an unique additional dictionary created by
the writable slave only if needed. The dictionary is obviously keyed by
the key name that we need to track: all the keys that are set with an
expire directly by a client writing to the slave are tracked.
The value in the dictionary is a bitmap of all the DBs where such a key
name need to be tracked, so that we can use a single dictionary to track
keys in all the DBs used by the slave (actually this limits the solution
to the first 64 DBs, but the default with Redis is to use 16 DBs).
This solution allows to pay both a small complexity and CPU penalty,
which is zero when the feature is not used, actually. The slave-side
eviction is encapsulated in code which is not coupled with the rest of
the Redis core, if not for the hook to track the keys.
TODO
I'm doing the first smoke tests to see if the feature works as expected:
so far so good. Unit tests should be added before merging into the
4.0 branch.
2016-12-13 04:20:06 -05:00
|
|
|
|
|
|
|
int writable_slave = server.masterhost && server.repl_slave_ro == 0;
|
|
|
|
if (c && writable_slave && !(c->flags & CLIENT_MASTER))
|
|
|
|
rememberSlaveKeyWithExpire(db,key);
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the expire time of the specified key, or -1 if no expire
|
|
|
|
* is associated with this key (i.e. the key is non volatile) */
|
2011-11-09 10:51:19 -05:00
|
|
|
long long getExpire(redisDb *db, robj *key) {
|
2010-06-21 18:07:48 -04:00
|
|
|
dictEntry *de;
|
|
|
|
|
|
|
|
/* No expire? return ASAP */
|
|
|
|
if (dictSize(db->expires) == 0 ||
|
|
|
|
(de = dictFind(db->expires,key->ptr)) == NULL) return -1;
|
|
|
|
|
|
|
|
/* The entry was found in the expire dict, this means it should also
|
|
|
|
* be present in the main dict (safety check). */
|
2015-07-26 09:29:53 -04:00
|
|
|
serverAssertWithInfo(NULL,key,dictFind(db->dict,key->ptr) != NULL);
|
2011-11-09 10:51:19 -05:00
|
|
|
return dictGetSignedIntegerVal(de);
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
|
2010-08-02 12:13:39 -04:00
|
|
|
/* Propagate expires into slaves and the AOF file.
|
|
|
|
* When a key expires in the master, a DEL operation for this key is sent
|
|
|
|
* to all the slaves and the AOF file if enabled.
|
|
|
|
*
|
|
|
|
* This way the key expiry is centralized in one place, and since both
|
|
|
|
* AOF and the master->slave link guarantee operation ordering, everything
|
|
|
|
* will be consistent even if we allow write operations against expiring
|
|
|
|
* keys. */
|
2015-10-02 09:27:57 -04:00
|
|
|
void propagateExpire(redisDb *db, robj *key, int lazy) {
|
2010-08-02 12:13:39 -04:00
|
|
|
robj *argv[2];
|
|
|
|
|
2015-10-02 09:27:57 -04:00
|
|
|
argv[0] = lazy ? shared.unlink : shared.del;
|
2010-08-02 12:13:39 -04:00
|
|
|
argv[1] = key;
|
2012-02-04 02:58:37 -05:00
|
|
|
incrRefCount(argv[0]);
|
|
|
|
incrRefCount(argv[1]);
|
2010-08-02 12:13:39 -04:00
|
|
|
|
2020-07-29 20:54:37 -04:00
|
|
|
propagate(server.delCommand,db->id,argv,2,PROPAGATE_AOF|PROPAGATE_REPL);
|
2010-08-02 12:13:39 -04:00
|
|
|
|
2010-08-02 15:37:39 -04:00
|
|
|
decrRefCount(argv[0]);
|
|
|
|
decrRefCount(argv[1]);
|
2010-08-02 12:13:39 -04:00
|
|
|
}
|
|
|
|
|
2018-10-19 06:00:57 -04:00
|
|
|
/* Check if the key is expired. */
|
|
|
|
int keyIsExpired(redisDb *db, robj *key) {
|
|
|
|
mstime_t when = getExpire(db,key);
|
2019-11-06 03:57:29 -05:00
|
|
|
mstime_t now;
|
2018-10-19 06:00:57 -04:00
|
|
|
|
|
|
|
if (when < 0) return 0; /* No expire for this key */
|
|
|
|
|
|
|
|
/* Don't expire anything while loading. It will be done later. */
|
|
|
|
if (server.loading) return 0;
|
|
|
|
|
|
|
|
/* If we are in the context of a Lua script, we pretend that time is
|
|
|
|
* blocked to when the Lua script started. This way a key can expire
|
|
|
|
* only the first time it is accessed and not in the middle of the
|
|
|
|
* script execution, making propagation to slaves / AOF consistent.
|
2019-11-06 03:57:29 -05:00
|
|
|
* See issue #1525 on Github for more information. */
|
|
|
|
if (server.lua_caller) {
|
|
|
|
now = server.lua_time_start;
|
|
|
|
}
|
|
|
|
/* If we are in the middle of a command execution, we still want to use
|
|
|
|
* a reference time that does not change: in that case we just use the
|
|
|
|
* cached time, that we update before each call in the call() function.
|
|
|
|
* This way we avoid that commands such as RPOPLPUSH or similar, that
|
|
|
|
* may re-open the same key multiple times, can invalidate an already
|
|
|
|
* open object in a next call, if the next call will see the key expired,
|
|
|
|
* while the first did not. */
|
2019-11-19 05:28:04 -05:00
|
|
|
else if (server.fixed_time_expire > 0) {
|
2019-11-06 03:57:29 -05:00
|
|
|
now = server.mstime;
|
|
|
|
}
|
|
|
|
/* For the other cases, we want to use the most fresh time we have. */
|
|
|
|
else {
|
|
|
|
now = mstime();
|
|
|
|
}
|
2018-10-19 06:00:57 -04:00
|
|
|
|
2019-11-06 03:57:29 -05:00
|
|
|
/* The key expired if the current (virtual or real) time is greater
|
|
|
|
* than the expire time of the key. */
|
2018-10-19 06:00:57 -04:00
|
|
|
return now > when;
|
|
|
|
}
|
|
|
|
|
2018-02-27 10:44:39 -05:00
|
|
|
/* This function is called when we are going to perform some operation
|
|
|
|
* in a given key, but such key may be already logically expired even if
|
|
|
|
* it still exists in the database. The main way this function is called
|
|
|
|
* is via lookupKey*() family of functions.
|
|
|
|
*
|
|
|
|
* The behavior of the function depends on the replication role of the
|
|
|
|
* instance, because slave instances do not expire keys, they wait
|
|
|
|
* for DELs from the master for consistency matters. However even
|
|
|
|
* slaves will try to have a coherent return value for the function,
|
|
|
|
* so that read commands executed in the slave side will be able to
|
|
|
|
* behave like if the key is expired even if still present (because the
|
|
|
|
* master has yet to propagate the DEL).
|
|
|
|
*
|
|
|
|
* In masters as a side effect of finding a key which is expired, such
|
|
|
|
* key will be evicted from the database. Also this may trigger the
|
|
|
|
* propagation of a DEL/UNLINK command in AOF / replication stream.
|
|
|
|
*
|
|
|
|
* The return value of the function is 0 if the key is still valid,
|
|
|
|
* otherwise the function returns 1 if the key is expired. */
|
2010-06-21 18:07:48 -04:00
|
|
|
int expireIfNeeded(redisDb *db, robj *key) {
|
2018-10-24 06:26:27 -04:00
|
|
|
if (!keyIsExpired(db,key)) return 0;
|
|
|
|
|
|
|
|
/* If we are running in the context of a slave, instead of
|
|
|
|
* evicting the expired key from the database, we return ASAP:
|
|
|
|
* the slave key expiration is controlled by the master that will
|
|
|
|
* send us synthesized DEL operations for expired keys.
|
|
|
|
*
|
|
|
|
* Still we try to return the right information to the caller,
|
|
|
|
* that is, 0 if we think the key should be still valid, 1 if
|
|
|
|
* we think the key is expired at this time. */
|
|
|
|
if (server.masterhost != NULL) return 1;
|
2010-06-21 18:07:48 -04:00
|
|
|
|
|
|
|
/* Delete the key */
|
|
|
|
server.stat_expiredkeys++;
|
2015-10-02 09:27:57 -04:00
|
|
|
propagateExpire(db,key,server.lazyfree_lazy_expire);
|
2015-07-27 03:41:48 -04:00
|
|
|
notifyKeyspaceEvent(NOTIFY_EXPIRED,
|
2013-01-28 07:00:03 -05:00
|
|
|
"expired",key,db->id);
|
2020-02-14 12:22:25 -05:00
|
|
|
int retval = server.lazyfree_lazy_expire ? dbAsyncDelete(db,key) :
|
|
|
|
dbSyncDelete(db,key);
|
2020-04-21 04:51:46 -04:00
|
|
|
if (retval) signalModifiedKey(NULL,db,key);
|
2020-02-14 12:22:25 -05:00
|
|
|
return retval;
|
2010-06-21 18:07:48 -04:00
|
|
|
}
|
|
|
|
|
2011-03-23 13:09:17 -04:00
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* API to get key arguments from commands
|
|
|
|
* ---------------------------------------------------------------------------*/
|
2020-10-05 10:03:17 -04:00
|
|
|
|
|
|
|
/* Prepare the getKeysResult struct to hold numkeys, either by using the
|
|
|
|
* pre-allocated keysbuf or by allocating a new array on the heap.
|
|
|
|
*
|
|
|
|
* This function must be called at least once before starting to populate
|
|
|
|
* the result, and can be called repeatedly to enlarge the result array.
|
|
|
|
*/
|
|
|
|
int *getKeysPrepareResult(getKeysResult *result, int numkeys) {
|
|
|
|
/* GETKEYS_RESULT_INIT initializes keys to NULL, point it to the pre-allocated stack
|
|
|
|
* buffer here. */
|
|
|
|
if (!result->keys) {
|
|
|
|
serverAssert(!result->numkeys);
|
|
|
|
result->keys = result->keysbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Resize if necessary */
|
|
|
|
if (numkeys > result->size) {
|
|
|
|
if (result->keys != result->keysbuf) {
|
|
|
|
/* We're not using a static buffer, just (re)alloc */
|
|
|
|
result->keys = zrealloc(result->keys, numkeys * sizeof(int));
|
|
|
|
} else {
|
|
|
|
/* We are using a static buffer, copy its contents */
|
|
|
|
result->keys = zmalloc(numkeys * sizeof(int));
|
|
|
|
if (result->numkeys)
|
|
|
|
memcpy(result->keys, result->keysbuf, result->numkeys * sizeof(int));
|
|
|
|
}
|
|
|
|
result->size = numkeys;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result->keys;
|
|
|
|
}
|
2011-03-23 13:09:17 -04:00
|
|
|
|
2014-03-10 10:24:38 -04:00
|
|
|
/* The base case is to use the keys position as given in the command table
|
|
|
|
* (firstkey, lastkey, step). */
|
2020-10-05 10:03:17 -04:00
|
|
|
int getKeysUsingCommandTable(struct redisCommand *cmd,robj **argv, int argc, getKeysResult *result) {
|
2011-03-23 13:09:17 -04:00
|
|
|
int j, i = 0, last, *keys;
|
2015-07-27 03:41:48 -04:00
|
|
|
UNUSED(argv);
|
2011-03-23 13:09:17 -04:00
|
|
|
|
|
|
|
if (cmd->firstkey == 0) {
|
2020-10-05 10:03:17 -04:00
|
|
|
result->numkeys = 0;
|
|
|
|
return 0;
|
2011-03-23 13:09:17 -04:00
|
|
|
}
|
2017-04-19 10:17:08 -04:00
|
|
|
|
2011-03-23 13:09:17 -04:00
|
|
|
last = cmd->lastkey;
|
|
|
|
if (last < 0) last = argc+last;
|
2020-02-05 11:06:33 -05:00
|
|
|
|
|
|
|
int count = ((last - cmd->firstkey)+1);
|
2020-10-05 10:03:17 -04:00
|
|
|
keys = getKeysPrepareResult(result, count);
|
2020-02-05 11:06:33 -05:00
|
|
|
|
2011-03-23 13:09:17 -04:00
|
|
|
for (j = cmd->firstkey; j <= last; j += cmd->keystep) {
|
2017-04-19 10:17:08 -04:00
|
|
|
if (j >= argc) {
|
2018-01-12 05:21:10 -05:00
|
|
|
/* Modules commands, and standard commands with a not fixed number
|
2018-07-01 01:24:50 -04:00
|
|
|
* of arguments (negative arity parameter) do not have dispatch
|
2018-01-12 05:21:10 -05:00
|
|
|
* time arity checks, so we need to handle the case where the user
|
|
|
|
* passed an invalid number of arguments here. In this case we
|
|
|
|
* return no keys and expect the command implementation to report
|
|
|
|
* an arity or syntax error. */
|
|
|
|
if (cmd->flags & CMD_MODULE || cmd->arity < 0) {
|
2020-10-05 10:03:17 -04:00
|
|
|
getKeysFreeResult(result);
|
|
|
|
result->numkeys = 0;
|
|
|
|
return 0;
|
2017-04-19 10:17:08 -04:00
|
|
|
} else {
|
|
|
|
serverPanic("Redis built-in command declared keys positions not matching the arity requirements.");
|
|
|
|
}
|
|
|
|
}
|
2011-03-28 11:54:42 -04:00
|
|
|
keys[i++] = j;
|
2011-03-23 13:09:17 -04:00
|
|
|
}
|
2020-10-05 10:03:17 -04:00
|
|
|
result->numkeys = i;
|
|
|
|
return i;
|
2011-03-23 13:09:17 -04:00
|
|
|
}
|
|
|
|
|
2014-03-10 10:31:01 -04:00
|
|
|
/* Return all the arguments that are keys in the command passed via argc / argv.
|
|
|
|
*
|
|
|
|
* The command returns the positions of all the key arguments inside the array,
|
Squash merging 125 typo/grammar/comment/doc PRs (#7773)
List of squashed commits or PRs
===============================
commit 66801ea
Author: hwware <wen.hui.ware@gmail.com>
Date: Mon Jan 13 00:54:31 2020 -0500
typo fix in acl.c
commit 46f55db
Author: Itamar Haber <itamar@redislabs.com>
Date: Sun Sep 6 18:24:11 2020 +0300
Updates a couple of comments
Specifically:
* RM_AutoMemory completed instead of pointing to docs
* Updated link to custom type doc
commit 61a2aa0
Author: xindoo <xindoo@qq.com>
Date: Tue Sep 1 19:24:59 2020 +0800
Correct errors in code comments
commit a5871d1
Author: yz1509 <pro-756@qq.com>
Date: Tue Sep 1 18:36:06 2020 +0800
fix typos in module.c
commit 41eede7
Author: bookug <bookug@qq.com>
Date: Sat Aug 15 01:11:33 2020 +0800
docs: fix typos in comments
commit c303c84
Author: lazy-snail <ws.niu@outlook.com>
Date: Fri Aug 7 11:15:44 2020 +0800
fix spelling in redis.conf
commit 1eb76bf
Author: zhujian <zhujianxyz@gmail.com>
Date: Thu Aug 6 15:22:10 2020 +0800
add a missing 'n' in comment
commit 1530ec2
Author: Daniel Dai <764122422@qq.com>
Date: Mon Jul 27 00:46:35 2020 -0400
fix spelling in tracking.c
commit e517b31
Author: Hunter-Chen <huntcool001@gmail.com>
Date: Fri Jul 17 22:33:32 2020 +0800
Update redis.conf
Co-authored-by: Itamar Haber <itamar@redislabs.com>
commit c300eff
Author: Hunter-Chen <huntcool001@gmail.com>
Date: Fri Jul 17 22:33:23 2020 +0800
Update redis.conf
Co-authored-by: Itamar Haber <itamar@redislabs.com>
commit 4c058a8
Author: 陈浩鹏 <chenhaopeng@heytea.com>
Date: Thu Jun 25 19:00:56 2020 +0800
Grammar fix and clarification
commit 5fcaa81
Author: bodong.ybd <bodong.ybd@alibaba-inc.com>
Date: Fri Jun 19 10:09:00 2020 +0800
Fix typos
commit 4caca9a
Author: Pruthvi P <pruthvi@ixigo.com>
Date: Fri May 22 00:33:22 2020 +0530
Fix typo eviciton => eviction
commit b2a25f6
Author: Brad Dunbar <dunbarb2@gmail.com>
Date: Sun May 17 12:39:59 2020 -0400
Fix a typo.
commit 12842ae
Author: hwware <wen.hui.ware@gmail.com>
Date: Sun May 3 17:16:59 2020 -0400
fix spelling in redis conf
commit ddba07c
Author: Chris Lamb <chris@chris-lamb.co.uk>
Date: Sat May 2 23:25:34 2020 +0100
Correct a "conflicts" spelling error.
commit 8fc7bf2
Author: Nao YONASHIRO <yonashiro@r.recruit.co.jp>
Date: Thu Apr 30 10:25:27 2020 +0900
docs: fix EXPIRE_FAST_CYCLE_DURATION to ACTIVE_EXPIRE_CYCLE_FAST_DURATION
commit 9b2b67a
Author: Brad Dunbar <dunbarb2@gmail.com>
Date: Fri Apr 24 11:46:22 2020 -0400
Fix a typo.
commit 0746f10
Author: devilinrust <63737265+devilinrust@users.noreply.github.com>
Date: Thu Apr 16 00:17:53 2020 +0200
Fix typos in server.c
commit 92b588d
Author: benjessop12 <56115861+benjessop12@users.noreply.github.com>
Date: Mon Apr 13 13:43:55 2020 +0100
Fix spelling mistake in lazyfree.c
commit 1da37aa
Merge: 2d4ba28 af347a8
Author: hwware <wen.hui.ware@gmail.com>
Date: Thu Mar 5 22:41:31 2020 -0500
Merge remote-tracking branch 'upstream/unstable' into expiretypofix
commit 2d4ba28
Author: hwware <wen.hui.ware@gmail.com>
Date: Mon Mar 2 00:09:40 2020 -0500
fix typo in expire.c
commit 1a746f7
Author: SennoYuki <minakami1yuki@gmail.com>
Date: Thu Feb 27 16:54:32 2020 +0800
fix typo
commit 8599b1a
Author: dongheejeong <donghee950403@gmail.com>
Date: Sun Feb 16 20:31:43 2020 +0000
Fix typo in server.c
commit f38d4e8
Author: hwware <wen.hui.ware@gmail.com>
Date: Sun Feb 2 22:58:38 2020 -0500
fix typo in evict.c
commit fe143fc
Author: Leo Murillo <leonardo.murillo@gmail.com>
Date: Sun Feb 2 01:57:22 2020 -0600
Fix a few typos in redis.conf
commit 1ab4d21
Author: viraja1 <anchan.viraj@gmail.com>
Date: Fri Dec 27 17:15:58 2019 +0530
Fix typo in Latency API docstring
commit ca1f70e
Author: gosth <danxuedexing@qq.com>
Date: Wed Dec 18 15:18:02 2019 +0800
fix typo in sort.c
commit a57c06b
Author: ZYunH <zyunhjob@163.com>
Date: Mon Dec 16 22:28:46 2019 +0800
fix-zset-typo
commit b8c92b5
Author: git-hulk <hulk.website@gmail.com>
Date: Mon Dec 16 15:51:42 2019 +0800
FIX: typo in cluster.c, onformation->information
commit 9dd981c
Author: wujm2007 <jim.wujm@gmail.com>
Date: Mon Dec 16 09:37:52 2019 +0800
Fix typo
commit e132d7a
Author: Sebastien Williams-Wynn <s.williamswynn.mail@gmail.com>
Date: Fri Nov 15 00:14:07 2019 +0000
Minor typo change
commit 47f44d5
Author: happynote3966 <01ssrmikururudevice01@gmail.com>
Date: Mon Nov 11 22:08:48 2019 +0900
fix comment typo in redis-cli.c
commit b8bdb0d
Author: fulei <fulei@kuaishou.com>
Date: Wed Oct 16 18:00:17 2019 +0800
Fix a spelling mistake of comments in defragDictBucketCallback
commit 0def46a
Author: fulei <fulei@kuaishou.com>
Date: Wed Oct 16 13:09:27 2019 +0800
fix some spelling mistakes of comments in defrag.c
commit f3596fd
Author: Phil Rajchgot <tophil@outlook.com>
Date: Sun Oct 13 02:02:32 2019 -0400
Typo and grammar fixes
Redis and its documentation are great -- just wanted to submit a few corrections in the spirit of Hacktoberfest. Thanks for all your work on this project. I use it all the time and it works beautifully.
commit 2b928cd
Author: KangZhiDong <worldkzd@gmail.com>
Date: Sun Sep 1 07:03:11 2019 +0800
fix typos
commit 33aea14
Author: Axlgrep <axlgrep@gmail.com>
Date: Tue Aug 27 11:02:18 2019 +0800
Fixed eviction spelling issues
commit e282a80
Author: Simen Flatby <simen@oms.no>
Date: Tue Aug 20 15:25:51 2019 +0200
Update comments to reflect prop name
In the comments the prop is referenced as replica-validity-factor,
but it is really named cluster-replica-validity-factor.
commit 74d1f9a
Author: Jim Green <jimgreen2013@qq.com>
Date: Tue Aug 20 20:00:31 2019 +0800
fix comment error, the code is ok
commit eea1407
Author: Liao Tonglang <liaotonglang@gmail.com>
Date: Fri May 31 10:16:18 2019 +0800
typo fix
fix cna't to can't
commit 0da553c
Author: KAWACHI Takashi <tkawachi@gmail.com>
Date: Wed Jul 17 00:38:16 2019 +0900
Fix typo
commit 7fc8fb6
Author: Michael Prokop <mika@grml.org>
Date: Tue May 28 17:58:42 2019 +0200
Typo fixes
s/familar/familiar/
s/compatiblity/compatibility/
s/ ot / to /
s/itsef/itself/
commit 5f46c9d
Author: zhumoing <34539422+zhumoing@users.noreply.github.com>
Date: Tue May 21 21:16:50 2019 +0800
typo-fixes
typo-fixes
commit 321dfe1
Author: wxisme <850885154@qq.com>
Date: Sat Mar 16 15:10:55 2019 +0800
typo fix
commit b4fb131
Merge: 267e0e6 3df1eb8
Author: Nikitas Bastas <nikitasbst@gmail.com>
Date: Fri Feb 8 22:55:45 2019 +0200
Merge branch 'unstable' of antirez/redis into unstable
commit 267e0e6
Author: Nikitas Bastas <nikitasbst@gmail.com>
Date: Wed Jan 30 21:26:04 2019 +0200
Minor typo fix
commit 30544e7
Author: inshal96 <39904558+inshal96@users.noreply.github.com>
Date: Fri Jan 4 16:54:50 2019 +0500
remove an extra 'a' in the comments
commit 337969d
Author: BrotherGao <yangdongheng11@gmail.com>
Date: Sat Dec 29 12:37:29 2018 +0800
fix typo in redis.conf
commit 9f4b121
Merge: 423a030 e504583
Author: BrotherGao <yangdongheng@xiaomi.com>
Date: Sat Dec 29 11:41:12 2018 +0800
Merge branch 'unstable' of antirez/redis into unstable
commit 423a030
Merge: 42b02b7 46a51cd
Author: 杨东衡 <yangdongheng@xiaomi.com>
Date: Tue Dec 4 23:56:11 2018 +0800
Merge branch 'unstable' of antirez/redis into unstable
commit 42b02b7
Merge: 68c0e6e b8febe6
Author: Dongheng Yang <yangdongheng11@gmail.com>
Date: Sun Oct 28 15:54:23 2018 +0800
Merge pull request #1 from antirez/unstable
update local data
commit 714b589
Author: Christian <crifei93@gmail.com>
Date: Fri Dec 28 01:17:26 2018 +0100
fix typo "resulution"
commit e23259d
Author: garenchan <1412950785@qq.com>
Date: Wed Dec 26 09:58:35 2018 +0800
fix typo: segfauls -> segfault
commit a9359f8
Author: xjp <jianping_xie@aliyun.com>
Date: Tue Dec 18 17:31:44 2018 +0800
Fixed REDISMODULE_H spell bug
commit a12c3e4
Author: jdiaz <jrd.palacios@gmail.com>
Date: Sat Dec 15 23:39:52 2018 -0600
Fixes hyperloglog hash function comment block description
commit 770eb11
Author: 林上耀 <1210tom@163.com>
Date: Sun Nov 25 17:16:10 2018 +0800
fix typo
commit fd97fbb
Author: Chris Lamb <chris@chris-lamb.co.uk>
Date: Fri Nov 23 17:14:01 2018 +0100
Correct "unsupported" typo.
commit a85522d
Author: Jungnam Lee <jungnam.lee@oracle.com>
Date: Thu Nov 8 23:01:29 2018 +0900
fix typo in test comments
commit ade8007
Author: Arun Kumar <palerdot@users.noreply.github.com>
Date: Tue Oct 23 16:56:35 2018 +0530
Fixed grammatical typo
Fixed typo for word 'dictionary'
commit 869ee39
Author: Hamid Alaei <hamid.a85@gmail.com>
Date: Sun Aug 12 16:40:02 2018 +0430
fix documentations: (ThreadSafeContextStart/Stop -> ThreadSafeContextLock/Unlock), minor typo
commit f89d158
Author: Mayank Jain <mayankjain255@gmail.com>
Date: Tue Jul 31 23:01:21 2018 +0530
Updated README.md with some spelling corrections.
Made correction in spelling of some misspelled words.
commit 892198e
Author: dsomeshwar <someshwar.dhayalan@gmail.com>
Date: Sat Jul 21 23:23:04 2018 +0530
typo fix
commit 8a4d780
Author: Itamar Haber <itamar@redislabs.com>
Date: Mon Apr 30 02:06:52 2018 +0300
Fixes some typos
commit e3acef6
Author: Noah Rosamilia <ivoahivoah@gmail.com>
Date: Sat Mar 3 23:41:21 2018 -0500
Fix typo in /deps/README.md
commit 04442fb
Author: WuYunlong <xzsyeb@126.com>
Date: Sat Mar 3 10:32:42 2018 +0800
Fix typo in readSyncBulkPayload() comment.
commit 9f36880
Author: WuYunlong <xzsyeb@126.com>
Date: Sat Mar 3 10:20:37 2018 +0800
replication.c comment: run_id -> replid.
commit f866b4a
Author: Francesco 'makevoid' Canessa <makevoid@gmail.com>
Date: Thu Feb 22 22:01:56 2018 +0000
fix comment typo in server.c
commit 0ebc69b
Author: 줍 <jubee0124@gmail.com>
Date: Mon Feb 12 16:38:48 2018 +0900
Fix typo in redis.conf
Fix `five behaviors` to `eight behaviors` in [this sentence ](antirez/redis@unstable/redis.conf#L564)
commit b50a620
Author: martinbroadhurst <martinbroadhurst@users.noreply.github.com>
Date: Thu Dec 28 12:07:30 2017 +0000
Fix typo in valgrind.sup
commit 7d8f349
Author: Peter Boughton <peter@sorcerersisle.com>
Date: Mon Nov 27 19:52:19 2017 +0000
Update CONTRIBUTING; refer doc updates to redis-doc repo.
commit 02dec7e
Author: Klauswk <klauswk1@hotmail.com>
Date: Tue Oct 24 16:18:38 2017 -0200
Fix typo in comment
commit e1efbc8
Author: chenshi <baiwfg2@gmail.com>
Date: Tue Oct 3 18:26:30 2017 +0800
Correct two spelling errors of comments
commit 93327d8
Author: spacewander <spacewanderlzx@gmail.com>
Date: Wed Sep 13 16:47:24 2017 +0800
Update the comment for OBJ_ENCODING_EMBSTR_SIZE_LIMIT's value
The value of OBJ_ENCODING_EMBSTR_SIZE_LIMIT is 44 now instead of 39.
commit 63d361f
Author: spacewander <spacewanderlzx@gmail.com>
Date: Tue Sep 12 15:06:42 2017 +0800
Fix <prevlen> related doc in ziplist.c
According to the definition of ZIP_BIG_PREVLEN and other related code,
the guard of single byte <prevlen> should be 254 instead of 255.
commit ebe228d
Author: hanael80 <hanael80@gmail.com>
Date: Tue Aug 15 09:09:40 2017 +0900
Fix typo
commit 6b696e6
Author: Matt Robenolt <matt@ydekproductions.com>
Date: Mon Aug 14 14:50:47 2017 -0700
Fix typo in LATENCY DOCTOR output
commit a2ec6ae
Author: caosiyang <caosiyang@qiyi.com>
Date: Tue Aug 15 14:15:16 2017 +0800
Fix a typo: form => from
commit 3ab7699
Author: caosiyang <caosiyang@qiyi.com>
Date: Thu Aug 10 18:40:33 2017 +0800
Fix a typo: replicationFeedSlavesFromMaster() => replicationFeedSlavesFromMasterStream()
commit 72d43ef
Author: caosiyang <caosiyang@qiyi.com>
Date: Tue Aug 8 15:57:25 2017 +0800
fix a typo: servewr => server
commit 707c958
Author: Bo Cai <charpty@gmail.com>
Date: Wed Jul 26 21:49:42 2017 +0800
redis-cli.c typo: conut -> count.
Signed-off-by: Bo Cai <charpty@gmail.com>
commit b9385b2
Author: JackDrogon <jack.xsuperman@gmail.com>
Date: Fri Jun 30 14:22:31 2017 +0800
Fix some spell problems
commit 20d9230
Author: akosel <aaronjkosel@gmail.com>
Date: Sun Jun 4 19:35:13 2017 -0500
Fix typo
commit b167bfc
Author: Krzysiek Witkowicz <krzysiekwitkowicz@gmail.com>
Date: Mon May 22 21:32:27 2017 +0100
Fix #4008 small typo in comment
commit 2b78ac8
Author: Jake Clarkson <jacobwclarkson@gmail.com>
Date: Wed Apr 26 15:49:50 2017 +0100
Correct typo in tests/unit/hyperloglog.tcl
commit b0f1cdb
Author: Qi Luo <qiluo-msft@users.noreply.github.com>
Date: Wed Apr 19 14:25:18 2017 -0700
Fix typo
commit a90b0f9
Author: charsyam <charsyam@naver.com>
Date: Thu Mar 16 18:19:53 2017 +0900
fix typos
fix typos
fix typos
commit 8430a79
Author: Richard Hart <richardhart92@gmail.com>
Date: Mon Mar 13 22:17:41 2017 -0400
Fixed log message typo in listenToPort.
commit 481a1c2
Author: Vinod Kumar <kumar003vinod@gmail.com>
Date: Sun Jan 15 23:04:51 2017 +0530
src/db.c: Correct "save" -> "safe" typo
commit 586b4d3
Author: wangshaonan <wshn13@gmail.com>
Date: Wed Dec 21 20:28:27 2016 +0800
Fix typo they->the in helloworld.c
commit c1c4b5e
Author: Jenner <hypxm@qq.com>
Date: Mon Dec 19 16:39:46 2016 +0800
typo error
commit 1ee1a3f
Author: tielei <43289893@qq.com>
Date: Mon Jul 18 13:52:25 2016 +0800
fix some comments
commit 11a41fb
Author: Otto Kekäläinen <otto@seravo.fi>
Date: Sun Jul 3 10:23:55 2016 +0100
Fix spelling in documentation and comments
commit 5fb5d82
Author: francischan <f1ancis621@gmail.com>
Date: Tue Jun 28 00:19:33 2016 +0800
Fix outdated comments about redis.c file.
It should now refer to server.c file.
commit 6b254bc
Author: lmatt-bit <lmatt123n@gmail.com>
Date: Thu Apr 21 21:45:58 2016 +0800
Refine the comment of dictRehashMilliseconds func
SLAVECONF->REPLCONF in comment - by andyli029
commit ee9869f
Author: clark.kang <charsyam@naver.com>
Date: Tue Mar 22 11:09:51 2016 +0900
fix typos
commit f7b3b11
Author: Harisankar H <harisankarh@gmail.com>
Date: Wed Mar 9 11:49:42 2016 +0530
Typo correction: "faield" --> "failed"
Typo correction: "faield" --> "failed"
commit 3fd40fc
Author: Itamar Haber <itamar@redislabs.com>
Date: Thu Feb 25 10:31:51 2016 +0200
Fixes a typo in comments
commit 621c160
Author: Prayag Verma <prayag.verma@gmail.com>
Date: Mon Feb 1 12:36:20 2016 +0530
Fix typo in Readme.md
Spelling mistakes -
`eviciton` > `eviction`
`familar` > `familiar`
commit d7d07d6
Author: WonCheol Lee <toctoc21c@gmail.com>
Date: Wed Dec 30 15:11:34 2015 +0900
Typo fixed
commit a4dade7
Author: Felix Bünemann <buenemann@louis.info>
Date: Mon Dec 28 11:02:55 2015 +0100
[ci skip] Improve supervised upstart config docs
This mentions that "expect stop" is required for supervised upstart
to work correctly. See http://upstart.ubuntu.com/cookbook/#expect-stop
for an explanation.
commit d9caba9
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:30:03 2015 +1100
README: Remove trailing whitespace
commit 72d42e5
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:29:32 2015 +1100
README: Fix typo. th => the
commit dd6e957
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:29:20 2015 +1100
README: Fix typo. familar => familiar
commit 3a12b23
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:28:54 2015 +1100
README: Fix typo. eviciton => eviction
commit 2d1d03b
Author: daurnimator <quae@daurnimator.com>
Date: Mon Dec 21 18:21:45 2015 +1100
README: Fix typo. sever => server
commit 3973b06
Author: Itamar Haber <itamar@garantiadata.com>
Date: Sat Dec 19 17:01:20 2015 +0200
Typo fix
commit 4f2e460
Author: Steve Gao <fu@2token.com>
Date: Fri Dec 4 10:22:05 2015 +0800
Update README - fix typos
commit b21667c
Author: binyan <binbin.yan@nokia.com>
Date: Wed Dec 2 22:48:37 2015 +0800
delete redundancy color judge in sdscatcolor
commit 88894c7
Author: binyan <binbin.yan@nokia.com>
Date: Wed Dec 2 22:14:42 2015 +0800
the example output shoule be HelloWorld
commit 2763470
Author: binyan <binbin.yan@nokia.com>
Date: Wed Dec 2 17:41:39 2015 +0800
modify error word keyevente
Signed-off-by: binyan <binbin.yan@nokia.com>
commit 0847b3d
Author: Bruno Martins <bscmartins@gmail.com>
Date: Wed Nov 4 11:37:01 2015 +0000
typo
commit bbb9e9e
Author: dawedawe <dawedawe@gmx.de>
Date: Fri Mar 27 00:46:41 2015 +0100
typo: zimap -> zipmap
commit 5ed297e
Author: Axel Advento <badwolf.bloodseeker.rev@gmail.com>
Date: Tue Mar 3 15:58:29 2015 +0800
Fix 'salve' typos to 'slave'
commit edec9d6
Author: LudwikJaniuk <ludvig.janiuk@gmail.com>
Date: Wed Jun 12 14:12:47 2019 +0200
Update README.md
Co-Authored-By: Qix <Qix-@users.noreply.github.com>
commit 692a7af
Author: LudwikJaniuk <ludvig.janiuk@gmail.com>
Date: Tue May 28 14:32:04 2019 +0200
grammar
commit d962b0a
Author: Nick Frost <nickfrostatx@gmail.com>
Date: Wed Jul 20 15:17:12 2016 -0700
Minor grammar fix
commit 24fff01aaccaf5956973ada8c50ceb1462e211c6 (typos)
Author: Chad Miller <chadm@squareup.com>
Date: Tue Sep 8 13:46:11 2020 -0400
Fix faulty comment about operation of unlink()
commit 3cd5c1f3326c52aa552ada7ec797c6bb16452355
Author: Kevin <kevin.xgr@gmail.com>
Date: Wed Nov 20 00:13:50 2019 +0800
Fix typo in server.c.
From a83af59 Mon Sep 17 00:00:00 2001
From: wuwo <wuwo@wacai.com>
Date: Fri, 17 Mar 2017 20:37:45 +0800
Subject: [PATCH] falure to failure
From c961896 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B7=A6=E6=87=B6?= <veficos@gmail.com>
Date: Sat, 27 May 2017 15:33:04 +0800
Subject: [PATCH] fix typo
From e600ef2 Mon Sep 17 00:00:00 2001
From: "rui.zou" <rui.zou@yunify.com>
Date: Sat, 30 Sep 2017 12:38:15 +0800
Subject: [PATCH] fix a typo
From c7d07fa Mon Sep 17 00:00:00 2001
From: Alexandre Perrin <alex@kaworu.ch>
Date: Thu, 16 Aug 2018 10:35:31 +0200
Subject: [PATCH] deps README.md typo
From b25cb67 Mon Sep 17 00:00:00 2001
From: Guy Korland <gkorland@gmail.com>
Date: Wed, 26 Sep 2018 10:55:37 +0300
Subject: [PATCH 1/2] fix typos in header
From ad28ca6 Mon Sep 17 00:00:00 2001
From: Guy Korland <gkorland@gmail.com>
Date: Wed, 26 Sep 2018 11:02:36 +0300
Subject: [PATCH 2/2] fix typos
commit 34924cdedd8552466fc22c1168d49236cb7ee915
Author: Adrian Lynch <adi_ady_ade@hotmail.com>
Date: Sat Apr 4 21:59:15 2015 +0100
Typos fixed
commit fd2a1e7
Author: Jan <jsteemann@users.noreply.github.com>
Date: Sat Oct 27 19:13:01 2018 +0200
Fix typos
Fix typos
commit e14e47c1a234b53b0e103c5f6a1c61481cbcbb02
Author: Andy Lester <andy@petdance.com>
Date: Fri Aug 2 22:30:07 2019 -0500
Fix multiple misspellings of "following"
commit 79b948ce2dac6b453fe80995abbcaac04c213d5a
Author: Andy Lester <andy@petdance.com>
Date: Fri Aug 2 22:24:28 2019 -0500
Fix misspelling of create-cluster
commit 1fffde52666dc99ab35efbd31071a4c008cb5a71
Author: Andy Lester <andy@petdance.com>
Date: Wed Jul 31 17:57:56 2019 -0500
Fix typos
commit 204c9ba9651e9e05fd73936b452b9a30be456cfe
Author: Xiaobo Zhu <xiaobo.zhu@shopee.com>
Date: Tue Aug 13 22:19:25 2019 +0800
fix typos
Squashed commit of the following:
commit 1d9aaf8
Author: danmedani <danmedani@gmail.com>
Date: Sun Aug 2 11:40:26 2015 -0700
README typo fix.
Squashed commit of the following:
commit 32bfa7c
Author: Erik Dubbelboer <erik@dubbelboer.com>
Date: Mon Jul 6 21:15:08 2015 +0200
Fixed grammer
Squashed commit of the following:
commit b24f69c
Author: Sisir Koppaka <sisir.koppaka@gmail.com>
Date: Mon Mar 2 22:38:45 2015 -0500
utils/hashtable/rehashing.c: Fix typos
Squashed commit of the following:
commit 4e04082
Author: Erik Dubbelboer <erik@dubbelboer.com>
Date: Mon Mar 23 08:22:21 2015 +0000
Small config file documentation improvements
Squashed commit of the following:
commit acb8773
Author: ctd1500 <ctd1500@gmail.com>
Date: Fri May 8 01:52:48 2015 -0700
Typo and grammar fixes in readme
commit 2eb75b6
Author: ctd1500 <ctd1500@gmail.com>
Date: Fri May 8 01:36:18 2015 -0700
fixed redis.conf comment
Squashed commit of the following:
commit a8249a2
Author: Masahiko Sawada <sawada.mshk@gmail.com>
Date: Fri Dec 11 11:39:52 2015 +0530
Revise correction of typos.
Squashed commit of the following:
commit 3c02028
Author: zhaojun11 <zhaojun11@jd.com>
Date: Wed Jan 17 19:05:28 2018 +0800
Fix typos include two code typos in cluster.c and latency.c
Squashed commit of the following:
commit 9dba47c
Author: q191201771 <191201771@qq.com>
Date: Sat Jan 4 11:31:04 2020 +0800
fix function listCreate comment in adlist.c
Update src/server.c
commit 2c7c2cb536e78dd211b1ac6f7bda00f0f54faaeb
Author: charpty <charpty@gmail.com>
Date: Tue May 1 23:16:59 2018 +0800
server.c typo: modules system dictionary type comment
Signed-off-by: charpty <charpty@gmail.com>
commit a8395323fb63cb59cb3591cb0f0c8edb7c29a680
Author: Itamar Haber <itamar@redislabs.com>
Date: Sun May 6 00:25:18 2018 +0300
Updates test_helper.tcl's help with undocumented options
Specifically:
* Host
* Port
* Client
commit bde6f9ced15755cd6407b4af7d601b030f36d60b
Author: wxisme <850885154@qq.com>
Date: Wed Aug 8 15:19:19 2018 +0800
fix comments in deps files
commit 3172474ba991532ab799ee1873439f3402412331
Author: wxisme <850885154@qq.com>
Date: Wed Aug 8 14:33:49 2018 +0800
fix some comments
commit 01b6f2b6858b5cf2ce4ad5092d2c746e755f53f0
Author: Thor Juhasz <thor@juhasz.pro>
Date: Sun Nov 18 14:37:41 2018 +0100
Minor fixes to comments
Found some parts a little unclear on a first read, which prompted me to have a better look at the file and fix some minor things I noticed.
Fixing minor typos and grammar. There are no changes to configuration options.
These changes are only meant to help the user better understand the explanations to the various configuration options
2020-09-10 06:43:38 -04:00
|
|
|
* so the actual return value is a heap allocated array of integers. The
|
2014-03-10 10:31:01 -04:00
|
|
|
* length of the array is returned by reference into *numkeys.
|
|
|
|
*
|
|
|
|
* 'cmd' must be point to the corresponding entry into the redisCommand
|
|
|
|
* table, according to the command name in argv[0].
|
2014-03-10 10:24:38 -04:00
|
|
|
*
|
|
|
|
* This function uses the command table if a command-specific helper function
|
|
|
|
* is not required, otherwise it calls the command-specific function. */
|
2020-10-05 10:03:17 -04:00
|
|
|
int getKeysFromCommand(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result) {
|
2016-04-27 12:09:31 -04:00
|
|
|
if (cmd->flags & CMD_MODULE_GETKEYS) {
|
2020-10-05 10:03:17 -04:00
|
|
|
return moduleGetCommandKeysViaAPI(cmd,argv,argc,result);
|
2016-04-27 12:09:31 -04:00
|
|
|
} else if (!(cmd->flags & CMD_MODULE) && cmd->getkeys_proc) {
|
2020-10-05 10:03:17 -04:00
|
|
|
return cmd->getkeys_proc(cmd,argv,argc,result);
|
2011-03-23 13:09:17 -04:00
|
|
|
} else {
|
2020-10-05 10:03:17 -04:00
|
|
|
return getKeysUsingCommandTable(cmd,argv,argc,result);
|
2011-03-23 13:09:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-10 10:24:38 -04:00
|
|
|
/* Free the result of getKeysFromCommand. */
|
2020-10-05 10:03:17 -04:00
|
|
|
void getKeysFreeResult(getKeysResult *result) {
|
|
|
|
if (result && result->keys != result->keysbuf)
|
|
|
|
zfree(result->keys);
|
2011-03-23 13:09:17 -04:00
|
|
|
}
|
|
|
|
|
2014-03-10 10:24:38 -04:00
|
|
|
/* Helper function to extract keys from following commands:
|
2020-09-17 03:54:37 -04:00
|
|
|
* COMMAND [destkey] <num-keys> <key> [...] <key> [...] ... <options>
|
|
|
|
*
|
|
|
|
* eg:
|
|
|
|
* ZUNION <num-keys> <key> <key> ... <key> <options>
|
2014-03-10 10:24:38 -04:00
|
|
|
* ZUNIONSTORE <destkey> <num-keys> <key> <key> ... <key> <options>
|
2020-09-17 03:54:37 -04:00
|
|
|
*
|
|
|
|
* 'storeKeyOfs': destkey index, 0 means destkey not exists.
|
|
|
|
* 'keyCountOfs': num-keys index.
|
|
|
|
* 'firstKeyOfs': firstkey index.
|
|
|
|
* 'keyStep': the interval of each key, usually this value is 1.
|
|
|
|
* */
|
2020-10-05 10:03:17 -04:00
|
|
|
int genericGetKeys(int storeKeyOfs, int keyCountOfs, int firstKeyOfs, int keyStep,
|
|
|
|
robj **argv, int argc, getKeysResult *result) {
|
2011-03-23 13:09:17 -04:00
|
|
|
int i, num, *keys;
|
|
|
|
|
2020-09-17 03:54:37 -04:00
|
|
|
num = atoi(argv[keyCountOfs]->ptr);
|
2011-03-23 13:09:17 -04:00
|
|
|
/* Sanity check. Don't return any key if the command is going to
|
2020-09-17 03:54:37 -04:00
|
|
|
* reply with syntax error. (no input keys). */
|
|
|
|
if (num < 1 || num > (argc - firstKeyOfs)/keyStep) {
|
2020-10-05 10:03:17 -04:00
|
|
|
result->numkeys = 0;
|
|
|
|
return 0;
|
2011-03-23 13:09:17 -04:00
|
|
|
}
|
2014-03-07 16:32:04 -05:00
|
|
|
|
2020-10-05 10:03:17 -04:00
|
|
|
int numkeys = storeKeyOfs ? num + 1 : num;
|
|
|
|
keys = getKeysPrepareResult(result, numkeys);
|
|
|
|
result->numkeys = numkeys;
|
2014-03-07 16:32:04 -05:00
|
|
|
|
2020-09-17 03:54:37 -04:00
|
|
|
/* Add all key positions for argv[firstKeyOfs...n] to keys[] */
|
|
|
|
for (i = 0; i < num; i++) keys[i] = firstKeyOfs+(i*keyStep);
|
2014-03-07 16:32:04 -05:00
|
|
|
|
2020-09-17 03:54:37 -04:00
|
|
|
if (storeKeyOfs) keys[num] = storeKeyOfs;
|
2020-10-05 10:03:17 -04:00
|
|
|
return result->numkeys;
|
2020-09-11 04:59:15 -04:00
|
|
|
}
|
|
|
|
|
2020-11-15 07:14:25 -05:00
|
|
|
int zunionInterDiffStoreGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result) {
|
2020-09-11 04:59:15 -04:00
|
|
|
UNUSED(cmd);
|
2020-10-05 10:03:17 -04:00
|
|
|
return genericGetKeys(1, 2, 3, 1, argv, argc, result);
|
2020-09-17 03:54:37 -04:00
|
|
|
}
|
2020-09-11 04:59:15 -04:00
|
|
|
|
2020-11-15 07:14:25 -05:00
|
|
|
int zunionInterDiffGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result) {
|
2020-09-17 03:54:37 -04:00
|
|
|
UNUSED(cmd);
|
2020-10-05 10:03:17 -04:00
|
|
|
return genericGetKeys(0, 1, 2, 1, argv, argc, result);
|
2011-03-23 13:09:17 -04:00
|
|
|
}
|
2011-04-28 13:00:33 -04:00
|
|
|
|
2020-10-05 10:03:17 -04:00
|
|
|
int evalGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result) {
|
2015-07-27 03:41:48 -04:00
|
|
|
UNUSED(cmd);
|
2020-10-05 10:03:17 -04:00
|
|
|
return genericGetKeys(0, 2, 3, 1, argv, argc, result);
|
2014-03-10 10:26:10 -04:00
|
|
|
}
|
|
|
|
|
2014-03-10 11:26:08 -04:00
|
|
|
/* Helper function to extract keys from the SORT command.
|
|
|
|
*
|
|
|
|
* SORT <sort-key> ... STORE <store-key> ...
|
|
|
|
*
|
|
|
|
* The first argument of SORT is always a key, however a list of options
|
|
|
|
* follow in SQL-alike style. Here we parse just the minimum in order to
|
|
|
|
* correctly identify keys in the "STORE" option. */
|
2020-10-05 10:03:17 -04:00
|
|
|
int sortGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result) {
|
2014-07-21 17:31:21 -04:00
|
|
|
int i, j, num, *keys, found_store = 0;
|
2015-07-27 03:41:48 -04:00
|
|
|
UNUSED(cmd);
|
2014-03-10 11:26:08 -04:00
|
|
|
|
|
|
|
num = 0;
|
2020-10-05 10:03:17 -04:00
|
|
|
keys = getKeysPrepareResult(result, 2); /* Alloc 2 places for the worst case. */
|
2014-03-10 11:26:08 -04:00
|
|
|
keys[num++] = 1; /* <sort-key> is always present. */
|
|
|
|
|
|
|
|
/* Search for STORE option. By default we consider options to don't
|
|
|
|
* have arguments, so if we find an unknown option name we scan the
|
|
|
|
* next. However there are options with 1 or 2 arguments, so we
|
|
|
|
* provide a list here in order to skip the right number of args. */
|
|
|
|
struct {
|
|
|
|
char *name;
|
|
|
|
int skip;
|
|
|
|
} skiplist[] = {
|
|
|
|
{"limit", 2},
|
|
|
|
{"get", 1},
|
|
|
|
{"by", 1},
|
|
|
|
{NULL, 0} /* End of elements. */
|
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 2; i < argc; i++) {
|
|
|
|
for (j = 0; skiplist[j].name != NULL; j++) {
|
|
|
|
if (!strcasecmp(argv[i]->ptr,skiplist[j].name)) {
|
|
|
|
i += skiplist[j].skip;
|
|
|
|
break;
|
|
|
|
} else if (!strcasecmp(argv[i]->ptr,"store") && i+1 < argc) {
|
2014-03-10 11:39:07 -04:00
|
|
|
/* Note: we don't increment "num" here and continue the loop
|
|
|
|
* to be sure to process the *last* "STORE" option if multiple
|
|
|
|
* ones are provided. This is same behavior as SORT. */
|
2014-07-21 17:31:21 -04:00
|
|
|
found_store = 1;
|
2014-03-10 11:39:07 -04:00
|
|
|
keys[num] = i+1; /* <store-key> */
|
2014-03-10 11:26:08 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-05 10:03:17 -04:00
|
|
|
result->numkeys = num + found_store;
|
|
|
|
return result->numkeys;
|
2014-03-10 11:26:08 -04:00
|
|
|
}
|
|
|
|
|
2020-10-05 10:03:17 -04:00
|
|
|
int migrateGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result) {
|
2015-12-11 12:09:01 -05:00
|
|
|
int i, num, first, *keys;
|
|
|
|
UNUSED(cmd);
|
|
|
|
|
|
|
|
/* Assume the obvious form. */
|
|
|
|
first = 3;
|
|
|
|
num = 1;
|
|
|
|
|
|
|
|
/* But check for the extended one with the KEYS option. */
|
|
|
|
if (argc > 6) {
|
|
|
|
for (i = 6; i < argc; i++) {
|
|
|
|
if (!strcasecmp(argv[i]->ptr,"keys") &&
|
|
|
|
sdslen(argv[3]->ptr) == 0)
|
|
|
|
{
|
|
|
|
first = i+1;
|
|
|
|
num = argc-first;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-05 10:03:17 -04:00
|
|
|
keys = getKeysPrepareResult(result, num);
|
2015-12-11 12:09:01 -05:00
|
|
|
for (i = 0; i < num; i++) keys[i] = first+i;
|
2020-10-05 10:03:17 -04:00
|
|
|
result->numkeys = num;
|
|
|
|
return num;
|
2015-12-11 12:09:01 -05:00
|
|
|
}
|
|
|
|
|
2017-04-07 18:31:11 -04:00
|
|
|
/* Helper function to extract keys from following commands:
|
|
|
|
* GEORADIUS key x y radius unit [WITHDIST] [WITHHASH] [WITHCOORD] [ASC|DESC]
|
|
|
|
* [COUNT count] [STORE key] [STOREDIST key]
|
|
|
|
* GEORADIUSBYMEMBER key member radius unit ... options ... */
|
2020-10-05 10:03:17 -04:00
|
|
|
int georadiusGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result) {
|
2017-04-07 18:31:11 -04:00
|
|
|
int i, num, *keys;
|
|
|
|
UNUSED(cmd);
|
|
|
|
|
|
|
|
/* Check for the presence of the stored key in the command */
|
|
|
|
int stored_key = -1;
|
|
|
|
for (i = 5; i < argc; i++) {
|
|
|
|
char *arg = argv[i]->ptr;
|
|
|
|
/* For the case when user specifies both "store" and "storedist" options, the
|
2018-02-11 08:02:07 -05:00
|
|
|
* second key specified would override the first key. This behavior is kept
|
2017-04-07 18:31:11 -04:00
|
|
|
* the same as in georadiusCommand method.
|
|
|
|
*/
|
|
|
|
if ((!strcasecmp(arg, "store") || !strcasecmp(arg, "storedist")) && ((i+1) < argc)) {
|
|
|
|
stored_key = i+1;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
num = 1 + (stored_key == -1 ? 0 : 1);
|
|
|
|
|
|
|
|
/* Keys in the command come from two places:
|
|
|
|
* argv[1] = key,
|
|
|
|
* argv[5...n] = stored key if present
|
|
|
|
*/
|
2020-10-05 10:03:17 -04:00
|
|
|
keys = getKeysPrepareResult(result, num);
|
2017-04-07 18:31:11 -04:00
|
|
|
|
|
|
|
/* Add all key positions to keys[] */
|
|
|
|
keys[0] = 1;
|
|
|
|
if(num > 1) {
|
|
|
|
keys[1] = stored_key;
|
|
|
|
}
|
2020-10-05 10:03:17 -04:00
|
|
|
result->numkeys = num;
|
|
|
|
return num;
|
2017-04-07 18:31:11 -04:00
|
|
|
}
|
|
|
|
|
2020-04-06 07:23:07 -04:00
|
|
|
/* LCS ... [KEYS <key1> <key2>] ... */
|
2020-10-05 10:03:17 -04:00
|
|
|
int lcsGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result) {
|
2020-04-01 10:10:18 -04:00
|
|
|
int i;
|
2020-10-05 10:03:17 -04:00
|
|
|
int *keys = getKeysPrepareResult(result, 2);
|
2020-04-01 10:10:18 -04:00
|
|
|
UNUSED(cmd);
|
|
|
|
|
|
|
|
/* We need to parse the options of the command in order to check for the
|
2020-04-06 07:23:07 -04:00
|
|
|
* "KEYS" argument before the "STRINGS" argument. */
|
2020-04-01 10:10:18 -04:00
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
char *arg = argv[i]->ptr;
|
|
|
|
int moreargs = (argc-1) - i;
|
|
|
|
|
|
|
|
if (!strcasecmp(arg, "strings")) {
|
|
|
|
break;
|
2020-04-06 07:23:07 -04:00
|
|
|
} else if (!strcasecmp(arg, "keys") && moreargs >= 2) {
|
2020-04-01 10:10:18 -04:00
|
|
|
keys[0] = i+1;
|
2020-04-06 07:23:07 -04:00
|
|
|
keys[1] = i+2;
|
2020-10-05 10:03:17 -04:00
|
|
|
result->numkeys = 2;
|
|
|
|
return result->numkeys;
|
2020-04-01 10:10:18 -04:00
|
|
|
}
|
|
|
|
}
|
2020-10-05 10:03:17 -04:00
|
|
|
result->numkeys = 0;
|
|
|
|
return result->numkeys;
|
2020-04-01 10:10:18 -04:00
|
|
|
}
|
|
|
|
|
2020-02-05 02:42:49 -05:00
|
|
|
/* Helper function to extract keys from memory command.
|
|
|
|
* MEMORY USAGE <key> */
|
2020-10-05 10:03:17 -04:00
|
|
|
int memoryGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result) {
|
2020-02-05 02:42:49 -05:00
|
|
|
UNUSED(cmd);
|
|
|
|
|
2020-10-05 10:03:17 -04:00
|
|
|
getKeysPrepareResult(result, 1);
|
2020-02-05 02:42:49 -05:00
|
|
|
if (argc >= 3 && !strcasecmp(argv[1]->ptr,"usage")) {
|
2020-10-05 10:03:17 -04:00
|
|
|
result->keys[0] = 2;
|
|
|
|
result->numkeys = 1;
|
|
|
|
return result->numkeys;
|
2020-02-05 02:42:49 -05:00
|
|
|
}
|
2020-10-05 10:03:17 -04:00
|
|
|
result->numkeys = 0;
|
|
|
|
return 0;
|
2020-02-05 02:42:49 -05:00
|
|
|
}
|
|
|
|
|
2017-09-08 05:40:16 -04:00
|
|
|
/* XREAD [BLOCK <milliseconds>] [COUNT <count>] [GROUP <groupname> <ttl>]
|
2018-06-18 08:06:06 -04:00
|
|
|
* STREAMS key_1 key_2 ... key_N ID_1 ID_2 ... ID_N */
|
2020-10-05 10:03:17 -04:00
|
|
|
int xreadGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result) {
|
2018-06-28 05:22:59 -04:00
|
|
|
int i, num = 0, *keys;
|
2017-09-08 05:40:16 -04:00
|
|
|
UNUSED(cmd);
|
|
|
|
|
2018-06-18 08:06:06 -04:00
|
|
|
/* We need to parse the options of the command in order to seek the first
|
|
|
|
* "STREAMS" string which is actually the option. This is needed because
|
|
|
|
* "STREAMS" could also be the name of the consumer group and even the
|
|
|
|
* name of the stream key. */
|
2017-09-08 05:40:16 -04:00
|
|
|
int streams_pos = -1;
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
char *arg = argv[i]->ptr;
|
2018-06-18 08:06:06 -04:00
|
|
|
if (!strcasecmp(arg, "block")) {
|
|
|
|
i++; /* Skip option argument. */
|
|
|
|
} else if (!strcasecmp(arg, "count")) {
|
|
|
|
i++; /* Skip option argument. */
|
|
|
|
} else if (!strcasecmp(arg, "group")) {
|
|
|
|
i += 2; /* Skip option argument. */
|
|
|
|
} else if (!strcasecmp(arg, "noack")) {
|
|
|
|
/* Nothing to do. */
|
|
|
|
} else if (!strcasecmp(arg, "streams")) {
|
|
|
|
streams_pos = i;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
break; /* Syntax error. */
|
|
|
|
}
|
2017-09-08 05:40:16 -04:00
|
|
|
}
|
2017-09-08 05:51:53 -04:00
|
|
|
if (streams_pos != -1) num = argc - streams_pos - 1;
|
2017-09-08 05:40:16 -04:00
|
|
|
|
|
|
|
/* Syntax error. */
|
2018-04-20 08:19:03 -04:00
|
|
|
if (streams_pos == -1 || num == 0 || num % 2 != 0) {
|
2020-10-05 10:03:17 -04:00
|
|
|
result->numkeys = 0;
|
|
|
|
return 0;
|
2017-09-08 05:40:16 -04:00
|
|
|
}
|
2017-09-08 05:51:53 -04:00
|
|
|
num /= 2; /* We have half the keys as there are arguments because
|
|
|
|
there are also the IDs, one per key. */
|
2017-09-08 05:40:16 -04:00
|
|
|
|
2020-10-05 10:03:17 -04:00
|
|
|
keys = getKeysPrepareResult(result, num);
|
2018-06-18 07:51:19 -04:00
|
|
|
for (i = streams_pos+1; i < argc-num; i++) keys[i-streams_pos-1] = i;
|
2020-10-05 10:03:17 -04:00
|
|
|
result->numkeys = num;
|
|
|
|
return num;
|
2017-09-08 05:40:16 -04:00
|
|
|
}
|
|
|
|
|
2011-04-28 13:00:33 -04:00
|
|
|
/* Slot to Key API. This is used by Redis Cluster in order to obtain in
|
|
|
|
* a fast way a key that belongs to a specified hash slot. This is useful
|
2017-03-27 09:26:56 -04:00
|
|
|
* while rehashing the cluster and in other conditions when we need to
|
|
|
|
* understand if we have keys for a given hash slot. */
|
2020-04-09 04:24:10 -04:00
|
|
|
void slotToKeyUpdateKey(sds key, int add) {
|
|
|
|
size_t keylen = sdslen(key);
|
|
|
|
unsigned int hashslot = keyHashSlot(key,keylen);
|
2017-03-27 09:26:56 -04:00
|
|
|
unsigned char buf[64];
|
|
|
|
unsigned char *indexed = buf;
|
|
|
|
|
|
|
|
server.cluster->slots_keys_count[hashslot] += add ? 1 : -1;
|
|
|
|
if (keylen+2 > 64) indexed = zmalloc(keylen+2);
|
|
|
|
indexed[0] = (hashslot >> 8) & 0xff;
|
|
|
|
indexed[1] = hashslot & 0xff;
|
2020-04-09 04:24:10 -04:00
|
|
|
memcpy(indexed+2,key,keylen);
|
2017-03-27 09:26:56 -04:00
|
|
|
if (add) {
|
2017-04-07 02:46:39 -04:00
|
|
|
raxInsert(server.cluster->slots_to_keys,indexed,keylen+2,NULL,NULL);
|
2017-03-27 09:26:56 -04:00
|
|
|
} else {
|
2017-04-07 02:46:39 -04:00
|
|
|
raxRemove(server.cluster->slots_to_keys,indexed,keylen+2,NULL);
|
2017-03-27 09:26:56 -04:00
|
|
|
}
|
|
|
|
if (indexed != buf) zfree(indexed);
|
|
|
|
}
|
2011-04-28 13:00:33 -04:00
|
|
|
|
2020-04-09 04:24:10 -04:00
|
|
|
void slotToKeyAdd(sds key) {
|
2017-03-27 09:26:56 -04:00
|
|
|
slotToKeyUpdateKey(key,1);
|
2011-04-28 13:00:33 -04:00
|
|
|
}
|
|
|
|
|
2020-04-09 04:24:10 -04:00
|
|
|
void slotToKeyDel(sds key) {
|
2017-03-27 09:26:56 -04:00
|
|
|
slotToKeyUpdateKey(key,0);
|
2011-04-28 13:00:33 -04:00
|
|
|
}
|
|
|
|
|
2020-12-02 06:56:11 -05:00
|
|
|
/* Release the radix tree mapping Redis Cluster keys to slots. If 'async'
|
|
|
|
* is true, we release it asynchronously. */
|
|
|
|
void freeSlotsToKeysMap(rax *rt, int async) {
|
|
|
|
if (async) {
|
|
|
|
freeSlotsToKeysMapAsync(rt);
|
|
|
|
} else {
|
|
|
|
raxFree(rt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Empty the slots-keys map of Redis CLuster by creating a new empty one and
|
|
|
|
* freeing the old one. */
|
|
|
|
void slotToKeyFlush(int async) {
|
|
|
|
rax *old = server.cluster->slots_to_keys;
|
|
|
|
|
2017-03-27 09:26:56 -04:00
|
|
|
server.cluster->slots_to_keys = raxNew();
|
|
|
|
memset(server.cluster->slots_keys_count,0,
|
|
|
|
sizeof(server.cluster->slots_keys_count));
|
2020-12-02 06:56:11 -05:00
|
|
|
freeSlotsToKeysMap(old, async);
|
2013-02-22 04:15:32 -05:00
|
|
|
}
|
|
|
|
|
2020-10-28 02:51:35 -04:00
|
|
|
/* Populate the specified array of objects with keys in the specified slot.
|
2015-08-04 03:20:55 -04:00
|
|
|
* New objects are returned to represent keys, it's up to the caller to
|
|
|
|
* decrement the reference count to release the keys names. */
|
2013-02-25 05:24:42 -05:00
|
|
|
unsigned int getKeysInSlot(unsigned int hashslot, robj **keys, unsigned int count) {
|
2017-03-27 09:26:56 -04:00
|
|
|
raxIterator iter;
|
2011-04-29 10:17:58 -04:00
|
|
|
int j = 0;
|
2017-03-27 09:26:56 -04:00
|
|
|
unsigned char indexed[2];
|
|
|
|
|
|
|
|
indexed[0] = (hashslot >> 8) & 0xff;
|
|
|
|
indexed[1] = hashslot & 0xff;
|
|
|
|
raxStart(&iter,server.cluster->slots_to_keys);
|
2017-04-07 02:46:39 -04:00
|
|
|
raxSeek(&iter,">=",indexed,2);
|
|
|
|
while(count-- && raxNext(&iter)) {
|
2017-03-27 09:26:56 -04:00
|
|
|
if (iter.key[0] != indexed[0] || iter.key[1] != indexed[1]) break;
|
|
|
|
keys[j++] = createStringObject((char*)iter.key+2,iter.key_len-2);
|
2011-04-29 10:17:58 -04:00
|
|
|
}
|
2017-03-27 09:26:56 -04:00
|
|
|
raxStop(&iter);
|
2011-04-29 10:17:58 -04:00
|
|
|
return j;
|
2011-04-28 13:00:33 -04:00
|
|
|
}
|
2013-02-25 05:15:03 -05:00
|
|
|
|
2014-05-14 04:46:37 -04:00
|
|
|
/* Remove all the keys in the specified hash slot.
|
|
|
|
* The number of removed items is returned. */
|
|
|
|
unsigned int delKeysInSlot(unsigned int hashslot) {
|
2017-03-27 09:26:56 -04:00
|
|
|
raxIterator iter;
|
2014-05-14 04:46:37 -04:00
|
|
|
int j = 0;
|
2017-03-27 09:26:56 -04:00
|
|
|
unsigned char indexed[2];
|
2014-05-14 04:46:37 -04:00
|
|
|
|
2017-03-27 09:26:56 -04:00
|
|
|
indexed[0] = (hashslot >> 8) & 0xff;
|
|
|
|
indexed[1] = hashslot & 0xff;
|
|
|
|
raxStart(&iter,server.cluster->slots_to_keys);
|
|
|
|
while(server.cluster->slots_keys_count[hashslot]) {
|
2017-04-07 02:46:39 -04:00
|
|
|
raxSeek(&iter,">=",indexed,2);
|
|
|
|
raxNext(&iter);
|
2014-05-14 04:46:37 -04:00
|
|
|
|
2017-03-27 09:26:56 -04:00
|
|
|
robj *key = createStringObject((char*)iter.key+2,iter.key_len-2);
|
2014-05-14 04:46:37 -04:00
|
|
|
dbDelete(&server.db[0],key);
|
|
|
|
decrRefCount(key);
|
|
|
|
j++;
|
|
|
|
}
|
2017-03-27 09:26:56 -04:00
|
|
|
raxStop(&iter);
|
2014-05-14 04:46:37 -04:00
|
|
|
return j;
|
|
|
|
}
|
|
|
|
|
2013-02-25 05:24:42 -05:00
|
|
|
unsigned int countKeysInSlot(unsigned int hashslot) {
|
2017-03-27 09:26:56 -04:00
|
|
|
return server.cluster->slots_keys_count[hashslot];
|
2013-02-25 05:15:03 -05:00
|
|
|
}
|