<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://briansnelson.com/index.php?action=history&amp;feed=atom&amp;title=Basic_Redis_commands_-_Cheat_Sheet</id>
		<title>Basic Redis commands - Cheat Sheet - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://briansnelson.com/index.php?action=history&amp;feed=atom&amp;title=Basic_Redis_commands_-_Cheat_Sheet"/>
		<link rel="alternate" type="text/html" href="https://briansnelson.com/index.php?title=Basic_Redis_commands_-_Cheat_Sheet&amp;action=history"/>
		<updated>2026-06-04T09:59:01Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.24.1</generator>

	<entry>
		<id>https://briansnelson.com/index.php?title=Basic_Redis_commands_-_Cheat_Sheet&amp;diff=751&amp;oldid=prev</id>
		<title>Brian at 17:59, 17 June 2014</title>
		<link rel="alternate" type="text/html" href="https://briansnelson.com/index.php?title=Basic_Redis_commands_-_Cheat_Sheet&amp;diff=751&amp;oldid=prev"/>
				<updated>2014-06-17T17:59:11Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 17:59, 17 June 2014&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Basic Redis commands - Cheat Sheet==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Basic Redis commands - Cheat Sheet==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;When you encounter a Redis instance and you quickly want to learn about the setup you just need a few simple commands to peak into the setup. Of course it doesn't hurt to look at the official [http://redis.io/commands full command documentatio]n, but below is a listing just for sysadmins.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;[[File:Img-redis.jpg|frameless|right|Basic Redis commands - Cheat Sheet]]&lt;/ins&gt;When you encounter a Redis instance and you quickly want to learn about the setup you just need a few simple commands to peak into the setup. Of course it doesn't hurt to look at the official [http://redis.io/commands full command documentatio]n, but below is a listing just for sysadmins.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;===Accessing Redis===&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;===Accessing Redis===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key briansne_wiki-wiki_:diff:version:1.11a:oldid:750:newid:751 --&gt;
&lt;/table&gt;</summary>
		<author><name>Brian</name></author>	</entry>

	<entry>
		<id>https://briansnelson.com/index.php?title=Basic_Redis_commands_-_Cheat_Sheet&amp;diff=750&amp;oldid=prev</id>
		<title>Brian: Created page with &quot;==Basic Redis commands - Cheat Sheet==  When you encounter a Redis instance and you quickly want to learn about the setup you just need a few simple commands to peak into the ...&quot;</title>
		<link rel="alternate" type="text/html" href="https://briansnelson.com/index.php?title=Basic_Redis_commands_-_Cheat_Sheet&amp;diff=750&amp;oldid=prev"/>
				<updated>2014-06-17T17:57:02Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Basic Redis commands - Cheat Sheet==  When you encounter a Redis instance and you quickly want to learn about the setup you just need a few simple commands to peak into the ...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Basic Redis commands - Cheat Sheet==&lt;br /&gt;
&lt;br /&gt;
When you encounter a Redis instance and you quickly want to learn about the setup you just need a few simple commands to peak into the setup. Of course it doesn't hurt to look at the official [http://redis.io/commands full command documentatio]n, but below is a listing just for sysadmins.&lt;br /&gt;
&lt;br /&gt;
===Accessing Redis===&lt;br /&gt;
&lt;br /&gt;
First thing to know is that you can use &amp;quot;telnet&amp;quot; (usually on default port 6397)&lt;br /&gt;
&lt;br /&gt;
 telnet localhost 6397&lt;br /&gt;
or the Redis CLI client&lt;br /&gt;
&lt;br /&gt;
 redis-cli&lt;br /&gt;
&lt;br /&gt;
to connect to Redis. The advantage of redis-cli is that you have a help interface and command line history.&lt;br /&gt;
&lt;br /&gt;
===Scripting Redis Commands===&lt;br /&gt;
&lt;br /&gt;
For scripting just pass commands to &amp;quot;redis-cli&amp;quot;. For example:&lt;br /&gt;
&lt;br /&gt;
 $ redis-cli INFO | grep connected&lt;br /&gt;
 connected_clients:2&lt;br /&gt;
 connected_slaves:0&lt;br /&gt;
 $&lt;br /&gt;
===Server Statistics===&lt;br /&gt;
&lt;br /&gt;
The statistics command is &amp;quot;INFO&amp;quot; and will give you an output as following:&lt;br /&gt;
&lt;br /&gt;
 $ redis-cli INFO&lt;br /&gt;
 redis_version:2.2.12&lt;br /&gt;
 redis_git_sha1:00000000&lt;br /&gt;
 redis_git_dirty:0&lt;br /&gt;
 arch_bits:64&lt;br /&gt;
 multiplexing_api:epoll&lt;br /&gt;
 process_id:8353&lt;br /&gt;
 uptime_in_seconds:2592232&lt;br /&gt;
 uptime_in_days:30&lt;br /&gt;
 lru_clock:809325&lt;br /&gt;
 used_cpu_sys:199.20&lt;br /&gt;
 used_cpu_user:309.26&lt;br /&gt;
 used_cpu_sys_children:12.04&lt;br /&gt;
 used_cpu_user_children:1.47&lt;br /&gt;
 connected_clients:2&lt;br /&gt;
 connected_slaves:0&lt;br /&gt;
 client_longest_output_list:0&lt;br /&gt;
 client_biggest_input_buf:0&lt;br /&gt;
 blocked_clients:0&lt;br /&gt;
 used_memory:6596112&lt;br /&gt;
 used_memory_human:6.29M&lt;br /&gt;
 used_memory_rss:17571840&lt;br /&gt;
 mem_fragmentation_ratio:2.66&lt;br /&gt;
 use_tcmalloc:0&lt;br /&gt;
 loading:0&lt;br /&gt;
 aof_enabled:0&lt;br /&gt;
 changes_since_last_save:0&lt;br /&gt;
 bgsave_in_progress:0&lt;br /&gt;
 last_save_time:1371241671&lt;br /&gt;
 bgrewriteaof_in_progress:0&lt;br /&gt;
 total_connections_received:118&lt;br /&gt;
 total_commands_processed:1091&lt;br /&gt;
 expired_keys:441&lt;br /&gt;
 evicted_keys:0&lt;br /&gt;
 keyspace_hits:6&lt;br /&gt;
 keyspace_misses:1070&lt;br /&gt;
 hash_max_zipmap_entries:512&lt;br /&gt;
 hash_max_zipmap_value:64&lt;br /&gt;
 pubsub_channels:0&lt;br /&gt;
 pubsub_patterns:0&lt;br /&gt;
 vm_enabled:0&lt;br /&gt;
 role:master&lt;br /&gt;
 db0:keys=91,expires=88&lt;br /&gt;
&lt;br /&gt;
===Changing Runtime Configuration===&lt;br /&gt;
&lt;br /&gt;
The command&lt;br /&gt;
&lt;br /&gt;
 CONFIG GET *&lt;br /&gt;
&lt;br /&gt;
gives you a list of all active configuration variables you can change. The output might look like this:&lt;br /&gt;
&lt;br /&gt;
 redis 127.0.0.1:6379&amp;gt; CONFIG GET *&lt;br /&gt;
  1) &amp;quot;dir&amp;quot;&lt;br /&gt;
  2) &amp;quot;/var/lib/redis&amp;quot;&lt;br /&gt;
  3) &amp;quot;dbfilename&amp;quot;&lt;br /&gt;
  4) &amp;quot;dump.rdb&amp;quot;&lt;br /&gt;
  5) &amp;quot;requirepass&amp;quot;&lt;br /&gt;
  6) (nil)&lt;br /&gt;
  7) &amp;quot;masterauth&amp;quot;&lt;br /&gt;
  8) (nil)&lt;br /&gt;
  9) &amp;quot;maxmemory&amp;quot;&lt;br /&gt;
 10) &amp;quot;0&amp;quot;&lt;br /&gt;
 11) &amp;quot;maxmemory-policy&amp;quot;&lt;br /&gt;
 12) &amp;quot;volatile-lru&amp;quot;&lt;br /&gt;
 13) &amp;quot;maxmemory-samples&amp;quot;&lt;br /&gt;
 14) &amp;quot;3&amp;quot;&lt;br /&gt;
 15) &amp;quot;timeout&amp;quot;&lt;br /&gt;
 16) &amp;quot;300&amp;quot;&lt;br /&gt;
 17) &amp;quot;appendonly&amp;quot;&lt;br /&gt;
 18) &amp;quot;no&amp;quot;&lt;br /&gt;
 19) &amp;quot;no-appendfsync-on-rewrite&amp;quot;&lt;br /&gt;
 20) &amp;quot;no&amp;quot;&lt;br /&gt;
 21) &amp;quot;appendfsync&amp;quot;&lt;br /&gt;
 22) &amp;quot;everysec&amp;quot;&lt;br /&gt;
 23) &amp;quot;save&amp;quot;&lt;br /&gt;
 24) &amp;quot;900 1 300 10 60 10000&amp;quot;&lt;br /&gt;
 25) &amp;quot;slave-serve-stale-data&amp;quot;&lt;br /&gt;
 26) &amp;quot;yes&amp;quot;&lt;br /&gt;
 27) &amp;quot;hash-max-zipmap-entries&amp;quot;&lt;br /&gt;
 28) &amp;quot;512&amp;quot;&lt;br /&gt;
 29) &amp;quot;hash-max-zipmap-value&amp;quot;&lt;br /&gt;
 30) &amp;quot;64&amp;quot;&lt;br /&gt;
 31) &amp;quot;list-max-ziplist-entries&amp;quot;&lt;br /&gt;
 32) &amp;quot;512&amp;quot;&lt;br /&gt;
 33) &amp;quot;list-max-ziplist-value&amp;quot;&lt;br /&gt;
 34) &amp;quot;64&amp;quot;&lt;br /&gt;
 35) &amp;quot;set-max-intset-entries&amp;quot;&lt;br /&gt;
 36) &amp;quot;512&amp;quot;&lt;br /&gt;
 37) &amp;quot;slowlog-log-slower-than&amp;quot;&lt;br /&gt;
 38) &amp;quot;10000&amp;quot;&lt;br /&gt;
 39) &amp;quot;slowlog-max-len&amp;quot;&lt;br /&gt;
 40) &amp;quot;64&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Note that keys and values are alternating and you can change each key by issuing a &amp;quot;CONFIG SET&amp;quot; command like:&lt;br /&gt;
&lt;br /&gt;
 CONFIG SET timeout 900&lt;br /&gt;
&lt;br /&gt;
Such a change will be effective instantly. When changing values consider also updating the redis configuration file.&lt;br /&gt;
&lt;br /&gt;
===Multiple Databases===&lt;br /&gt;
&lt;br /&gt;
Redis has a concept of separated namespaces called &amp;quot;databases&amp;quot;. You can select the database number you want to use with &amp;quot;SELECT&amp;quot;. By default the database with index 0 is used. So issuing&lt;br /&gt;
&lt;br /&gt;
 redis 127.0.0.1:6379&amp;gt; SELECT 1&lt;br /&gt;
 OK&lt;br /&gt;
 redis 127.0.0.1:6379[1]&amp;gt;&lt;br /&gt;
&lt;br /&gt;
switches to the second database. Note how the prompt changed and now has a &amp;quot;[1]&amp;quot; to indicate the database selection.&lt;br /&gt;
&lt;br /&gt;
To find out how many databases there are you might want to run redis-cli from the shell:&lt;br /&gt;
&lt;br /&gt;
 $ redis-cli INFO | grep ^db&lt;br /&gt;
 db0:keys=91,expires=88&lt;br /&gt;
 db1:keys=1,expires=0&lt;br /&gt;
&lt;br /&gt;
===Dropping Databases===&lt;br /&gt;
&lt;br /&gt;
To drop the currently selected database run&lt;br /&gt;
&lt;br /&gt;
 FLUSHDB&lt;br /&gt;
to drop all databases at once run&lt;br /&gt;
&lt;br /&gt;
 FLUSHALL&lt;br /&gt;
&lt;br /&gt;
===Checking for Replication===&lt;br /&gt;
&lt;br /&gt;
To see if the instance is a replication slave or master issue&lt;br /&gt;
&lt;br /&gt;
 redis 127.0.0.1:6379&amp;gt; INFO&lt;br /&gt;
 [...]&lt;br /&gt;
 role:master&lt;br /&gt;
&lt;br /&gt;
and watch for the &amp;quot;role&amp;quot; line which shows either &amp;quot;master&amp;quot; or &amp;quot;slave&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Starting with version 2.8 the &amp;quot;INFO&amp;quot; command also gives you per slave replication status looking like this&lt;br /&gt;
&lt;br /&gt;
 slave0:ip=127.0.0.1,port=6380,state=online,offset=281,lag=0&lt;br /&gt;
&lt;br /&gt;
===Enabling Replication===&lt;br /&gt;
&lt;br /&gt;
If you quickly need to set up replication just issue&lt;br /&gt;
&lt;br /&gt;
 SLAVEOF &amp;lt;IP&amp;gt; &amp;lt;port&amp;gt;&lt;br /&gt;
on a machine that you want to become slave of the given IP. It will immediately get values from the master. Note that this instance will still be writable. If you want it to be read-only change the redis config file (only available in most recent version, e.g. not on Debian).&lt;br /&gt;
&lt;br /&gt;
To revert the slave setting run&lt;br /&gt;
&lt;br /&gt;
 SLAVEOF NO ONE&lt;br /&gt;
&lt;br /&gt;
===Dump Database Backup===&lt;br /&gt;
&lt;br /&gt;
As Redis allows RDB database dumps in background, you can issue a dump at any time. Just run:&lt;br /&gt;
&lt;br /&gt;
 BGSAVE&lt;br /&gt;
&lt;br /&gt;
When running this command Redis will fork and the new process will dump into the &amp;quot;dbfilename&amp;quot; configured in the Redis configuration without the original process being blocked. Of course the fork itself might cause an interruption.&lt;br /&gt;
&lt;br /&gt;
Use &amp;quot;LASTSAVE&amp;quot; to check when the dump file was last updated. For a simple backup solution just backup the dump file.&lt;br /&gt;
&lt;br /&gt;
If you need a synchronous save run &amp;quot;SAVE&amp;quot; instead of &amp;quot;BGSAVE&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Listing Connections===&lt;br /&gt;
&lt;br /&gt;
Starting with version 2.4 you can list connections with&lt;br /&gt;
&lt;br /&gt;
 CLIENT LIST&lt;br /&gt;
and you can terminate connections with&lt;br /&gt;
&lt;br /&gt;
 CLIENT KILL &amp;lt;IP&amp;gt;:&amp;lt;port&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Monitoring Traffic===&lt;br /&gt;
&lt;br /&gt;
The propably most useful command compared to memcached where you need to trace network traffic is the &amp;quot;MONITOR&amp;quot; command which will dump incoming commands in real time.&lt;br /&gt;
&lt;br /&gt;
 redis 127.0.0.1:6379&amp;gt; MONITOR&lt;br /&gt;
 OK&lt;br /&gt;
 1371241093.375324 &amp;quot;monitor&amp;quot;&lt;br /&gt;
 1371241109.735725 &amp;quot;keys&amp;quot; &amp;quot;*&amp;quot;&lt;br /&gt;
 1371241152.344504 &amp;quot;set&amp;quot; &amp;quot;testkey&amp;quot; &amp;quot;1&amp;quot;&lt;br /&gt;
 1371241165.169184 &amp;quot;get&amp;quot; &amp;quot;testkey&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Checking for Keys===&lt;br /&gt;
&lt;br /&gt;
If you want to know if an instance has a key or keys matching some pattern use &amp;quot;KEYS&amp;quot; instead of &amp;quot;GET&amp;quot; to get an overview.&lt;br /&gt;
&lt;br /&gt;
 redis 127.0.0.1:6379&amp;gt; KEYS test*&lt;br /&gt;
 1) &amp;quot;testkey2&amp;quot;&lt;br /&gt;
 2) &amp;quot;testkey3&amp;quot;&lt;br /&gt;
 3) &amp;quot;testkey&amp;quot;&lt;br /&gt;
On production servers use &amp;quot;KEYS&amp;quot; with care as you can limit it and it will cause a full scan of all keys!&lt;/div&gt;</summary>
		<author><name>Brian</name></author>	</entry>

	</feed>