Redis is a key-value type of database, and key is all strings, value can be a collection, hash, list, and so on.
Redis implements transactional functionality through the Multi/discard/exec/watch of these 4 commands. For transactions, we must know that transaction security is a very important one.
Transactions provide a mechanism for packaging multiple commands and then executing them one at a time, and will not break during transaction execution-meaning that the client's other commands are blocked until the transaction is complete.
var Redis = require ("Redis"), var client = Redis.createclient (); Client.on ("Error", function (Err) {Console.log ("error" + E RR);}); Client.on ("Connect", runsample); function runsample () {//Set a value of string type, return value: Okclient.set ("String Key", "Hello World", function (err, reply) {Console.log (reply.tostring ());}); /Gets the value of a string type, returns the word: Valueclient.get ("string Key", function (err, reply) {Console.log (reply.tostring ());}); /Another way to get the value of a string type, return Word: Valuevar multicmd = Client.multi (), Multicmd.get ("string Key"), Multicmd.exec (function (Err, Reply) {Console.log (reply.tostring ());}); /Set Expiration Time Client.expire (' string key ', 3);//valid time validation var MyTimer = setinterval (function () {client.get (' string key ', function ( Err, Reply) {if (reply) {Console.log (' I live: ' + reply.tostring ());} else {cleartimeout (MyTimer); Console.log (' I expired ') ); Client.quit ()});}, 1000);//Check how long a value is persisted before it expires var MyTimer = setinterval (function () {client.get (' string key ', function (err, reply) {if (reply) {Console.log (' I live: ' + reply.tostring ()); Client.ttl (' String key ', Writettl);} else {cleartimeout (MyTimer); Console.log (' I expired '); Client.quit ();}});}, 1000);//set operation var key = "Set key"; Client.sadd (Key, UID); Client.sadd (Key, "a"), Client.sadd (Key, "B");//Gets the key collection contains "1", if included, returns 1, otherwise returns 0client.sismember (key, "a", ShowData);//client.quit ();} function Writettl (err, data) {Console.log ("I live for this long yet:" + data);} function ShowData (err, data) {if (err) {Console.log ("ERR:" + err);} else {Console.log ("Reply:" + data);}}
Resources:
Redis Command Reference
Read and write Redis data in node. JS (Expiration Time and TTL)
Github Node_redis
Redis Design and implementation
Document Information
- Copyright Disclaimer: Free Reprint-Non-commercial-non-derivative-retain attribution | Creative Commons by-nc-nd 3.0
- Original URL: http://blog.csdn.net/cdztop/article/details/32784295
- Last modified: June 21, 2014 02:07