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

NAME

Zing::Redis - Redis Storage

ABSTRACT

Redis Storage Abstraction

SYNOPSIS

  use Zing::Redis;

  my $redis = Zing::Redis->new;

  # $redis->drop;

DESCRIPTION

This package provides a Redis adapter for use with data storage abstractions.

LIBRARIES

This package uses type constraints from:

Zing::Types

ATTRIBUTES

This package has the following attributes:

client

  client(Redis)

This attribute is read-only, accepts (Redis) values, and is optional.

METHODS

This package implements the following methods:

drop

  drop(Str $key) : Int

The drop method removes (drops) the item from the datastore.

drop example #1
  # given: synopsis

  $redis->drop('model');

dump

  dump(HashRef $data) : Str

The dump method encodes and returns the data provided as JSON.

dump example #1
  # given: synopsis

  $redis->dump({ status => 'ok' });

keys

  keys(Str @keys) : ArrayRef[Str]

The keys method returns a list of keys under the namespace of the datastore or provided key.

keys example #1
  # given: synopsis

  my $keys = $redis->keys('nodel');
keys example #2
  # given: synopsis

  $redis->send('model', { status => 'ok' });

  my $keys = $redis->keys('model');

load

  load(Str $data) : HashRef

The load method decodes the JSON data provided and returns the data as a hashref.

load example #1
  # given: synopsis

  $redis->load('{"status":"ok"}');

pop

  pop(Str $key) : Maybe[HashRef]

The pop method pops data off of the bottom of a list in the datastore.

pop example #1
  # given: synopsis

  $redis->pop('collection');
pop example #2
  # given: synopsis

  $redis->push('collection', { status => 1 });
  $redis->push('collection', { status => 2 });

  $redis->pop('collection');

pull

  pull(Str $key) : Maybe[HashRef]

The pull method pops data off of the top of a list in the datastore.

pull example #1
  # given: synopsis

  $redis->pull('collection');
pull example #2
  # given: synopsis

  $redis->push('collection', { status => 'ok' });

  $redis->pull('collection');

push

  push(Str $key, HashRef $val) : Int

The push method pushed data onto the bottom of a list in the datastore.

push example #1
  # given: synopsis

  $redis->push('collection', { status => 'ok' });
push example #2
  # given: synopsis

  $redis->push('collection', { status => 'ok' });

  $redis->push('collection', { status => 'ok' });

recv

  recv(Str $key) : Maybe[HashRef]

The recv method fetches and returns data from the datastore by its key.

recv example #1
  # given: synopsis

  $redis->recv('model');
recv example #2
  # given: synopsis

  $redis->send('model', { status => 'ok' });

  $redis->recv('model');

send

  send(Str $key, HashRef $val) : Str

The send method commits data to the datastore with its key and returns truthy.

send example #1
  # given: synopsis

  $redis->send('model', { status => 'ok' });

size

  size(Str $key) : Int

The size method returns the size of a list in the datastore.

size example #1
  # given: synopsis

  my $size = $redis->size('collection');
size example #2
  # given: synopsis

  $redis->push('collection', { status => 'ok' });

  my $size = $redis->size('collection');

slot

  slot(Str $key, Int $pos) : Maybe[HashRef]

The slot method returns the data from a list in the datastore by its index.

slot example #1
  # given: synopsis

  my $model = $redis->slot('collection', 0);
slot example #2
  # given: synopsis

  $redis->push('collection', { status => 'ok' });

  my $model = $redis->slot('collection', 0);

term

  term(Str @keys) : Str

The term method generates a term (safe string) for the datastore.

term example #1
  # given: synopsis

  $redis->term('model');

test

  test(Str $key) : Int

The test method returns truthy if the specific key (or datastore) exists.

test example #1
  # given: synopsis

  $redis->push('collection', { status => 'ok' });

  $redis->test('collection');
test example #2
  # given: synopsis

  $redis->drop('collection');

  $redis->test('collection');

AUTHOR

Al Newkirk, awncorp@cpan.org

LICENSE

Copyright (C) 2011-2019, Al Newkirk, et al.

This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated in the "license file".

PROJECT

Wiki

Project

Initiatives

Milestones

Contributing

Issues