PHP code example of adammbalogh / key-value-store

1. Go to this page and download the library: Download adammbalogh/key-value-store library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

adammbalogh / key-value-store example snippets



use AdammBalogh\KeyValueStore\KeyValueStore;
use AdammBalogh\KeyValueStore\Adapter\RedisAdapter as Adapter;
use Predis\Client as RedisClient;

$redisClient = new RedisClient();

$adapter = new Adapter($redisClient);

$kvs = new KeyValueStore($adapter);

$kvs->set('sample_key', 'Sample value');
$kvs->get('sample_key');
$kvs->delete('sample_key');

/**
 * Removes a key.
 *
 * @param string $key
 *
 * @return bool True if the deletion was successful, false if the deletion was unsuccessful.
 *
 * @throws \InvalidArgumentException
 * @throws InternalException
 */
public function delete($key);

/**
 * Sets a key's time to live in seconds.
 *
 * @param string $key
 * @param int $seconds
 *
 * @return bool True if the timeout was set, false if the timeout could not be set.
 *
 * @throws \InvalidArgumentException
 * @throws InternalException
 */
public function expire($key, $seconds);

/**
 * Returns the remaining time to live of a key that has a timeout.
 *
 * @param string $key
 *
 * @return int Ttl in seconds.
 *
 * @throws \InvalidArgumentException
 * @throws KeyNotFoundException
 * @throws InternalException
 */
public function getTtl($key);

/**
 * Determines if a key exists.
 *
 * @param string $key
 *
 * @return bool True if the key does exist, false if the key does not exist.
 *
 * @throws \InvalidArgumentException
 * @throws InternalException
 */
public function has($key);

/**
 * Removes the existing timeout on key, turning the key from volatile (a key with an expire set)
 * to persistent (a key that will never expire as no timeout is associated).
 *
 * @param string $key
 *
 * @return bool True if the persist was success, false if the persis was unsuccessful.
 *
 * @throws \InvalidArgumentException
 * @throws InternalException
 */
public function persist($key);

/**
 * Gets the value of a key.
 *
 * @param string $key
 *
 * @return mixed The value of the key.
 *
 * @throws \InvalidArgumentException
 * @throws KeyNotFoundException
 * @throws InternalException
 */
public function get($key);

/**
 * Sets the value of a key.
 *
 * @param string $key
 * @param mixed $value Can be any of serializable data type.
 *
 * @return bool True if the set was successful, false if it was unsuccessful.
 *
 * @throws \InvalidArgumentException
 * @throws InternalException
 */
public function set($key, $value);

/**
 * Removes all keys.
 *
 * @return void
 *
 * @throws \AdammBalogh\KeyValueStore\Exception\InternalException
 */
public function flush();