fictorial / redis-node-client Goto Github PK
View Code? Open in Web Editor NEWRedis client for Node.js (abandoned)
License: MIT License
Redis client for Node.js (abandoned)
License: MIT License
I cannot make this version or the fork that claims to have fixed work with Node 0.2.4. 0.2.3 is absolutely fine however but on .4 I get no callbacks from server requests. I think it's related to originalCommand getting clobbered somehow.
Patch + tests available @ http://github.com/clement/redis-node-client/tree/empty_lists
Hi!
If i execute some code:
var client = require("./redis-node-client/lib/redis-client").createClient();
client.set('test', 'data');
when gets error like :
/home/node/redis-node-client/lib/redis-client.js:394
var callback = originalCommand[originalCommand.length - 1];
^
TypeError: Cannot read property 'length' of undefined
redis-node-client version 1.3.5
redis version 1.2.6
node.js version 0.1.97
Sorry for my bad english, i'm from russia)
Thanx.
See the redis node_chat example here:
The the following keys:
"config:a"
"config:b"
"config:c d"
"keys" returns the following string:
"config:a config:b config:c d"
Splitting on \s results in the following keys
"config:a"
"config:b"
"config:c"
"d"
This bulkreply should be an array or the separator should be escaped from the values.
Is redis-node-client compatible with node v0.1.100 ?
diff --git a/counter-example.js b/counter-example.js index cb31bb2..5328824 100644 --- a/counter-example.js +++ b/counter-example.js @@ -1,5 +1,5 @@ var sys = require("sys"); -var redis = require("./redis"); +var redis = require("./redisclient"); var client = new redis.Client(); client.connect(learn_to_count);
The result is :
assert:80
throw new assert.AssertionError({
^
AssertionError: "testZINTER" "ERR unknown command 'zinter'"
at /home/ogoudron/fictorial-redis-node-client-30e9f41/test/test.js:121:25
at Client.onReply_ (/home/ogoudron/fictorial-redis-node-client-30e9f41/lib/redis-client.js:400:34)
at /home/ogoudron/fictorial-redis-node-client-30e9f41/lib/redis-client.js:143:30
at ReplyParser.feed (/home/ogoudron/fictorial-redis-node-client-30e9f41/lib/redis-client.js:160:55)
at Stream. (/home/ogoudron/fictorial-redis-node-client-30e9f41/lib/redis-client.js:337:28)
at Stream.emit (events:26:26)
at IOWatcher.callback (net:512:16)
at node.js:265:9
Tested on Ubuntu Desktop 10.04 (VIA C7) and Debian 5.0 (Celeron 220).
Bests regards, Olivier Goudron
For example:
var kiwi = require('kiwi'),
redisClient = kiwi.require('redis-client').createClient();
redisClient.subscribeTo("channel", function (channel, message) {
var message2 = JSON.parse(message);
});
If a string which otherwise would be processed fine with JSON.parse is published to "channel", the above code will bomb (node.js v0.1.9x).
Maybe that's expected and I'm just clueless about how to properly buffer inbound chunks before referencing them later in the callback. The following seems to work .. most of the time:
var kiwi = require('kiwi'),
redisClient = kiwi.require('redis-client').createClient();
redisClient.subscribeTo("channel", function (channel, message) {
var message2 = '' + message,
message3 = JSON.parse(message2);
});
What is the best way to go about this, if that's a good way to put it?
require("tcp") changes to require("net")
this.conn = process.tcp.Connection()
becomes
this.conn = net.Stream()
Would you consider publishing the redis-node-client library to NPM?
Thanks,
Zach
diff --git a/redisclient.js b/redisclient.js index 6660a38..047a264 100644 --- a/redisclient.js +++ b/redisclient.js @@ -92,7 +92,7 @@ Client.prototype.connect = function (callback) { }; Client.prototype.close = function () { - if (this.conn && conn.readyState === "open") { + if (this.conn && this.conn.readyState === "open") { this.conn.close(); this.conn = null; }
When I run:
node test.js
I get the following error:
DEBUG: read buffer: -ERR unknown command 'PSUBSCRIBE'-ERR unknown command 'PUNSUBS ...
DEBUG: error: ERR unknown command 'PSUBSCRIBE'
ReferenceError: error is not defined
at Client.handleReplies (/home/maritz/Programming/repos/e-Tourney/lib/redis-client/redisclient.js:219:28)
at Stream. (/home/maritz/Programming/repos/e-Tourney/lib/redis-client/redisclient.js:67:16)
at IOWatcher.callback (net:328:14)
at node.js:813:9
make test in my redis passes all tests.
GIT revisions:
redis-node-client: 44a3058
node: 53530e98 (was the same with master HEAD - had to change back for something else)
redis: cac154c5
If there is anything I can do to provide further help, let me know. :)
would be very helpful to me :D
The following code used to work with an older version of redis-node-client (before the latest refactoring):
var logInUser = flow.define(
function(username, rawPassword) {
this.username = username
this.rawPassword = rawPassword
this.client = new redis.createClient(); // used to be redis.Client()
this.client.get('user:username:'+this.username+':id', this)
},function(err, userID){
this.userID = userID
if (this.userID == null) {
self.flash('message', 'login failure')
self.redirect('/login')
} else {
this.client.hgetall('user:id:' + this.userID, this)
}
},function(err, user) {
if (sha1.hex(user.salt + this.rawPassword) != user.password) {
self.flash('message', 'login failure')
self.redirect('/login')
} else {
self.flash('message', 'login successful')
self.session.user = user
self.redirect('/chat')
}
}
);
(This code uses flow-js [http://github.com/willconant/flow-js] to make the asynchronous logic easier to understand.)
The stacktrace culminates here:
Error: disconnected at Client.exists (/js hacking/redis-node-client/redisclient.js:582:19
(This is triggered right after the first call to client.get()
).
redis-node-client itself works (for example, code like the following works fine):
setInterval(function () {
client.get('getsetfoo', function (err, value) {
sys.puts("value is: " + value)
})
}, 5000);
Is the failure that I noted expected behavior (i.e., do I need to write my code differently now), or is there something else wrong?
In the case of LRANGE ( and perhaps others ), if the range is greater than the length, then its not an error. Rather *0<CR>
is returned. But currently handle_multi_bulk_reply()
only checks for -1. An empty list would be the appropriate behaviour. Patch is below. It isn't against the latest version, sorry.
diff --git a/redisclient.js b/redisclient.js
index 64dee0d..139f6f0 100644
--- a/redisclient.js
+++ b/redisclient.js
@@ -151,6 +151,8 @@ Client.prototype.handle_multi_bulk_reply = function (buf) {
var next_reply_at = crlf_at + crlf_len;
if (count === -1) // value doesn't exist
return [ null, next_reply_at ];
+ if (count === 0)
+ return [ [], next_reply_at ];
if (next_reply_at >= buffer.length)
return null;
var results = [];
~/.node_libraries/redis-node-client$ node test/test.js
............................................................................................++
assert:80
throw new assert.AssertionError({
^
AssertionError: "testZINTER" "ERR unknown command 'zinter'"
at /home/andi/.node_libraries/redis-node-client/test/test.js:121:25
at Client.onReply_ (/home/andi/.node_libraries/redis-node-client/lib/redis-client.js:400:34)
at /home/andi/.node_libraries/redis-node-client/lib/redis-client.js:143:30
at ReplyParser.feed (/home/andi/.node_libraries/redis-node-client/lib/redis-client.js:160:55)
at Stream.<anonymous> (/home/andi/.node_libraries/redis-node-client/lib/redis-client.js:337:28)
at Stream.emit (events:26:26)
at IOWatcher.callback (net:489:16)
at node.js:769:9
Redis 2.0.2
OS: OSX 10.5.8
Node: 0.1.94
Redis: 1.3.11
redis-client: 5050251
Test case: http://gist.github.com/400261
The request sent to redis is consistently truncated in the same place. Either of two changes avoid the problem (but are not fixes):
A. Swap the order of "template" and "code" properties
B. Change Client.requestBuffer to be created with an initial size of 4096 instead of 512
I'm trying to work out what the problem is now and will submit a fix if I find it.
TypeError: Cannot read property 'length' of null
at Client.handlePublishedMessage_ (/home/phazm/.node_libraries/redis-node-client/lib/redis-client.js:423:42)
at Client.onReply_ (/home/phazm/.node_libraries/redis-node-client/lib/redis-client.js:390:14)
at /home/phazm/.node_libraries/redis-node-client/lib/redis-client.js:136:34
at ReplyParser.feed (/home/phazm/.node_libraries/redis-node-client/lib/redis-client.js:198:25)
at Stream. (/home/phazm/.node_libraries/redis-node-client/lib/redis-client.js:337:28)
at Stream.emit (events:25:26)
at IOWatcher.callback (net:369:16)
at node.js:204:9
Using the latest from HEAD for redis, node, and redis-node-client
I'm not actually doing anything with pubsub, so I think there's an errant call somewhere, when it's running the code when it doesn't need to.
Getting this when I connect to Redis:
TypeError: Cannot read property 'length' of undefined
/usr/local/lib/node/.npm/redis-client/0.3.5/package/lib/redis-client.js:394
var callback = originalCommand[originalCommand.length - 1];
Redis HEAD sends pmessage for messages to psubscribers.
HSETNX was introduced in Redis 1.3.10, but redis-node-client doesn't seem to support it yet - can you confirm this, fictorial?
I'm having an issue between redis-node-client and redis-py (http://github.com/andymccurdy/redis-py), so I'm not sure which library it might be an issue with (or if it's my own issue), but this is the problem:
I have an app that stores compressed data in redis. When I store this data using redis-py, and then later try to read it with redis-node-client, I've noticed that the binary data gets mangled (gzip can't decompress the data anymore). I've attached some files that should make it pretty easy to reproduce the issue. The files to use are here: http://dl.dropbox.com/u/211886/redis_node_binary_issue.zip
First, to see that things work, fire up your redis server (on the default port and host). Then run "node write_file_to_redis.js" followed by "node read_file_from_redis.js" and you should get the output of the testfile.txt.gz after it has been decompressed. This is using the node-compress module (http://github.com/waveto/node-compress) but I've included a binary in the attached files. But after running this, the output should be:
This is some data that is going to be compressed
Similarly, do the same as above but using the python scripts (so "python write_file_to_redis.py" and "python read_file_from_redis.py").
Now, do the following:
a) python write_file_to_redis.py
b) node read_file_from_redis.js
You'll see that no output appears
Similarly:
a) node write_file_to_redis.js
b) python read_file_from_redis.py
Python fails with an exception, claiming it's not a gzipped file.
I tried using redis-cli to inspect what's going on, and it seems like the binary data that gets written to redis is actually different when redis-node-client writes it vs when redis-py writes it.
Hello,
Thanks for putting together this redis client. Did some testing today. Ran into a bug where there was no callback when "get"ing a key which had a large value. After some debugging, I noticed that the problem was related to this.valueBufferLen being reset.
See:
// If the current value buffer is too big, create a new buffer, copy in
// the old buffer, and replace the old buffer with the new buffer.
if (this.valueBufferLen === this.valueBuffer.length) {
sys.puts( ">>>> BUFFER OVERFLOW" );
var newBuffer = new Buffer(this.valueBuffer.length * 2);
this.valueBuffer.copy(newBuffer, 0, 0);
///D this.valueBufferLen = 0;
this.valueBuffer = newBuffer;
}
Documentation available here
I want to get the value of item 0 in a list.
// No worky
a = redis.lindex('mylist', 0);
sys.puts(a);
=> undefined
// No worky with a callback
b = redis.lindex('mylist', 0, function (err, value) { return value; });
sys.puts(b);
=> undefined
// Works, but it's ugly
c = redis.lindex('mylist', 0, function (err, value) { somevar = value; });
sys.puts(somevar);
=> yayitworks
Is there a better way?
If I do the following:
input = getStringFromUser();
client = require('lib/redis-client').createClient();
client.get(input);
will the person giving me the input be able to do something nasty, i.e. execute commands other than GET
? It would be nice if the documentation said something definitive on this point.
There were changes in Node 0.1.0 regarding observers that we need to incorporate.
Using latest from git, after starting publisher, then starting subscriber, I get this:
$ node subscriber.js
waiting for messages...
TypeError: Cannot read property 'length' of undefined
at Client.onReply_ (/web/node/node/redis/redis-node-client/lib/redis-client.js:395:51)
at /web/node/node/redis/redis-node-client/lib/redis-client.js:150:34
at ReplyParser.feed (/web/node/node/redis/redis-node-client/lib/redis-client.js:212:25)
at Stream. (/web/node/node/redis/redis-node-client/lib/redis-client.js:346:28)
at Stream.emit (events:25:26)
at IOWatcher.callback (net:365:18)
at node.js:176:9
if you try to compress redis_client.js with google closure you get this error:
redis-client.js:646: ERROR - Parse error.
Internet Explorer has a non-standard intepretation of trailing commas.
Arrays will have the wrong length and objects will not parse at all.
.. which of course does not affect the usage on nodejs but handicaps using compression in a project build process. simply removing the trailing comma on line 646 fixes this.
I am a active redis user and community member and wanted to try out redis on node.js
I installed the latest source from git for (node, redis, redis-node-client)
Both redis and node compiled w/o problem. I ran "sudo make install" node. Everything ok.
I fired up redis and ran "node test/test.js" which throws the error " has no method 'utf8Write'"
I am brand new to node.js so this could be a newbie bug, but I have no clue what is going on.
I am on Ubuntu 9.04.
LOGS:
sammy@laptop:~/Downloads/GIT/redis-node-client$ node test/test.js -v
DEBUG: [CONNECT]
DEBUG: [ERROR] Connection to redis encountered an error: TypeError: Object # has no method 'utf8Write'
DEBUG: [ERROR] TypeError: Object # has no method 'utf8Write'
DEBUG: [RECONNECTING 1/10]
DEBUG: [WAIT 1000 ms]
node.js:50
throw e;
^
TypeError: Object # has no method 'utf8Write'
at Client.sendCommand (/mnt/newhome/Downloads/GIT/redis-node-client/lib/redis-client.js:694:37)
at Client.select (/mnt/newhome/Downloads/GIT/redis-node-client/lib/redis-client.js:768:26)
at clearTestDatabasesBeforeEachTest (/mnt/newhome/Downloads/GIT/redis-node-client/test/test.js:128:12)
at /mnt/newhome/Downloads/GIT/redis-node-client/test/test.js:1865:9
at Array.forEach (native)
at Client.runAllTests (/mnt/newhome/Downloads/GIT/redis-node-client/test/test.js:1863:22)
at Client.emit (events:27:15)
at Stream. (/mnt/newhome/Downloads/GIT/redis-node-client/lib/redis-client.js:325:16)
at Stream.emit (events:27:15)
at IOWatcher. (net:864:16)
The redis client does recieve a connection:
[7338] 19 Sep 12:07:31 - Accepted 127.0.0.1:43113
[7338] 19 Sep 12:07:31 - Client closed connection
Any help would be appreciated :)
AssertionError: "select" "ERR unknown command '*2"
Hello,
Looking at the code, it is my understanding that a Client can not be invoked "simultaneously". Is this correct? If so, the application needs to either create a new client per call (which has the overhead of creating and ending a connection for each invocation) or creating some kind of client pool and managing asking and releasing a client to the pool. Before going ahead and implementing such a pooling mechanism I was wondering 1) is my understanding correct (I am pretty new to both redis and node) and 2) if yes, do you have any plans to add connection pooling - should connection pooling be implemented in the redis client or is it something that the core node connection framework should offer. Any suggestion? [cross posted in the node google groups]
Script code:
GLOBAL.DEBUG = 1; var redis = require("./lib/redis-node-client/redisclient"); var rd_client = new redis.Client(); rd_client.connect(function() { rd_client.mset("blah", 100).addCallback(function() { rd_client.close(); }).addErrback(function(e) { rd_client.close(); }); });
Script output:
--- call: client.mset( 'blah','100' ) command:*3$4mset$4blah$undefined100 --- buffer: +OK-ERR unknown command '0' prefix: + result: [true,5] --- buffer: -ERR unknown command '0' prefix: - result: ["unknown command '0'",26] /Users/koles/tmp/node1/lib/redis-node-client/redisclient.js:246 if (callback.promise) { ^ TypeError: Cannot read property 'promise' of undefined at [object Object].handle_replies (/Users/koles/tmp/node1/lib/redis-node-client/redisclient.js:246:17) at Connection. (/Users/koles/tmp/node1/lib/redis-node-client/redisclient.js:75:12) at node.js:950:9 at node.js:954:1
The following alternatives of rd_client.mset("blah", 100) work correctly:
rd_client.set("blah", 100)
rd_client.mset("blah", 99)
rd_client.mset("blah", "100")
rd_client.mset("blah", 100, "bleh", 99)
OS: Darwin Kernel Version 9.8.0
Tested with all combinations of redis-1.1.95, redis-node-client and master branches of both.
See this script:
Setting dataSize to "1024 * 143" succeeds in running the commands. Setting dataSize to "1024 * 144" or more results in no more responses after command 30, 31, 32, or 33.
I'd like to add a dependency on redis-node-client in npm, but it seems it's not in npm. The package installs cleanly locally, so it would just be a matter of "npm publish ."
Thanks!
A bunch of buffer methods have changed (no more utf8Write or utf8Slice for example). The tests fail with Node as of this commit - http://github.com/ry/node/commit/85fb47c11cc985889be9c1a802cfc0331d8ad7a8 .
I think it's still compatible with the latest stable release though.
To reproduce,
If you remove the "throw e" under the client.maybeReconnect() call in the stream "error" listener, that behaves as expected - a stream of "reconnecting" events followed by a "noconnection" after the maximum reconnect count is reached.
Your test suite didn’t catch this, because it doesn’t actually ensure the callbacks in which the assertions are made are ever executed.
I didn’t know how to fix the problem itself, but I added failing assertions to your test suite:
elliottcable/redis-node-client@329a214474bb34aba7a49a207622d4f20ad201ec
Just an FYI, really, I get the following when I run the tests:
$ node ./test/test.js
.............................................................................................AssertionError: "testBLPOP 2" "ERR unknown command 'blpop'"
at /Users/zach/.node_libraries/redis-node-client/test/test.js:1532:25
at Client.onReply_ (/Users/zach/.node_libraries/redis-node-client/lib/redis-client.js:402:34)
at /Users/zach/.node_libraries/redis-node-client/lib/redis-client.js:158:30
at ReplyParser.feed (/Users/zach/.node_libraries/redis-node-client/lib/redis-client.js:175:55)
at Stream.<anonymous> (/Users/zach/.node_libraries/redis-node-client/lib/redis-client.js:347:28)
at IOWatcher.callback (net:303:16)
at node.js:748:9
Given the environment:
mac os x 10.6.3
node 0.1.91
redis 1.2.6
Thanks,
Zach
Hello,
Using rpush to push a string into redis and lrange to get that string back out. If I use
JSON.stringify(returned_data) I get an array of the ASCII value:
[{"0":112,"1":97,"2":114,"3":116,"4":121,"length":5}] <-- that's the word "party"
code:
http://gist.github.com/375879
node -v 0.1.91
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.