Download the PHP package juniora/laravel-redis-paginator without Composer

On this page you can find all versions of the php package juniora/laravel-redis-paginator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-redis-paginator

Laravel Redis Sorted Set Paginator

Latest Version on Packagist GitHub Tests Action Status Total Downloads

Ever wanted to display paginated sorted sets at scale? A great example of this would be a leaderboard for a game, or for a website with a large userbase. This package will create a Laravel LengthAwarePaginator from a Redis sorted set. As a sorted set, by definition, is always sorted, it allows a large number of records to be paginated, with very little overhead.

Installation

You can install the package via composer:

Usage

Initialise the paginator by using dependency injection or the provided RedisPaginator facade. The example below will interact with the leaderboard sorted set. We leverage Laravel's Redis interface, which will honour any prefixing and clustering options that you have configured on your application.

Here is an example of a paginated sorted set in action:

Sorting

The sortAsc and sortDesc methods allow you to choose the order of the returned results. The default sorting is in ascending order.

Get the rank and page for a user

You may want to display the user's rank in the sorted set, as well as a link to jump to the page that contains their name. This can be achieved by using the rank() method. A MemberRank object will be returned which contains the score, rank, and page properties:

Using the facade

For those of you who prefer facades over dependency injection, that option is also available:

Selecting a page to view

The current page can be set by using the page() method, or by using the method parameters. Under the hood, the package uses Laravel's default Paginator's page resolution, which means that the page can also be specified via the query string.

Resolving Eloquent models

Given that Redis an in-memory data structure store, and not a relational database, it is very likely that the real data relating to your paginated data (leaderboard?) is not wholly stored in Redis. This data will need to be loaded once you have fetched your paginated results, and this package will handle that for you.

In this example, we assume that you have stored your data in the following format:

member score Eloquent ID
user:1 100 1
user:2 200 2
user:3 300 3

First, create a Redis resolver. This can be placed anywhere your application, such as app/RedisResolvers/UserResolver.php.

The $modelKey property should correspond to the key that you are using to generate your Redis members. This will generally be id or uuid. The $scoreField property defines the field that will be mapped onto your Eloquent model, or merged into your results array.

The resolveKey() method will take a single key (Redis member), and allow you to transform it. In the example above, we are stripping user: from the string, before casting it to an integer.

You can then define resolveModels() that accepts an array of resolved keys to be queried.

Finally, we must set our model resolver before running the query:

We can now access our full User model, as well as the score that has been loaded from Redis:

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-redis-paginator with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/redis Version ^8.0|^9.0|^10.0|^11.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package juniora/laravel-redis-paginator contains the following files

Loading the files please wait ....