kamnev/laravel-redis-helper 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

kamnev/laravel-redis-helper

Composer 安装命令:

composer require kamnev/laravel-redis-helper

包简介

Laravel Redis Helper package of Predis\Predis

README 文档

README

Laravel Redis Helper package of Predis\Predis

Use Redis more effectively with Laravel!

Installation

  composer require kamnev/laravel-redis-helper

Laravel

Add from .env redis settings

  REDIS_HOST=your_redis_host
  REDIS_PASSWORD=your_redis_password
  REDIS_PORT=your_redis_port
  REDIS_CLIENT=predis

Lumen

Add from .env redis settings

  REDIS_HOST=your_redis_host
  REDIS_PASSWORD=your_redis_password
  REDIS_PORT=your_redis_port
  REDIS_CLIENT=predis

Register it in bootstrap/app.php

  $app->register(Illuminate\Redis\RedisServiceProvider::class);

Usage

You can now using the Facades:

RedisString working with strings in Redis:

  1. Method set takes 4 parameters set(string $key, string $value, string $option = "KEEPTTL", int $time = 600) $option supports a set of options that modify its behavior: "EX" or "EXAT" or "PXAT" or "NX" or "XX" or "KEEPTTL" or "GET".
  2. Method get have 1 required parameter key and 1 optional decode if you set json (default = false).
  //Set string value in cache
  RedisString::set('products', json_encode(Product::all()), 'EX', 6000);
  
  //Get decoded products 
  RedisString::get('products', true);

RedisHash working with hash in Redis:

  1. Method getAll - get all values of key. If you set models collection in json, then you can decoded passing the second parameter true (default = false), the fird parameter convert to array or object StdClass return Collection
  2. Method getAllVal - get all values.
  3. Method getAllKeys - get all keys.
  4. Method get - Get value on key. The first parameter is key, the second parameter is field(maybe model id), the third parameter is decoding json data (default = false).
  5. Method set - Set the string value of a hash field.
  6. Method del - Del one or more hash fields. The second parameter can be string or array.
  //Get get all values of key  
  RedisHash::getAll('products', true, true);
  
  //Get all values.
  RedisHash::getAllValue('products', true, true);  
  
  //Get all keys.
  RedisHash::getAllKeys('products');
  
  //Get value on key 
  RedisHash::get('products', 2, true, false);
  
  //Set the string value of a hash field
  RedisHash::set('products', 2, json_encode(Product::find(3)));
  
  //Del one or more hash fields
  RedisHash::del('products', [1,2,3,4, etc..]));

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-03-14