承接 mjohann/simple-redis 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mjohann/simple-redis

最新稳定版本:v1.1.0

Composer 安装命令:

composer require mjohann/simple-redis

包简介

Simple Redis is a PHP class that provides a practical and reusable abstraction for working with Redis. It allows you to easily create connections and perform common operations such as set, get, del, list, pub, sub and many others, without worrying about the underlying configuration complexity.

README 文档

README

SimpleRedis is a PHP class that offers a practical and reusable abstraction for working with Redis. It allows you to easily establish connections and perform common operations, as outlined in the features section — all without the need to worry about the underlying configuration complexity.

📦 Installation

You can install the library via Packagist/Composer:

composer require mjohann/simple-redis

⚙️ Requirements

  • PHP 8.0 or higher

🚀 Features

  • SimpleRedis uses predis/predis as a dependency
  • Supported:
    • set
    • get
    • del
    • list
    • pub
    • sub

🧪 Usage Example

<?php

require_once "vendor/autoload.php";

use MJohann\Packlib\SimpleRedis;

// Create and configure a Redis connection
$redis = new SimpleRedis();
$redis->open();

// SET: Store the key "key" with the value "value" and a TTL (Time To Live) of 60 seconds
echo "Set: ";
var_dump($redis->set("key", "value", 60));
echo PHP_EOL, PHP_EOL;

// GET: Retrieve the value associated with the key "key"
echo "Get: ";
var_dump($redis->get("key"));
echo PHP_EOL, PHP_EOL;

// Wait 10 seconds before deleting the key
sleep(10);

// DEL: Delete the key "key" from Redis
echo "Del: ";
var_dump($redis->del("key"));
echo PHP_EOL, PHP_EOL;

// Define the key for the RPUSH list
$keyListRPUSH = "list:names_RPUSH";

// RPUSH: Add elements to the end (right) of the list
echo "List RPUSH: ";
var_dump($redis->listPush($keyListRPUSH, "Matheus", "r"));
echo PHP_EOL, PHP_EOL;

echo "List RPUSH: ";
var_dump($redis->listPush($keyListRPUSH, "Johann", "r"));
echo PHP_EOL, PHP_EOL;

echo "List RPUSH: ";
var_dump($redis->listPush($keyListRPUSH, "Araújo", "r"));
echo PHP_EOL, PHP_EOL;

// Update the value at index 0 in the list
echo "List set: ";
var_dump($redis->listSet($keyListRPUSH, 0, "Matheus Johann"));
echo PHP_EOL, PHP_EOL;

// Wait 5 seconds
sleep(5);

// Remove the element "Johann" from the list
echo "List remove: ";
var_dump($redis->listRemove($keyListRPUSH, "Johann"));
echo PHP_EOL;

// Define the key for the LPUSH list
$keyList = "list:names_LPUSH";

// LPUSH: Add elements to the beginning (left) of the list
echo "List LPUSH: ",
var_dump($redis->listPush($keyList, "Matheus"));
echo PHP_EOL, PHP_EOL;

echo "List LPUSH: ",
var_dump($redis->listPush($keyList, "Johann"));
echo PHP_EOL, PHP_EOL;

echo "List LPUSH: ",
var_dump($redis->listPush($keyList, "Araújo"));
echo PHP_EOL, PHP_EOL;

// LLEN: Get the total number of elements in the list
echo "List size: ";
var_dump($redis->listSize($keyList));
echo PHP_EOL, PHP_EOL;

// LINDEX: Retrieve the element at index 0
echo "List index [0]: ";
var_dump($redis->listIndex($keyList, 0));
echo PHP_EOL, PHP_EOL;

// LRANGE: Retrieve all elements from the list
echo "List all: ";
var_dump($redis->listAll($keyList));
echo PHP_EOL;

// Wait 5 seconds
sleep(5);

// LPOP: Remove and print one element from the beginning of the list every 5 seconds
echo "Popping list items..." . PHP_EOL;
while (($value = $redis->listPop($keyList)) !== null) {
    var_dump($value);
    echo PHP_EOL, PHP_EOL;
    sleep(5);
}

// Delete the entire list
echo "Del: ";
var_dump($redis->del($keyListRPUSH));
echo PHP_EOL, PHP_EOL;

// Close the Redis connection
$redis->close();

For more examples, see the example/ file in the repository.

📁 Project Structure

simple-redis/
├── src/
│   └── SimpleRedis.php
│   └── Facades/
│       └── SimpleRedis.php
├── example/
│   └── docker-compose.yml
│   └── script.php
│   └── sub.php
│   └── pub.php
├── composer.json
├── .gitignore
├── LICENSE
└── README.md

📄 License

This project is licensed under the MIT License. See the LICENSE file for more information.

👨‍💻 Author

Developed by Matheus Johann Araújo – Pernambuco, Brazil.

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固