Rediska

Follow me on twitter…

Hashes

This key type allows you to store hashes and is similar to associative array in PHP:

<?php

// Initialize Rediska
$rediska = new Rediska();

// Initialize hash
$user = new Rediska_Key_Hash('user');

// Set field as object properties
$user->firstName = 'John';

// Fields accessible as array keys
$user['lastName'] = 'Silver';

// Get field value
print $user->firstName; #=> 'Silver'

// Remove field
unset($user->firstName);

// Check if field is set
if (!isset($user->firstName)) {
    // Set several fields at a time
    $user->set(array('firstName' => 'John', 'lastName' => 'Silver', 'viewed' => 1));
}

// Get fields count
print count($user); #=> 2

// Increment field's value
$user->increment('viewed');

// Iterate hash
foreach($user as $field => $value) {
    print "$field => $value";
}

?>

See all available methods.

Comments

Alex November 08, 2011 11:50

print $user->firstName; #=> 'Silver'

no, it yelds in 'John' :)

Fork me on GitHub