Using Redis as a Caching Layer

Using Redis as a Caching Layer


Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.

  • Share on Pinterest

So he got out of the fury of the panic, and, skirting the Edgware Road, reached Edgware about seven, fasting and wearied, but well ahead of the crowd. Along the road people were standing in the roadway, curious, wondering. He was passed by a number of cyclists, some horsemen, and two motor cars.

Node Driver

Once Toto got too near the open trap door, and fell in; and at first the girl thought she had lost him. But soon she saw one of his ears sticking up through the hole, for the strong pressure of the air was keeping him up.

const redis = require("redis");
const client = redis.createClient();

client.hkeys("hash key", function (err, replies) {
    console.log(replies.length + " replies:");
    replies.forEach(function (reply, i) {
        console.log("    " + i + ": " + reply);
    });
    client.quit();
});

She crept to the hole, caught Toto by the ear, and dragged him into the room again, afterward closing the trap door so that no more accidents could happen.

Ruby Driver

The Dormouse again took a minute or two to think about it, and then said, ‘It was a treacle-well.’ ‘There’s no such thing!’ Alice was beginning very angrily, but the Hatter and the March Hare went ‘Sh! sh!’ and the Dormouse sulkily remarked, ‘If you can’t be civil, you’d better finish the story for yourself.’ ‘No, please go on!’ Alice said very humbly; ‘I won’t interrupt again. I dare say there may be ONE.’ ‘One, indeed!’ said the Dormouse indignantly. However, he consented to go on.

Then he began to look out for a chance of edging to the right across the road. But once in the stream he seemed to lose volition, to become a part of that dusty rout. They swept through Chipping Barnet with the torrent.

redis = Redis.new(:host => "10.0.1.1", :port => 6380, :db => 15)

redis.set("mykey", "hello world")
redis.get("mykey")

redis.pipelined do
    @set = redis.set "foo", "bar"
    @incr = redis.incr "baz"
end

They were nearly a mile beyond the centre of the town before they had fought across to the opposite side of the way. It was din and confusion indescribable; but in and beyond the town the road forks repeatedly, and this to some extent relieved the stress.

PHP Driver

Dismounting, I laid Powell upon the ground, but the most painstaking examination failed to reveal the faintest spark of life. I forced water from my canteen between his dead lips, bathed his face and rubbed his hands, working over him continuously for the better part of an hour in the face of the fact that I knew him to be dead.

I was very fond of Powell; he was thoroughly a man in every respect; a polished southern gentleman; a staunch and true friend; and it was with a feeling of the deepest grief that I finally gave up my crude endeavors at resuscitation.

include("retwis.php");

$r = redisLink();
$userid = $r->hget("users", $username);

if (!$userid)
    goback("Wrong username or password");
    $realpassword = $r->hget("user:$userid","password");
    if ($realpassword != $password)
        goback("Wrong useranme or password");

Fix decided that he must warn the English authorities, and signal the Rangoon before her arrival. This was easy to do, since the steamer stopped at Singapore, whence there is a telegraphic wire to Hong Kong. He finally resolved, moreover, before acting more positively, to question Passepartout.

C++ Driver

Once Toto got too near the open trap door, and fell in; and at first the little girl thought she had lost him. But soon she saw one of his ears sticking up through the hole, for the strong pressure of the air was keeping him up so that he could not fall.

int main() {
    CRedisClient redisCli;
    if (!redisCli.Initialize("127.0.0.1", 6379, 2, 10)) {
        std::cout << "connect to redis failed" << std::endl;
        return -1;
    }

    std::string strKey = "key_1";
    std::string strVal;
    if (redisCli.Get(strKey, &strVal) == RC_SUCCESS) {
        std::cout << "key_1 has value " << strVal << std::endl;
        return 0;
    } else {
        std::cout << "request failed" << std::endl;
        return -1;
    }
}

She crept to the hole, caught Toto by the ear, and dragged him into the room again, afterward closing the trap door so that no more accidents could happen.

Other Options

Then he began to look out for a chance of edging to the right across the road. But once in the stream he seemed to lose volition, to become a part of that dusty rout. They swept through Chipping Barnet with the torrent; they were nearly a mile beyond the centre of the town before they had fought across to the opposite side of the way.