Skip to content

cim-engineering/simple-redis-dal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

Simple Redis Abstraction Layer


Installation with composer

Install library via composer

composer require tsk/simple-redis-dal

Initialization

Simple initialization

$db = new hooli("127.0.0.0", "password");

Check if eveything works

Simple check

$db->ping();

Handling simple values

Set a value

$key = "username";
$db->setvalue($key, "MaryPoppins");

Get the value

$username = $db->getvalue($key);

Delete a value

$key = "username";
$db->delete($key);

Cache a value

$key = "session_id";
$value = "12345";
$time = 20 // Time is in minutes

$db->cachevalue($key, $value, $time);

Expire a value

$key = "session_id";
$time = 1 // Time in minutes

$db->expire($key, $time);

Dealing with Hashes

Create a hash / Store data into a hash (record types structured as collections of field-value pairs)

$data = [
    "firstName" => "Mary",
    "lastName" => "Poppins",
    "email" => "marypoppins@email.com",
    "location" => "USA, New York"
];
$HashName = 'marypoppins@email.com';
$db->createhash($HashName, $data);

Check if a value exists in a hash

$HashName = 'marypoppins@email.com';
$db->checkhash($HashName, "firstName");

Update / replace a single value in a hash

$HashName = 'marypoppins@email.com';
$db->replacehash($HashName, "location", "Nigeria, Lagos");

Insert new value into hash

$HashName = 'marypoppins@email.com';
$db->inserthash($HashName, "age", 32);

Fetch all values in a single hash

$HashName = 'marypoppins@email.com';
$db->gethash($HashName);

or using return types
$db->json()->gethash($HashName);

Count the keys in a hash

$HashName = 'marypoppins@email.com';
$count = $db->countkeys($HashName);

Increase a value in a hash

$HashName = 'marypoppins@email.com';
$key = 'age'; // The value of this key must be an integer
$increaseBy = 4;
$db->increase($HashName, $key); // This method increases the value by one
$db->increaseby($HashName, $key, $increaseBy); // This method increases the value by the specified number 

Dealing with lists

Insert value into a list

$List = "users";
$db->insertlist($List, "something@email.com");

search for a value inside a list

$List = "users";
if($db->search_list($List, "something@email.com")){
    echo 'value exists';
}

Count number of values /entries in a List

$List = "users";
$db->countlist($List);

Delete a List

$List = "users";
$db->deletelist($List);

Return all values in a List as JSON return type

$List = "users";
$db->json()->getlist($List);

Get a specific number of elements from a list

$List = "users";
$num = 10;
$users = $db->getlistnum($List, $num); // Returns an array

Dealing with HashLists

Save hashes to list (HashList) while mapping each value in list to key in hash

$data = [
    "firstName" => "Mary",
    "lastName" => "Poppins",
    "email" => "marypoppins@email.com",
    "location" => "USA, New York"
];
$list = "users";
$userID = "mary123";
$db->inserthashlist($userID, $data, $list);

Return all data in a HashList as json

$list = "users";
echo $db->gethashlist($list);

fetching specified number of keys in a list

list Name of the Redis list num is asigned the number of keys to be fetched

echo $db->getlistnum($list, $num)

Fetching specified number of hashes

list Name of the Redis list num reperesents the number of hashes to fetch from a list

echo $db->gethashlistnum($list, $num)

Collaborators ✨

timek
Tim3k
kusaasira
Joshua Kusaasira
Marshud
Marshud

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages