You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/develop/connect/cli.md
+15-17Lines changed: 15 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -144,7 +144,7 @@ If the target server requires authentication using a client side certificate,
144
144
you can specify a certificate and a corresponding private key using `--cert` and
145
145
`--key`.
146
146
147
-
## Getting input from other programs
147
+
## Get input from other programs
148
148
149
149
There are two ways you can use `redis-cli` in order to receive input from other
150
150
commands via the standard input. One is to use the target payload as the last argument
@@ -235,7 +235,7 @@ A CSV (Comma Separated Values) output feature exists within `redis-cli` to expor
235
235
236
236
Note that the `--csv` flag will only work on a single command, not the entirety of a DB as an export.
237
237
238
-
## Running Lua scripts
238
+
## Run Lua scripts
239
239
240
240
The `redis-cli` has extensive support for using the debugging facility
241
241
of Lua scripting, available with Redis 3.2 onwards. For this feature, refer to the [Redis Lua debugger documentation]({{< relref "/develop/interact/programmability/lua-debugging" >}}).
@@ -261,8 +261,7 @@ So `location:hastings:temp` will populate the [`KEYS`]({{< relref "/commands/key
261
261
The `--eval` option is useful when writing simple scripts. For more
262
262
complex work, the Lua debugger is recommended. It is possible to mix the two approaches, since the debugger can also execute scripts from an external file.
263
263
264
-
Interactive mode
265
-
===
264
+
## Interactive mode
266
265
267
266
We have explored how to use the Redis CLI as a command line program.
268
267
This is useful for scripts and certain types of testing, however most
@@ -293,7 +292,7 @@ The prompt updates as the connected server changes or when operating on a databa
293
292
127.0.0.1:6379> DBSIZE
294
293
(integer) 503
295
294
296
-
##Handling connections and reconnections
295
+
### Handle connections and reconnections
297
296
298
297
Using the `CONNECT` command in interactive mode makes it possible to connect
299
298
to a different instance, by specifying the *hostname* and *port* we want
@@ -346,7 +345,7 @@ testing, but this limitation should be known.
346
345
347
346
Use the `-t <timeout>` option to specify server timeout in seconds.
348
347
349
-
## Editing, history, completion and hints
348
+
###Editing, history, completion and hints
350
349
351
350
Because `redis-cli` uses the
352
351
[linenoise line editing library](http://github.com/antirez/linenoise), it
@@ -372,7 +371,7 @@ syntax hints. Like command history, this behavior can be turned on and off via t
372
371
373
372
Reverse history searches, such as `CTRL-R` in terminals, is supported.
374
373
375
-
## Preferences
374
+
###Preferences
376
375
377
376
There are two ways to customize `redis-cli` behavior. The file `.redisclirc`
378
377
in the home directory is loaded by the CLI on startup. You can override the
@@ -387,7 +386,7 @@ can be set, either by typing the command in the CLI or adding it to the
387
386
*`:set hints` - enables syntax hints
388
387
*`:set nohints` - disables syntax hints
389
388
390
-
##Running the same command N times
389
+
### Run the same command N times
391
390
392
391
It is possible to run the same command multiple times in interactive mode by prefixing the command
393
392
name by a number:
@@ -399,7 +398,7 @@ name by a number:
399
398
(integer) 4
400
399
(integer) 5
401
400
402
-
##Showing help about Redis commands
401
+
### Show online help for Redis commands
403
402
404
403
`redis-cli` provides online help for most Redis [commands]({{< relref "/commands" >}}), using the `HELP` command. The command can be used
405
404
in two forms:
@@ -433,12 +432,11 @@ For example in order to show help for the [`PFADD`]({{< relref "/commands/pfadd"
433
432
434
433
Note that `HELP` supports TAB completion as well.
435
434
436
-
##Clearing the terminal screen
435
+
### Clear the terminal screen
437
436
438
437
Using the `CLEAR` command in interactive mode clears the terminal's screen.
439
438
440
-
Special modes of operation
441
-
===
439
+
## Special modes of operation
442
440
443
441
So far we saw two main modes of `redis-cli`.
444
442
@@ -460,7 +458,7 @@ are explained in the next sections:
460
458
* Simulating [LRU]({{< relref "/develop/reference/eviction" >}}) workloads for showing stats about keys hits.
461
459
* A client for the Lua debugger.
462
460
463
-
## Continuous stats mode
461
+
###Continuous stats mode
464
462
465
463
Continuous stats mode is probably one of the lesser known yet very useful features of `redis-cli` to monitor Redis instances in real time. To enable this mode, the `--stat` option is used.
466
464
The output is very clear about the behavior of the CLI in this mode:
@@ -547,7 +545,7 @@ The `--memkeys` option now works on cluster replicas.
547
545
548
546
You can use the `--keystats` and `--keystats-samples` options to combine `--memkeys` and `--bigkeys` with additional distribution data.
549
547
550
-
## Getting a list of keys
548
+
## Get a list of keys
551
549
552
550
It is also possible to scan the key space, again in a way that does not
553
551
block the Redis server (which does happen when you use a command
@@ -624,7 +622,7 @@ When another client publishes some message in some channel, such as with the com
624
622
This is very useful for debugging Pub/Sub issues.
625
623
To exit the Pub/Sub mode just process `CTRL-C`.
626
624
627
-
## Monitoring commands executed in Redis
625
+
## Monitor commands executed in Redis
628
626
629
627
Similarly to the Pub/Sub mode, the monitoring mode is entered automatically
630
628
once you use the [`MONITOR`]({{< relref "/commands/monitor" >}}) command. All commands received by the active Redis instance will be printed to the standard output:
@@ -637,7 +635,7 @@ once you use the [`MONITOR`]({{< relref "/commands/monitor" >}}) command. All co
637
635
Note that it is possible to pipe the output, so you can monitor
638
636
for specific patterns using tools such as `grep`.
639
637
640
-
## Monitoring the latency of Redis instances
638
+
## Monitor the latency of Redis instances
641
639
642
640
Redis is often used in contexts where latency is very critical. Latency
643
641
involves multiple moving parts within the application, from the client library
@@ -765,7 +763,7 @@ If you think some of the commands are not replicated correctly in your replicas
765
763
this is a good way to check what's happening, and also useful information
766
764
in order to improve the bug report.
767
765
768
-
## Performing an LRU simulation
766
+
## Perform an LRU simulation
769
767
770
768
Redis is often used as a cache with [LRU eviction]({{< relref "/develop/reference/eviction" >}}).
771
769
Depending on the number of keys and the amount of memory allocated for the
*`mem_usage` is called when the [`MEMORY`]({{< relref "/commands/memory" >}}) command asks for the total memory consumed by a specific key, and is used in order to get the amount of bytes used by the module value.
135
131
*`free` is called when a key with the module native type is deleted via [`DEL`]({{< relref "/commands/del" >}}) or in any other mean, in order to let the module reclaim the memory associated with such a value.
136
132
137
-
Ok, but *why* modules types require a 9 characters name?
138
-
---
139
-
140
-
Oh, I understand you need to understand this, so here is a very specific
141
-
explanation.
133
+
### Why module types require nine character names
142
134
143
135
When Redis persists to RDB files, modules specific data types require to
144
136
be persisted as well. Now RDB files are sequences of key-value pairs
@@ -186,8 +178,7 @@ we can convert back the 64 bit value into a 9 characters name, and print
186
178
an error to the user that includes the module type name! So that she or he
187
179
immediately realizes what's wrong.
188
180
189
-
Setting and getting keys
190
-
---
181
+
### Set and get keys
191
182
192
183
After registering our new data type in the `RedisModule_OnLoad()` function,
193
184
we also need to be able to set Redis keys having as value our native type.
@@ -254,8 +245,7 @@ key if there is already one:
254
245
}
255
246
/* Do something with 'data'... */
256
247
257
-
Free method
258
-
---
248
+
### Free method
259
249
260
250
As already mentioned, when Redis needs to free a key holding a native type
261
251
value, it needs help from the module in order to release the memory. This
@@ -274,8 +264,7 @@ However a more real world one will call some function that performs a more
274
264
complex memory reclaiming, by casting the void pointer to some structure
275
265
and freeing all the resources composing the value.
276
266
277
-
RDB load and save methods
278
-
---
267
+
### RDB load and save methods
279
268
280
269
The RDB saving and loading callbacks need to create (and load back) a
281
270
representation of the data type on disk. Redis offers a high level API
@@ -352,18 +341,11 @@ Note that while there is no error handling on the API that writes and reads
352
341
from disk, still the load callback can return NULL on errors in case what
353
342
it reads does not look correct. Redis will just panic in that case.
Modules data types should try to use `RedisModule_Alloc()` functions family
369
351
in order to allocate, reallocate and release heap memory used to implement the native data structures (see the other Redis Modules documentation for detailed information).
Copy file name to clipboardExpand all lines: content/develop/reference/sentinel-clients.md
+11-22Lines changed: 11 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -46,17 +46,15 @@ A Redis client supporting Sentinel can automatically discover the address of a R
46
46
47
47
This is the procedure a client should follow in order to obtain the master address starting from the list of Sentinels and the service name.
48
48
49
-
Step 1: connecting to the first Sentinel
50
-
---
49
+
### Step 1: connect to the first Sentinel
51
50
52
51
The client should iterate the list of Sentinel addresses. For every address it should try to connect to the Sentinel, using a short timeout (in the order of a few hundreds of milliseconds). On errors or timeouts the next Sentinel address should be tried.
53
52
54
53
If all the Sentinel addresses were tried without success, an error should be returned to the client.
55
54
56
55
The first Sentinel replying to the client request should be put at the start of the list, so that at the next reconnection, we'll try first the Sentinel that was reachable in the previous connection attempt, minimizing latency.
57
56
58
-
Step 2: ask for master address
59
-
---
57
+
### Step 2: ask for the master address
60
58
61
59
Once a connection with a Sentinel is established, the client should retry to execute the following command on the Sentinel:
62
60
@@ -71,8 +69,7 @@ The result from this call can be one of the following two replies:
71
69
72
70
If an ip:port pair is received, this address should be used to connect to the Redis master. Otherwise if a null reply is received, the client should try the next Sentinel in the list.
73
71
74
-
Step 3: call the ROLE command in the target instance
75
-
---
72
+
### Step 3: call the ROLE command in the target instance
76
73
77
74
Once the client discovered the address of the master instance, it should
78
75
attempt a connection with the master, and call the [`ROLE`]({{< relref "/commands/role" >}}) command in order
@@ -82,8 +79,7 @@ If the [`ROLE`]({{< relref "/commands/role" >}}) commands is not available (it w
82
79
83
80
If the instance is not a master as expected, the client should wait a short amount of time (a few hundreds of milliseconds) and should try again starting from Step 1.
84
81
85
-
Handling reconnections
86
-
===
82
+
## Handle reconnections
87
83
88
84
Once the service name is resolved into the master address and a connection is established with the Redis master instance, every time a reconnection is needed, the client should resolve again the address using Sentinels restarting from Step 1. For instance Sentinel should contacted again the following cases:
89
85
@@ -92,8 +88,7 @@ Once the service name is resolved into the master address and a connection is es
92
88
93
89
In the above cases and any other case where the client lost the connection with the Redis server, the client should resolve the master address again.
94
90
95
-
Sentinel failover disconnection
96
-
===
91
+
## Sentinel failover disconnection
97
92
98
93
Starting with Redis 2.8.12, when Redis Sentinel changes the configuration of
99
94
an instance, for example promoting a replica to a master, demoting a master to
@@ -107,8 +102,7 @@ If the client will contact a Sentinel with yet not updated information, the veri
107
102
108
103
Note: it is possible that a stale master returns online at the same time a client contacts a stale Sentinel instance, so the client may connect with a stale master, and yet the ROLE output will match. However when the master is back again Sentinel will try to demote it to replica, triggering a new disconnection. The same reasoning applies to connecting to stale replicas that will get reconfigured to replicate with a different master.
109
104
110
-
Connecting to replicas
111
-
===
105
+
## Connect to replicas
112
106
113
107
Sometimes clients are interested to connect to replicas, for example in order to scale read requests. This protocol supports connecting to replicas by modifying step 2 slightly. Instead of calling the following command:
114
108
@@ -124,21 +118,18 @@ Symmetrically the client should verify with the [`ROLE`]({{< relref "/commands/r
124
118
instance is actually a replica, in order to avoid scaling read queries with
125
119
the master.
126
120
127
-
Connection pools
128
-
===
121
+
## Connection pools
129
122
130
123
For clients implementing connection pools, on reconnection of a single connection, the Sentinel should be contacted again, and in case of a master address change all the existing connections should be closed and connected to the new address.
131
124
132
-
Error reporting
133
-
===
125
+
## Error reporting
134
126
135
127
The client should correctly return the information to the user in case of errors. Specifically:
136
128
137
129
* If no Sentinel can be contacted (so that the client was never able to get the reply to `SENTINEL get-master-addr-by-name`), an error that clearly states that Redis Sentinel is unreachable should be returned.
138
130
* If all the Sentinels in the pool replied with a null reply, the user should be informed with an error that Sentinels don't know this master name.
139
131
140
-
Sentinels list automatic refresh
141
-
===
132
+
## Sentinels list automatic refresh
142
133
143
134
Optionally once a successful reply to `get-master-addr-by-name` is received, a client may update its internal list of Sentinel nodes following this procedure:
144
135
@@ -147,8 +138,7 @@ Optionally once a successful reply to `get-master-addr-by-name` is received, a c
147
138
148
139
It is not needed for a client to be able to make the list persistent updating its own configuration. The ability to upgrade the in-memory representation of the list of Sentinels can be already useful to improve reliability.
149
140
150
-
Subscribe to Sentinel events to improve responsiveness
151
-
===
141
+
## Subscribe to Sentinel events to improve responsiveness
152
142
153
143
The [Sentinel documentation]({{< relref "/operate/oss_and_stack/management/sentinel" >}}) shows how clients can connect to
154
144
Sentinel instances using Pub/Sub in order to subscribe to changes in the
@@ -163,7 +153,6 @@ However update messages received via Pub/Sub should not substitute the
163
153
above procedure, since there is no guarantee that a client is able to
164
154
receive all the update messages.
165
155
166
-
Additional information
167
-
===
156
+
## Additional information
168
157
169
158
For additional information or to discuss specific aspects of this guidelines, please drop a message to the [Redis Google Group](https://groups.google.com/group/redis-db).
0 commit comments