The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MCE::Shared::Minidb - A fast, pure-Perl in-memory data structure store

VERSION

This document describes MCE::Shared::Minidb version 1.699_009

SYNOPSIS

   # non-shared
   use MCE::Shared::Minidb;

   my $db = MCE::Shared::Minidb->new();

   # shared
   use MCE::Shared;

   my $db = MCE::Shared->minidb();

   # HoH
   $db->hset('key1', 'f1', 'foo');
   $db->hset('key2', 'f1', 'bar', 'f2', 'baz');

   $val = $db->hget('key2', 'f2');  # 'baz'

   # HoA
   $db->lset('key1', 0, 'foo');
   $db->lset('key2', 0, 'bar', 1, 'baz');

   $val = $db->lget('key2', 1);     # 'baz'

DESCRIPTION

A simplistic in-memory NoSQL-like DB for use with MCE::Shared. Although several methods resemble the Redis API, it is not the intent for this module to become 100% compatible with it.

QUERY STRING

Several methods in MCE::Shared::Minidb receive a query string argument. The string is quoteless. Basically, any quotes inside the string will be treated literally.

   Search capability: =~ !~ eq ne lt le gt ge == != < <= > >=
  
   "key =~ /pattern/i :AND field =~ /pattern/i"
   "key =~ /pattern/i :AND index =~ /pattern/i"
   "key =~ /pattern/i :AND field eq foo bar"     # address eq foo bar
   "index eq foo baz :OR key !~ /pattern/i"      # 9 eq foo baz

      key   means to match against keys in the hash (H)oH or (H)oA
      field means to match against HoH->{key}->{field}; e.g. address
      index means to match against HoA->{key}->[index]; e.g. 9

   Keys in hash may have spaces, but not in field names Ho(H).
   :AND(s) and :OR(s) mixed together is not supported.

The select_aref and select_href methods receive a select string allowing one to specify field names and sort directives.

   "f1 f2 f3 :WHERE f4 > 20 :AND key =~ /foo/ :ORDER BY f5 DESC ALPHA"
   "f1 f2 f3 :where f4 > 20 :and key =~ /foo/ :order by f5 desc alpha"

   "f5 f1 f2 :WHERE fN > 40 :AND key =~ /bar/ :ORDER BY key ALPHA"
   "f5 f1 f2 :where fN > 40 :and key =~ /bar/ :order by key alpha"

   "f5 f1 f2 :WHERE fN > 40 :AND key =~ /bar/"
   "f5 f1 f2 :where fN > 40 :and key =~ /bar/"

   "f5 f1 f2"

The shorter form without field names is allowed for HoA.

   "4 > 20 :and key =~ /baz/"  4 is the array index
  

API DOCUMENTATION - HASHES ( HoH )

To be completed before the final 1.700 release.

hset ( key, field, value [, field, value, ... ] )
hget ( key, field [, field, ... ] )
hget ( key )
hdel ( key, field [, field, ... ] )
hdel ( key )
hexists ( key, field [, field, ... ] )
hexists ( key )
hclear ( key )
hclear
hkeys ( key, field [, field, ... ] )
hkeys ( "query string" )
hkeys
hvals ( key, field [, field, ... ] )
hvals ( "query string" )
hvals
hpairs ( key, field [, field, ... ] )
hpairs ( "query string" )
hpairs
hsort ( "BY key [ ASC | DESC ] [ ALPHA ]" )
hsort ( "BY field [ ASC | DESC ] [ ALPHA ]" )
happend ( key, field, string )
hdecr ( key, field )
hdecrby ( key, field, number )
hincr ( key, field )
hincrby ( key, field, number )
hgetdecr ( key, field )
hgetincr ( key, field )
hgetset ( key, field, value )
hlen ( key, field )
hlen ( key )
hlen

API DOCUMENTATION - LISTS ( HoA )

lset ( key, index, value [, index, value, ... ] )
lget ( key, index [, index, ... ] )
lget ( key )
ldel ( key, index [, index, ... ] )
ldel ( key )
lexists ( key, index [, index, ... ] )
lexists ( key )
lclear ( key )
lclear
lrange ( key, start, stop )
lsplice ( key, offset, length [, list ] )
lpop ( key )
lpush ( key, value [, value, ... ] )
rpop ( key )
rpush ( key, value [, value, ... ] )
lkeys ( key, index [, index, ... ] )
lkeys ( "query string" )
lkeys
lvals ( key, index [, index, ... ] )
lvals ( "query string" )
lvals
lpairs ( key, index [, index, ... ] )
lpairs ( "query string" )
lpairs
lsort ( "BY key [ ASC | DESC ] [ ALPHA ]" )
lsort ( "BY index [ ASC | DESC ] [ ALPHA ]" )
lsort ( key, "BY key [ ASC | DESC ] [ ALPHA ]" )
lsort ( key, "BY val [ ASC | DESC ] [ ALPHA ]" )
lappend ( key, index, string )
ldecr ( key, index )
ldecrby ( key, index, number )
lincr ( key, index )
lincrby ( key, index, number )
lgetdecr ( key, index )
lgetincr ( key, index )
lgetset ( key, index, value )
llen ( key, index )
llen ( key )
llen

COMMON API

new

Constructs an empty Minidb object.

dump ( "file.dat" )

Dumps the content to a file.

restore ( "file.dat" )

Restores the content from a file.

iterator ( ":hashes", "query string" )
iterator ( ":hashes" )

Returns a code reference that returns a single key => href pair.

iterator ( ":hashes", key, "query string" )
iterator ( ":hashes", key [, key, ... ] )

Returns a code reference that returns a single key => value pair.

iterator ( ":lists", "query string" )
iterator ( ":lists" )

Returns a code reference that returns a single key => aref pair.

iterator ( ":lists", key, "query string" )
iterator ( ":lists", key [, key, ... ] )

Returns a code reference that returns a single key => value pair.

select_aref ( ":hashes", "select string" )
select_aref ( ":lists", "select string" )

Returns [ key, aref ] pairs.

select_href ( ":hashes", "select string" )
select_href ( ":lists", "select string" )

Returns [ key, href ] pairs.

CREDITS

The implementation is inspired by various Redis Hash/List primitives at http://redis.io/commands.

INDEX

MCE, MCE::Core, MCE::Shared

AUTHOR

Mario E. Roy, <marioeroy AT gmail DOT com>