RedisString.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\common\model;
  13. use think\cache\driver\Redis;
  14. class RedisString
  15. {
  16. static private $instance;
  17. static private $handle;
  18. private function __construct(){
  19. self::$handle = (new Redis(config('cache.stores.redis')))->handler();
  20. }
  21. static public function getInstance(){
  22. if(!self::$instance instanceof self){
  23. self::$instance = new self();
  24. }
  25. return self::$instance;
  26. }
  27. //有序集合 添加
  28. public function zAdd($key,$score,$value){
  29. return self::$handle->zAdd($key,$score,$value);
  30. }
  31. //获取有序集合$value当前的排名排名从0开始
  32. public function zRevRank($key,$value){
  33. return self::$handle->zRevrank($key,$value);
  34. }
  35. //获取成员数 Zrangebyscore
  36. public function zRangeByScore($key,$min,$max){
  37. return self::$handle->zRangeByScore($key,(string)$min,(string)$max);
  38. }
  39. //移除指定区别的成员
  40. public function zREMRANGEBYSCORE($key,$min,$max){
  41. return self::$handle->zREMRANGEBYSCORE($key,(string)$min,(string)$max);
  42. }
  43. //查看有序集合指定区间内的成员
  44. public function zRange($key, $start=0, $stop=-1){
  45. return self::$handle->zRANGE($key,$start,$stop);
  46. }
  47. }