PHP code example of jsidorenko / redcard

1. Go to this page and download the library: Download jsidorenko/redcard 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/ */

    

jsidorenko / redcard example snippets


    $redis = new Predis\Client(array(
        'scheme' => 'tcp',
        'host'   => 'localhost',
        'port'   => 6379,
    ));

    $autocomplete = new JSidorenko\RedCard\RedisAutocomplete( $redis );
    or
    $autocomplete = new JSidorenko\RedCard\RedisAutocomplete( $redis, "yourDomainPrefix" );

    instead of "yourDomainPrefix" you can write something like "users" or "locations"


$autocomplete->store(2, "cat");
$autocomplete->store(3, "care");
$autocomplete->store("MYCRAZYID", "caress");
$autocomplete->store(55, "cars");
$autocomplete->store(6, "camera");

$results = $autocomplete->find("car");

var_dump($results)



$autocomplete->store(2, "Mary", "users");
$autocomplete->store(3, "Sally", "users");
$autocomplete->store(4, "Leo", "users" );

$autocomplete->store(5, "Mary Had A Litte Lamb", "blog-title");
$autocomplete->store(6, "Redis Rocks, A Life Story", "blog-title");

$results = $autocomplete->find("Mary", "users");

// Will only return Mary instead of "Mary Had A Litte Lamb"


	    store($id, $phrase, $bin = '', $score = 1, $data = NULL)
	

	    $autocomplete->store('id123', "Clockwork Orange", "Books", 3, array('author'=>'Anthony Burgess'))
	

	    find($phrase, $bin = '', $count = 10, $isCaching = true)
	

	    $autocomplete->find("Clock", "Books", 1, true)
	

	    findByID($id, $bin = '')
	

	    $autocomplete->findByID('id123')
	

	    remove($id, $bin = '')
	

	    $autocomplete->remove('id123', 'Books')
	

	    clear()
	

	    $autocomplete->clear()