PHP code example of pigeonboys / fastsub

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

    

pigeonboys / fastsub example snippets


use PigeonBoys\Fastsub;

Fastsub\SubscriptionConfiguration::initialize(host: '127.0.0.1', port: 6379, database: 0);

use PigeonBoys\Fastsub;

// Set key-value pair in the <serialnumber> hash
Fastsub\SubscriptionQuery::hash('serialnumber')->updateOrCreate('111111', '[{"product":"test-product","ends_at":1738774349}]');

// Set multiple key-value pairs in the <serialnumber> hash
Fastsub\SubscriptionQuery::hash('serialnumber')->upsert([
    '111111' => '[{"product":"test-product","ends_at":1738774349}]',
    '222222' => '[{"product":"test-product","ends_at":1738774349}]',
]);

use PigeonBoys\Fastsub;

// Retrieve the field '111111' from the 'serialnumber' hash
$s = Fastsub\SubscriptionQuery::hash('serialnumber')->field('111111')->get();

// Response:
array:1 [▼
  111111 => "[{"product":"test-product","ends_at":1738774349}]"
]

use PigeonBoys\Fastsub;

// Retrieve the field '111111' from the 'serialnumber' hash as a JSON object
$s = Fastsub\SubscriptionQuery::hash('serialnumber')->field('111111')->json();

// Response:
array:1 [▼
  111111 => array:1 [▼
    0 => array:2 [▼
      "product" => "test-product"
      "ends_at" => 1738774349
    ]
  ]
]

use PigeonBoys\Fastsub;

// Retrieve fields '111111' and '222222' from the 'serialnumber' hash
$s = Fastsub\SubscriptionQuery::hash('serialnumber')->fields(['111111', '222222'])->get();

// Response:
array:2 [▼
  111111 => "[{"product":"test-product","ends_at":1738774349}]"
  222222 => "[{"product":"test-product","ends_at":1738774349}]"
]

use PigeonBoys\Fastsub;

// Retrieve fields '111111' and '222222' from the 'serialnumber' hash as JSON objects
$s = Fastsub\SubscriptionQuery::hash('serialnumber')->fields(['111111', '222222'])->json();

// Response:
array:2 [▼
  111111 => array:1 [▼
    0 => array:2 [▼
      "product" => "test-product"
      "ends_at" => 1738774349
    ]
  ]
  222222 => array:2 [▼
    0 => array:2 [▼
      "product" => "test-product"
      "ends_at" => 1738774349
    ]
  ]
]