MCE::Shared::Ordhash - Ordered-hash helper class
This document describes MCE::Shared::Ordhash version 1.699_009
# non-shared use MCE::Shared::Ordhash; my $oh = MCE::Shared::Ordhash->new( @pairs ); # shared use MCE::Shared; my $oh = MCE::Shared->ordhash( @pairs ); # oo interface $val = $oh->set( $key, $val ); $val = $oh->get( $key ); $val = $oh->delete( $key ); # del is an alias for delete $bool = $oh->exists( $key ); void = $oh->clear(); $len = $oh->len(); # scalar keys %{ $oh } $len = $oh->len( $key ); # length $oh->{ $key } @pair = $oh->pop(); $len = $oh->push( @pairs ); @pair = $oh->shift(); $len = $oh->unshift( @pairs ); %pairs = $oh->splice( $offset, $length, @pairs ); $oh2 = $oh->clone( @keys ); # @keys is optional $oh3 = $oh->flush( @keys ); $iter = $oh->iterator( @keys ); # ($key, $val) = $iter->() @keys = $oh->keys( @keys ); %pairs = $oh->pairs( @keys ); @vals = $oh->values( @keys ); # vals is an alias for values $cnt = $oh->mdel( @keys ); @vals = $oh->mget( @keys ); $bool = $oh->mexists( @keys ); # true if all keys exists $len = $oh->mset( $key/$val pairs ); # merge is an alias for mset @vals = $oh->sort(); # by val $a <=> $b default @vals = $oh->sort( "desc" ); # by val $b <=> $a @vals = $oh->sort( "alpha" ); # by val $a cmp $b @vals = $oh->sort( "alpha desc" ); # by val $b cmp $a @vals = $oh->sort( "key" ); # by key $a <=> $b @vals = $oh->sort( "key desc" ); # by key $b <=> $a @vals = $oh->sort( "key alpha" ); # by key $a cmp $b @vals = $oh->sort( "key alpha desc" ); # by key $b cmp $a # search capability key/val { =~ !~ eq ne lt le gt ge == != < <= > >= } # query string is quoteless, otherwise quote(s) are treated literally # key/val means to match against actual key/val respectively # do not mix :AND(s) and :OR(s) together @keys = $oh->keys( "key =~ /$pattern/i" ); @keys = $oh->keys( "key !~ /$pattern/i" ); @keys = $oh->keys( "val =~ /$pattern/i" ); @keys = $oh->keys( "val !~ /$pattern/i" ); %pairs = $oh->pairs( "key == $number" ); %pairs = $oh->pairs( "key != $number :AND val > 100" ); %pairs = $oh->pairs( "key < $number :OR key > $number" ); %pairs = $oh->pairs( "val <= $number" ); %pairs = $oh->pairs( "val > $number" ); %pairs = $oh->pairs( "val >= $number" ); @vals = $oh->values( "key eq $string" ); @vals = $oh->values( "key ne $string with space" ); @vals = $oh->values( "key lt $string :OR val =~ /$pat1|$pat2/" ); @vals = $oh->values( "val le $string :AND val eq foo bar" ); @vals = $oh->values( "val gt $string" ); @vals = $oh->values( "val ge $string" ); # sugar methods without having to call set/get explicitly $len = $oh->append( $key, $string ); # $val .= $string $val = $oh->decr( $key ); # --$val $val = $oh->decrby( $key, $number ); # $val -= $number $val = $oh->getdecr( $key ); # $val-- $val = $oh->getincr( $key ); # $val++ $val = $oh->incr( $key ); # ++$val $val = $oh->incrby( $key, $number ); # $val += $number $old = $oh->getset( $key, $new ); # $o = $v, $v = $n, $o
An ordered-hash helper class for use with MCE::Shared.
Several methods in MCE::Shared::Ordhash receive a query string argument. The string is quoteless. Basically, any quotes inside the string will be treated literally.
MCE::Shared::Ordhash
Search capability: =~ !~ eq ne lt le gt ge == != < <= > >= "key =~ /pattern/i :AND val =~ /pattern/i" "key =~ /pattern/i :AND val eq foo bar" # val eq foo bar "val eq foo baz :OR key !~ /pattern/i" key means to match against keys in the hash likewise, val means to match against values :AND(s) and :OR(s) mixed together is not supported
To be completed before the final 1.700 release.
del is an alias for delete.
del
delete
Same as clone. Clears all existing items before returning.
clone
merge is an alias for mset.
merge
mset
vals is an alias for values.
vals
values
This module is equipped with sugar methods to not have to call set and get explicitly. The API resembles a subset of the Redis primitives http://redis.io/commands#strings with key representing the hash key.
set
get
Append a value to a key.
Decrement the value of a key by one and return its new value.
Decrement the value of a key by the given number and return its new value.
Decrement the value of a key by one and return its old value.
Increment the value of a key by one and return its old value.
Set the value of a key and return its old value.
Increment the value of a key by one and return its new value.
Increment the value of a key by the given number and return its new value.
The implementation is inspired by Hash::Ordered.
MCE, MCE::Core, MCE::Shared
Mario E. Roy, <marioeroy AT gmail DOT com>
To install MCE, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MCE
CPAN shell
perl -MCPAN -e shell install MCE
For more information on module installation, please visit the detailed CPAN module installation guide.