Skip to content

Commit 08c5ab7

Browse files
committed
Add utility method _serialize()
1 parent d7a99fc commit 08c5ab7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/Redis.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3020,6 +3020,26 @@ public function _prefix( $value ) {}
30203020
*/
30213021
public function _unserialize( $value ) {}
30223022

3023+
/**
3024+
* A utility method to serialize values manually. This method allows you to serialize a value with whatever
3025+
* serializer is configured, manually. This can be useful for serialization/unserialization of data going in
3026+
* and out of EVAL commands as phpredis can't automatically do this itself. Note that if no serializer is
3027+
* set, phpredis will change Array values to 'Array', and Objects to 'Object'.
3028+
* @param mixed $value The value to be serialized.
3029+
* @return mixed
3030+
* @example
3031+
* <pre>
3032+
* $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE);
3033+
* $redis->_serialize("foo"); // returns "foo"
3034+
* $redis->_serialize(Array()); // Returns "Array"
3035+
* $redis->_serialize(new stdClass()); // Returns "Object"
3036+
*
3037+
* $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
3038+
* $redis->_serialize("foo"); // Returns 's:3:"foo";'
3039+
* </pre>
3040+
*/
3041+
public function _serialize( $value ) {}
3042+
30233043
/**
30243044
* Dump a key out of a redis database, the value of which can later be passed into redis using the RESTORE command.
30253045
* The data that comes out of DUMP is a binary representation of the key as Redis stores it.

0 commit comments

Comments
 (0)