What is the best way to store an object in redis?

I have a class that is modeled as follows: all member variables are composed of strings and integers.

> class XYZ extends CFormModel
    {
    //Values required for rendering the Dashboard
    public $username;
    public $analysis_type;
    public $trace_selection;
    public $filter_phantoms;
    public $trace_oui_map;
    public $frame_min;
    public $frame_max;
    public $time_end;
    public $frame_range;
    public $time_range;
    //Other Values
    private $RETURNURL;
    private $PARAMS;
    private $connection;        // connection to db client
    private $database;          // handle to database
    private $col_trace_info;    // handle to trace_info collection
    private $col_csv;           // handle to csv collection
    ...
    ...

I want to store this object of this class in the redis cache for better performance. The solutions I stumbled upon is to use hashmaps.

Yii::app()->cache()->executeCommand("HSET", array("KEY"=>$hashMap, "FIELD"=>$key, "VALUE"=>$object));

My question is, is there a better way to store an object in memory using any other data structure or serialize it before storing or something like that?

+4
source share
1 answer

Hash ( ), . - -redis Redis. , - .

:

  • messagepack.
  • Hash Set, . -: . get/set .
  • , "" , " " "-". . 2.8.9 +: : 0, msgpack /searchstring ( , \t ) ZRANGEBYLEX.
  • , messagepack, 1000 () Lua script .

.

, , TW

+8

Source: https://habr.com/ru/post/1540194/


All Articles