Addendum,
On first access, hget(hash, key) retrieves a null value even if the key
exists or even if I flush redis. The second time hget is accessed, it
returns the correct value with no change in code.
Thanks for helping,
Regards
Neeraj
On Sunday, April 27, 2014 9:49:04 PM UTC-7, Neeraj Sharma wrote:
>
> Hi,
>
> I'm trying to develop a web application with node, express and mysql. I'm
> using Redis for SQL caching.
> I wrote this module for caching for my web app and I use these functions
> throughout my project to access redis.
>
> function cache() {
> this.client = redis.createClient();
> this.client.flushall();
> this.stats = {
> hits: 0,
> misses: 0,
> keys: 0
> };
> }
>
> cache.prototype.get = function(hash, key, cb) { //call it as .get(err,
> value)
> if(this.client.hexists(hash, key)) {
> this.stats.hits++;
> this.client.hget(hash, key, function(err, val) {
> if(err) {
> throw err;
> } else {
> cb(null, JSON.parse(val));
> }
> });
> } else {
> this.stats.misses++;
> cb(null, null);
> }
> };
>
> var vlmCache = new cache();
> module.exports.vlmCache = vlmCache;
>
> Other functions I've omitted like invalidate, set etc are omitted from
> this copy paste.
>
> The issue I am facing is that even if the key exists or doesn't exists,
> this.client.hexists result in a true value t he first time it is called.
> Output is correct the second time it is called. I'm unable to figure out
> the problem in it.
>
> In my modules, I require this caching module and use such code to access
> cache.
>
> cache.vlmCache.get("movies", sql, function(err, value) {
> if(value !== null) {
> console.log("got data from cache");
> console.log(JSON.stringify(cache.vlmCache.getStats()));
> res.send(JSON.stringify(value));
> } else {
>
> I tried to create and close the client in my specific module as well, but
> a similar behavior. If I don't use my cache functions, the output is
> correct.
>
> Please suggest.
>
> Regards
> Neeraj
>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.