<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>It's GG</title>
  <id>http://127.0.0.1</id>
  <updated>2011-09-23</updated>
  <author>
    <name>GG</name>
  </author>
  <entry>
    <title>Delete all Redis keys</title>
    <link rel="alternate" href="http://127.0.0.1/2011/11/01/delete-all-redis-keys/"/>
    <id>http://127.0.0.1/2011/11/01/delete-all-redis-keys/</id>
    <published>2011-11-01</published>
    <updated>2011-11-01</updated>
    <author>
      <name>GG</name>
    </author>
    <summary type="html">&lt;pre class="prettyprint"&gt;
redis-cli KEYS "*" | xargs redis-cli DEL
&lt;/pre&gt;

</summary>
    <content type="html">&lt;pre class="prettyprint"&gt;
redis-cli KEYS "*" | xargs redis-cli DEL
&lt;/pre&gt;

</content>
  </entry>
  <entry>
    <title>Recursively add empty directories to git</title>
    <link rel="alternate" href="http://127.0.0.1/2011/10/03/recursively-add-empty-directories-to-git/"/>
    <id>http://127.0.0.1/2011/10/03/recursively-add-empty-directories-to-git/</id>
    <published>2011-10-03</published>
    <updated>2011-10-03</updated>
    <author>
      <name>GG</name>
    </author>
    <summary type="html">&lt;pre class="prettyprint"&gt;
for i in $(find . -type d -regex ``./[^.].*'' -empty); do touch $i"/.gitignore"; done;
&lt;/pre&gt;

</summary>
    <content type="html">&lt;pre class="prettyprint"&gt;
for i in $(find . -type d -regex ``./[^.].*'' -empty); do touch $i"/.gitignore"; done;
&lt;/pre&gt;

</content>
  </entry>
  <entry>
    <title>Flash policy server using Node.js</title>
    <link rel="alternate" href="http://127.0.0.1/2011/10/02/flash-policy-server-using-nodejs/"/>
    <id>http://127.0.0.1/2011/10/02/flash-policy-server-using-nodejs/</id>
    <published>2011-10-02</published>
    <updated>2011-10-02</updated>
    <author>
      <name>GG</name>
    </author>
    <summary type="html">&lt;p&gt;The following code serves the cross domain policy file, needed for flash socket
connections&amp;hellip;&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;The following code serves the cross domain policy file, needed for flash socket
connections.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;flash_policy_server.js&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
var net = require(&amp;quot;net&amp;quot;),
    domains = [&amp;quot;*:*&amp;quot;]; // Domain:Port

net.createServer(
    function(socket) {
        socket.write(&amp;quot;&amp;lt;?xml version='1.0' ?&amp;gt;\n&amp;quot;);
        socket.write(&amp;quot;&amp;lt;!DOCTYPE cross-domain-policy SYSTEM 'http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd'&amp;gt;\n&amp;quot;);
        socket.write(&amp;quot;&amp;lt;cross-domain-policy&amp;gt;\n&amp;quot;);
        domains.forEach(
            function(domain) {
                var parts = domain.split(':');
                socket.write(&amp;quot;\t&amp;lt;allow-access-from domain='&amp;quot; + parts[0] + &amp;quot;' to-ports='&amp;quot; + parts[1] + &amp;quot;' /&amp;gt;\n&amp;quot;);
            }
        );
        socket.write(&amp;quot;&amp;lt;/cross-domain-policy&amp;gt;\n&amp;quot;);
        socket.end();
    }
).listen(843);
&lt;/pre&gt;


&lt;p&gt;Since 843 is a reserved port, you have to run the server as root.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
sudo node flash_policy_server.js
&lt;/pre&gt;

</content>
  </entry>
  <entry>
    <title>Exploring Redis</title>
    <link rel="alternate" href="http://127.0.0.1/2011/09/24/exploring-redis/"/>
    <id>http://127.0.0.1/2011/09/24/exploring-redis/</id>
    <published>2011-09-24</published>
    <updated>2011-09-24</updated>
    <author>
      <name>GG</name>
    </author>
    <summary type="html">&lt;h2&gt;1. Introduction&lt;/h2&gt;

&lt;h3&gt;1.1. What is Redis?&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;RE&lt;/strong&gt;mote &lt;strong&gt;DI&lt;/strong&gt;ctionary &lt;strong&gt;S&lt;/strong&gt;erver(Redis) is a key-value datastore created by
Salvatore Sanfilippo. Redis can store rich set of datatypes including lists, sets,
ordered sets and hashes in addition to strings. Redis provides many convenience
methods that operate on these datatypes&amp;hellip;&lt;/p&gt;
</summary>
    <content type="html">&lt;h2&gt;1. Introduction&lt;/h2&gt;

&lt;h3&gt;1.1. What is Redis?&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;RE&lt;/strong&gt;mote &lt;strong&gt;DI&lt;/strong&gt;ctionary &lt;strong&gt;S&lt;/strong&gt;erver(Redis) is a key-value datastore created by
Salvatore Sanfilippo. Redis can store rich set of datatypes including lists, sets,
ordered sets and hashes in addition to strings. Redis provides many convenience
methods that operate on these datatypes.&lt;/p&gt;

&lt;h3&gt;1.2. Advantages&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Blazing fast &amp;ndash; Redis can support 100K+ read/write operations per sec.&lt;/li&gt;
&lt;li&gt;Rich Datatypes &amp;ndash; Redis can store binary safe Strings, Lists, Hashes, Sets and Ordered Sets.&lt;/li&gt;
&lt;li&gt;Atomicity &amp;ndash; All operations in Redis are Atomic. Redis can run operations under transaction.&lt;/li&gt;
&lt;li&gt;Mulitool &amp;ndash; Redis supports publish/subscribe, notifications, key expiry etc in addition to data storage.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;2. Data Structures&lt;/h2&gt;

&lt;h3&gt;2.1. Strings&lt;/h3&gt;

&lt;p&gt;Redis can store binary safe strings of size limit upto 1GB.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; SET name "John Doe"
OK
redis 127.0.0.1:6379&gt; GET name
"John Doe"
&lt;/pre&gt;


&lt;p&gt;Strings can be stored and retrived in batches.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; MSET age 30 sex "male"
OK
redis 127.0.0.1:6379&gt; MGET age sex
1) "30"
2) "male"
&lt;/pre&gt;


&lt;p&gt;Strings can be treated as atomic counter.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; INCR age
(integer) 31
redis 127.0.0.1:6379&gt; INCRBY age 4
(integer) 35
redis 127.0.0.1:6379&gt; GET age
"35"
redis 127.0.0.1:6379&gt; DECR age
(integer) 34
redis 127.0.0.1:6379&gt; DECRBY age 4
(integer) 30
redis 127.0.0.1:6379&gt; GET age
"30"
&lt;/pre&gt;


&lt;p&gt;Strings are mutable and can be modified in place.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; APPEND name " Mr."
(integer) 12
redis 127.0.0.1:6379&gt; GET name
"John Doe Mr."
redis 127.0.0.1:6379&gt; STRLEN name
(integer) 12
redis 127.0.0.1:6379&gt; SUBSTR name 0 3
"John"
&lt;/pre&gt;


&lt;h3&gt;2.2. Lists&lt;/h3&gt;

&lt;p&gt;Redis can store ordered collection of strings in a list.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; LPUSH students "John Doe"
(integer) 1
redis 127.0.0.1:6379&gt; LPUSH students "Captain Kirk"
(integer) 2
redis 127.0.0.1:6379&gt; LPUSH students "Sheldon Cooper"
(integer) 3
redis 127.0.0.1:6379&gt; LLEN students
(integer) 3
redis 127.0.0.1:6379&gt; LRANGE students 0 2
1) "Sheldon Cooper"
2) "Captain Kirk"
3) "John Doe"
redis 127.0.0.1:6379&gt; LPOP students
"Sheldon Cooper"
redis 127.0.0.1:6379&gt; LLEN students
(integer) 2
redis 127.0.0.1:6379&gt; LRANGE students 0 1
1) "Captain Kirk"
2) "John Doe"
redis 127.0.0.1:6379&gt; LREM students 1 "John Doe"
(integer) 1
redis 127.0.0.1:6379&gt; LLEN students
(integer) 1
redis 127.0.0.1:6379&gt; LRANGE students 0 0
1) "Captain Kirk"
&lt;/pre&gt;


&lt;p&gt;Lists are mutable and can be modified in place.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; LINSERT students BEFORE "Captain Kirk" "Dexter Morgan"
(integer) 3
redis 127.0.0.1:6379&gt; LRANGE students 0 2
1) "Dexter Morgan"
2) "Captain Kirk"
3) "John Doe"
redis 127.0.0.1:6379&gt; LPUSH students "Peter Parker"
(integer) 4
redis 127.0.0.1:6379&gt; LRANGE students 0 3
1) "Peter Parker"
2) "Dexter Morgan"
3) "Captain Kirk"
4) "John Doe"
redis 127.0.0.1:6379&gt; LTRIM students 1 3
OK
redis 127.0.0.1:6379&gt; LLEN students
(integer) 3
redis 127.0.0.1:6379&gt; LRANGE students 0 2
1) "Dexter Morgan"
2) "Captain Kirk"
3) "John Doe"
redis 127.0.0.1:6379&gt; LREM students 1 "John Doe"
(integer) 1
redis 127.0.0.1:6379&gt; LLEN students
(integer) 1
redis 127.0.0.1:6379&gt; LRANGE students 0 1
1) "Captain Kirk"
&lt;/pre&gt;


&lt;h3&gt;2.3. Sets&lt;/h3&gt;

&lt;p&gt;Redis can store unordered collection of non-duplicate strings in a set.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; SADD birds crow
(integer) 1
redis 127.0.0.1:6379&gt; SADD birds pigeon
(integer) 1
redis 127.0.0.1:6379&gt; SADD birds bat
(integer) 1
redis 127.0.0.1:6379&gt; SADD mammals dog
(integer) 1
redis 127.0.0.1:6379&gt; SADD mammals cat
(integer) 1
redis 127.0.0.1:6379&gt; SADD mammals bat
(integer) 1
redis 127.0.0.1:6379&gt; SMEMBERS birds
1) "bat"
2) "crow"
3) "pigeon"
redis 127.0.0.1:6379&gt; SMEMBERS mammals
1) "bat"
2) "cat"
3) "dog"
&lt;/pre&gt;


&lt;p&gt;Sets are mutable and can be modified in place.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; SREM mammals cat
(integer) 1
redis 127.0.0.1:6379&gt; SMEMBERS mammals
1) "bat"
2) "dog"
redis 127.0.0.1:6379&gt; SADD mammals human
(integer) 1
redis 127.0.0.1:6379&gt; SMEMBERS mammals
1) "bat"
2) "human"
3) "dog"
&lt;/pre&gt;


&lt;p&gt;Redis supports common Set related operations.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; SINTER birds mammals
1) "bat"
redis 127.0.0.1:6379&gt; SUNION birds mammals
1) "crow"
2) "bat"
3) "human"
4) "pigeon"
5) "dog"
redis 127.0.0.1:6379&gt; SDIFF birds mammals
1) "crow"
2) "pigeon"
&lt;/pre&gt;


&lt;h3&gt;2.4. Ordered Sets&lt;/h3&gt;

&lt;p&gt;Ordered Sets are similar to Sets, but the members are sorted and stored according
to an associated floating point score.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; ZADD days 0 mon
(integer) 1
redis 127.0.0.1:6379&gt; ZADD days 1 tue
(integer) 1
redis 127.0.0.1:6379&gt; ZADD days 2 wed
(integer) 1
redis 127.0.0.1:6379&gt; ZADD days 3 thu
(integer) 1
redis 127.0.0.1:6379&gt; ZADD days 4 fri
(integer) 1
redis 127.0.0.1:6379&gt; ZADD days 5 sat
(integer) 1
redis 127.0.0.1:6379&gt; ZADD days 6 sun
(integer) 1
redis 127.0.0.1:6379&gt; ZCARD days
(integer) 7
redis 127.0.0.1:6379&gt; ZRANGE days 0 6
1) "mon"
2) "tue"
3) "wed"
4) "thu"
5) "fri"
6) "sat"
7) "sun"
redis 127.0.0.1:6379&gt; ZSCORE days sat
"5"
redis 127.0.0.1:6379&gt; ZCOUNT days 3 6
(integer) 4
redis 127.0.0.1:6379&gt; ZRANGEBYSCORE days 3 6
1) "thu"
2) "fri"
3) "sat"
4) "sun"
&lt;/pre&gt;


&lt;h3&gt;2.5. Hashes&lt;/h3&gt;

&lt;p&gt;Redis can store key-value pairs in Hashes.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; HKEYS student
1) "name"
2) "age"
3) "sex"
redis 127.0.0.1:6379&gt; HVALS student
1) "Ganesh"
2) "30"
3) "Male"
redis 127.0.0.1:6379&gt; HGETALL student
1) "name"
2) "Ganesh"
3) "age"
4) "30"
5) "sex"
6) "Male"
redis 127.0.0.1:6379&gt; HDEL student sex
(integer) 1
redis 127.0.0.1:6379&gt; HGETALL student
1) "name"
2) "Ganesh"
3) "age"
4) "30"
&lt;/pre&gt;


&lt;p&gt;Hashes can be stored and retrived in batches.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; HMSET kid name Akshi age 2 sex Female
OK
redis 127.0.0.1:6379&gt; HMGET kid name age sex
1) "Akshi"
2) "2"
3) "Female"
&lt;/pre&gt;


&lt;h2&gt;3. Publish/Subscribe&lt;/h2&gt;

&lt;p&gt;Redis supports Publish/Subscribe pattern. Redis publisher send messages to different
channels. And Redis receivers listen to the channels and retrieve the messages of its interest.&lt;/p&gt;

&lt;h3&gt;3.1. Channel Subscription&lt;/h3&gt;

&lt;p&gt;In one redis client session&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; SUBSCRIBE channelone
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "channelone"
3) (integer) 1
&lt;/pre&gt;


&lt;p&gt;In another redis client session&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; PUBLISH channelone hello
(integer) 1
redis 127.0.0.1:6379&gt; PUBLISH channelone world
(integer) 1
&lt;/pre&gt;


&lt;p&gt;The messages are received in the first redis client session.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; SUBSCRIBE channelone
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "channelone"
3) (integer) 1
1) "message"
2) "channelone"
3) "hello"
1) "message"
2) "channelone"
3) "world"
&lt;/pre&gt;


&lt;h3&gt;3.2. Pattern Subscription&lt;/h3&gt;

&lt;p&gt;Redis also supports pattern based subscriptions, wherein the receivers listen to
channels matching a particular pattern.&lt;/p&gt;

&lt;p&gt;In one redis client session.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; PSUBSCRIBE channel*
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "channel*"
3) (integer) 1
&lt;/pre&gt;


&lt;p&gt;In another redis client session.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; PUBLISH channelone hello
(integer) 1
redis 127.0.0.1:6379&gt; PUBLISH channeltwo world
(integer) 1
&lt;/pre&gt;


&lt;p&gt;The messages sent to both the channels are received in the first redis client session.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; PSUBSCRIBE channel*
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "channel*"
3) (integer) 1
1) "pmessage"
2) "channel*"
3) "channelone"
4) "hello"
1) "pmessage"
2) "channel*"
3) "channeltwo"
4) "world"
&lt;/pre&gt;


&lt;h2&gt;4. Key Expiry&lt;/h2&gt;

&lt;p&gt;Redis supports volatile keys that expire after a specified TTL(Time To Live).&lt;/p&gt;

&lt;p&gt;Keys with TTL as -1 never expire.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; SET name "John Doe"
OK
redis 127.0.0.1:6379&gt; TTL name
(integer) -1
&lt;/pre&gt;




&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; SET name "John Doe"
OK
redis 127.0.0.1:6379&gt; EXISTS name
(integer) 1
redis 127.0.0.1:6379&gt; EXPIRE name 5
(integer) 1
&lt;/pre&gt;


&lt;p&gt;After 5 secs&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; EXISTS name
(integer) 0
redis 127.0.0.1:6379&gt; GET name
(nil)
&lt;/pre&gt;


&lt;p&gt;Keys can be expired at specified unix timestamp. The following expires at 2011-09-24 00:40:00&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; SET name "John Doe"
OK
redis 127.0.0.1:6379&gt; EXPIREAT name 1316805000
(integer) 1
redis 127.0.0.1:6379&gt; EXISTS name
(integer) 0
&lt;/pre&gt;


&lt;h2&gt;5. Transactions&lt;/h2&gt;

&lt;p&gt;All Redis operations run under transactions. Redis supports multi step commands that run
as a single atomic unit.&lt;/p&gt;

&lt;p&gt;*NX commands modify the keys only when the keys do not already exists. Checking for the keys
and setting the value happen under transaction and are unaffected by simultaneous clients
trying to alter the keys.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; SET name "John Doe"
OK
redis 127.0.0.1:6379&gt; SETNX name "Dexter Morgan"
(integer) 0
redis 127.0.0.1:6379&gt; GET name
"John Doe"
&lt;/pre&gt;




&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; GETSET name "Dexter Morgan"
"John Doe"
redis 127.0.0.1:6379&gt; GET name
"Dexter Morgan"
&lt;/pre&gt;


&lt;p&gt;Redis can also run multiple operations under transactions.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; SET counter 0
OK
redis 127.0.0.1:6379&gt; MULTI
OK
redis 127.0.0.1:6379&gt; INCR counter
QUEUED
redis 127.0.0.1:6379&gt; INCR counter
QUEUED
redis 127.0.0.1:6379&gt; INCR counter
QUEUED
redis 127.0.0.1:6379&gt; EXEC
1) (integer) 1
2) (integer) 2
3) (integer) 3
redis 127.0.0.1:6379&gt; GET counter
"3"
&lt;/pre&gt;


&lt;p&gt;Transactions can be explicitly aborted.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; SET newcounter 0
OK
redis 127.0.0.1:6379&gt; MULTI
OK
redis 127.0.0.1:6379&gt; INCR newcounter
QUEUED
redis 127.0.0.1:6379&gt; INCR newcounter
QUEUED
redis 127.0.0.1:6379&gt; INCR newcounter
QUEUED
redis 127.0.0.1:6379&gt; DISCARD
OK
redis 127.0.0.1:6379&gt; GET newcounter
"0"
&lt;/pre&gt;


&lt;h2&gt;6. Persistance&lt;/h2&gt;

&lt;p&gt;Redis is in-memory datastore. But it supports configurable disk persistance.&lt;/p&gt;

&lt;h3&gt;6.1. Snapshotting&lt;/h3&gt;

&lt;p&gt;Snapshotting is the default persistance method of Redis. Redis stores the entire
memory content in a file called dump.rdb at regular interval of time.&lt;/p&gt;

&lt;p&gt;You can also explicity trigger snapshotting.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; SET name "John Doe"
OK
redis 127.0.0.1:6379&gt; SAVE
OK
redis 127.0.0.1:6379&gt; SET name "Sheldon Cooper"
OK
redis 127.0.0.1:6379&gt; BGSAVE
Background saving started
&lt;/pre&gt;


&lt;p&gt;On redis installed through brew on Mac OSX, the dump.rdb is present at&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
/usr/local/var/db/redis/dump.rdb
&lt;/pre&gt;


&lt;h3&gt;6.2. Append-only file&lt;/h3&gt;

&lt;p&gt;Redis also supports fully-durable alternate to snapshotting. In the append-only mode
all the commands altering the keys will be appended to a AOF(Append-Only File).
The current state of Redis can be rebuilt by executing the commands in AOF.&lt;/p&gt;

&lt;p&gt;To enable append-only file mode, change the following in redis.conf and restart the
redis server.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
appendonly yes
&lt;/pre&gt;


&lt;p&gt;All the executed commands are appended to appendonly.aof file&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; GET name
(nil)
redis 127.0.0.1:6379&gt; SET name "Ganesh Gunasegaran"
OK
redis 127.0.0.1:6379&gt; EXIT

→ cat /usr/local/var/db/redis/appendonly.aof
*2
$6
SELECT
$1
0
*3
$3
SET
$4
name
$18
Ganesh Gunasegaran
&lt;/pre&gt;


&lt;h2&gt;7. Administration&lt;/h2&gt;

&lt;p&gt;Redis has 16 numbered databases. Data can be stored and moved among them.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; SELECT 0
OK
redis 127.0.0.1:6379&gt; SET name "John Doe"
OK
redis 127.0.0.1:6379&gt; SELECT 1
OK
redis 127.0.0.1:6379[1]&gt; GET name
(nil)
redis 127.0.0.1:6379[1]&gt; SELECT 0
OK
redis 127.0.0.1:6379&gt; MOVE name 1
(integer) 1
redis 127.0.0.1:6379&gt; SELECT 1
OK
redis 127.0.0.1:6379[1]&gt; GET name
"John Doe"
&lt;/pre&gt;


&lt;p&gt;Redis supports various commands to query about the database.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379[1]&gt; DBSIZE
(integer) 1
redis 127.0.0.1:6379[1]&gt; INFO
redis_version:2.2.13
redis_git_sha1:00000000
redis_git_dirty:0
arch_bits:64
multiplexing_api:kqueue
......
&lt;/pre&gt;


&lt;p&gt;Redis provides commands for clearing the database.&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
redis 127.0.0.1:6379&gt; SET name "John Doe"
OK
redis 127.0.0.1:6379&gt; DBSIZE
(integer) 1
redis 127.0.0.1:6379&gt; SELECT 1
OK
redis 127.0.0.1:6379[1]&gt; SET name "Sheldon Cooper"
OK
redis 127.0.0.1:6379[1]&gt; DBSIZE
(integer) 1
redis 127.0.0.1:6379[1]&gt; SELECT 0
OK
redis 127.0.0.1:6379&gt; FLUSHDB
OK
redis 127.0.0.1:6379&gt; DBSIZE
(integer) 0
redis 127.0.0.1:6379&gt; SELECT 1
OK
redis 127.0.0.1:6379[1]&gt; DBSIZE
(integer) 1
redis 127.0.0.1:6379[1]&gt; FLUSHALL
OK
redis 127.0.0.1:6379[1]&gt; DBSIZE
(integer) 0
&lt;/pre&gt;


&lt;h2&gt;8. Client Libraries&lt;/h2&gt;

&lt;p&gt;Redis has a wide range of client libraries.&lt;/p&gt;

&lt;h3&gt;8.1. Node.js Client&lt;/h3&gt;

&lt;pre class="prettyprint"&gt;
gg:~/Work/Node
→ npm install redis
redis@0.6.7 ./node_modules/redis
&lt;/pre&gt;


&lt;p&gt;Simple storage and retrieval&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
var redis = require('redis');
var redisClient = redis.createClient();

redisClient.on('error', function(error) {
  console.log('Error: ' + error);
});

console.log('Storing Data');
redisClient.set('name', 'Ganesh Gunasegaran', redis.print);

console.log('Retreiving Data');
redisClient.get('name', redis.print);

redisClient.quit();
&lt;/pre&gt;


&lt;p&gt;Output&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
gg:~/Work/Node
→ node redis_test.js
Storing Data
Retreiving Data
Reply: OK
Reply: Ganesh Gunasegaran
&lt;/pre&gt;


&lt;p&gt;Using Node.js client to access Redis Publish/Subscribe&lt;/p&gt;

&lt;p&gt;pubsub_client_one.js&lt;/p&gt;

&lt;pre class="prettyprint"&gt;

var redis = require('redis');
var clientOne = redis.createClient();

clientOne.on('message', function(channel, message) {
  console.log('clientOne got : ' + message);
});

clientOne.subscribe('channelOne');
&lt;/pre&gt;


&lt;p&gt;pubsub_client_one.js&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
var redis = require('redis');
var clientTwo = redis.createClient();

clientTwo.publish('channelOne', 'Hello message from clientTwo');
&lt;/pre&gt;


&lt;p&gt;Output&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
gg:~/Work/Node
→ node pubsub_client_one.js
clientOne got : Hello message from clientTwo
gg:~/Work/Node
→ node pubsub_client_two.js
&lt;/pre&gt;


&lt;h3&gt;8.2. Other Clients&lt;/h3&gt;

&lt;p&gt;For a full list of supported clients, refer to &lt;a href="http://redis.io/clients"&gt;Redis Homepage&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;9. References&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://redis.io/documentation"&gt;Redis documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://simonwillison.net/static/2010/redis-tutorial/"&gt;Simon Willison &amp;ndash; Redis tutorial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blog.mjrusso.com/2010/10/17/redis-from-the-ground-up.html"&gt;Michael J. Russo &amp;ndash; Redis from ground up&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;10. Summary&lt;/h2&gt;

&lt;p&gt;&lt;img src="/img/redis/overview.png" alt="Overview" /&gt;&lt;/p&gt;

&lt;p&gt;This work is licensed under a &lt;a href="http://creativecommons.org/licenses/by/3.0/"&gt;Creative Commons Attribution &amp;ndash; Non Commercial &amp;ndash; No Derives 3.0
Unported License&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Redis - Command Reference</title>
    <link rel="alternate" href="http://127.0.0.1/2011/09/23/redis---command-reference/"/>
    <id>http://127.0.0.1/2011/09/23/redis---command-reference/</id>
    <published>2011-09-23</published>
    <updated>2011-09-23</updated>
    <author>
      <name>GG</name>
    </author>
    <summary type="html">&lt;p&gt;Click here to download &lt;a href="/files/redis_command_reference_sep_23_2011.pdf"&gt;Redis &amp;ndash; Command Reference&lt;/a&gt; last updated on Sept 23, 2011.&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;Click here to download &lt;a href="/files/redis_command_reference_sep_23_2011.pdf"&gt;Redis &amp;ndash; Command Reference&lt;/a&gt; last updated on Sept 23, 2011.&lt;/p&gt;
</content>
  </entry
