UNPKG

redis-node

Version:

A Complete Redis Client for Node.js

51 lines (43 loc) 1.36 kB
var redis = require('redis-node'); var redcli = redis.createClient(); redcli.select(1); var testObj = {'a': 'ö'} var jsonString = JSON.stringify(testObj); console.log('Origin JSON string: '+jsonString); console.log('JSON.parse(jsonString): '); console.log(JSON.parse(jsonString)); redcli.set('testJson', jsonString, function(err, status) { if (err) throw err; if (status) { redcli.get('testJson', function(err, jsonStringFromRedis) { if (err) throw err; if (jsonStringFromRedis) { console.log('\nRedis JSON string: '+jsonStringFromRedis); try { JSON.parse(jsonStringFromRedis); } catch(e) { console.log('JSON.parse(jsonStringFromRedis) fails since output is corrupted.\n'); } } }); } }); // Ugly hack to format output easily. setTimeout(function() { var testStr = 'ä'; console.log('Origin test string: '+testStr); var buf = new Buffer(32), size = buf.write(testStr, 0, "utf8"); testStr = buf.slice(0, size); redcli.set('testStr', testStr, function(err, status) { if (err) throw err; if (status) { redcli.get('testStr', function(err, testStrFromRedis) { if (err) throw err; if (testStrFromRedis) { console.log('Redis test string: '+testStrFromRedis.toString("binary")); } }); } }); }, 150);