can be). ‣In-Memory. Your data should fit in RAM. ‣Values are associated with unique Keys ‣Data Types: Strings, Lists, Sets, Sorted Sets, Hashes ‣Every command is Atomic ‣Keys can be segmented.
can be). ‣In-Memory. Your data should fit in RAM. ‣Values are associated with unique Keys ‣Data Types: Strings, Lists, Sets, Sorted Sets, Hashes ‣Every command is Atomic ‣Keys can be segmented.
C as a PHP Module • https://github.com/phpredis/phpredis • 2600+ Stars • PHP License • Predis: Written in PHP • https://github.com/nrk/predis • 2000+ Stars • MIT License
Periodic Snapshots written to disk ‣ AOF: (append-only file) writes data to disk ‣ None: ONLY stores data in memory. ‣ Both: If you really care about your data, use AOF, with periodic snapshots. For more info, see: http://redis.io/topics/persistence
query the values ‣Keys can be anything (including binary data) ‣…Up to 512Mb ‣Small keys are good! ‣Keys can expire (up to you, you set when) ‣Define a schema: object-type:id:field
‣Examples: Serialized data such as JSON or binary data such as a JPEG image. ‣Redis doesn't care what you store. Key/String values are what typically happens when you use redis as a cache backend (e.g. instead of memcache)
couchdb nosql Updating a Set: SADD blog:11 json # would now include "couchdb", "nosql", "json" Remove an item from a set: SREM blog:11 json # removes the "json" value from the set tags for a blog entry.
returns "nosql", "redis" Does an set contain a given value?: SISMEMBER blog:10 python # returns 0 or 1 Set-based operations: SUNION blog:10 blog:11 # returns "redis", "couchdb", "nosql" SINTER blog:10 blog:11 # returns "nosql" SDIFF blog:10 blog:11 # returns "redis" (in blog:10 but not blog:11)
30 sally ZADD leaders 50 julie ZADD leaders 10 bill Find a rank (default ordering is low to high): ZRANK leaders bill # returns 0 Find a rank (sorted high to low): ZREVRANK leaders bill # returns 2
= array('meaning' => 42); Resque::enqueue('default', 'Calculate', $args); class Calculate{ public function perform() { // Do the work… some_calculation($this->args[‘meaning’]); } }
a message on a Channel ‣Subscribers get the message. ‣Laravel has this built-in. Subscribe to a Channel called messages: SUBSCRIBE messages Publish a message: PUBLISH messages "Hello World!"
a message on a Channel ‣Subscribers get the message. ‣Laravel has this built-in. Subscribe to a Channel called messages: SUBSCRIBE messages Publish a message: PUBLISH messages "Hello World!" Try in multiple terminals.
Redis; // Get a user for a given id $user = Redis::get('user:profile:'.$id); // Set some metric date_default_timezone_set('UTC'); $key = "m:num-logins:d:" . date("Y-m-d"); Redis::set($key, 1); // increment that metric Redis::incr($key);
Redis; // Add some tags to your blog post $key = "blog:" . $postId; $values = Redis::sadd($key, "redis", “php"); // Retrieve those tags $tags = Redis::smembers($key);
to // the Redis CLI $client = new Predis\Client(); // Set some key & retrieve it's value $client->set('my_key', 'Some Value'); $value = $client->get('my_key'); // Returns 'Some Value'
"blogpost:" . $postId; $tags = array("redis", "php", "predis"); $client->lpush($key, $tags); // Get the 2nd tag $client->lindex($key, 1); // Returns 'php' // Get the number of tags $client->llen($key); // Returns 3