Làm cách nào để thêm Redis trong PHP?
Tiện ích mở rộng phpredis cung cấp API để giao tiếp với kho lưu trữ khóa-giá trị Redis. Nó được phát hành theo Giấy phép PHP, phiên bản 3. 01. Mã này đã được Owlient phát triển và duy trì từ tháng 11 năm 2009 đến tháng 3 năm 2011 Show
Bạn có thể gửi nhận xét, bản vá lỗi, câu hỏi tại đây trên github, tới michael. máy xay @ gmail. com (Twitter, Mastodon), p. yatsukhnenko@gmail. com (@yatsukhnenko), or n. favrefelix@gmail. com (@yowgi) Tài liệu APIĐây là một công việc đang được tiến hành, nhưng cuối cùng sẽ thay thế MỘT README ĐỂ QUY ĐỊNH TẤT CẢ các tài liệu của chúng tôi Hỗ trợ dự ánPhpRedis sẽ luôn là phần mềm nguồn mở và miễn phí, nhưng nếu bạn hoặc công ty của bạn thấy nó hữu ích, vui lòng cân nhắc hỗ trợ dự án. Việc phát triển một thư viện lớn, phức tạp và hiệu quả như PhpRedis cần rất nhiều thời gian và công sức, và sự hỗ trợ sẽ được đánh giá cao. ❤️ Cách tốt nhất để hỗ trợ dự án là thông qua các nhà tài trợ GitHub. Nhiều bậc phần thưởng cấp quyền truy cập vào kênh chùng của chúng tôi, nơi tôi và Pavlo thường xuyên có mặt để trả lời các câu hỏi. Ngoài ra, điều này sẽ cho phép bạn cung cấp phản hồi về các bản sửa lỗi và tính năng mới cần ưu tiên Bạn cũng có thể đóng góp một lần với nhà tài trợTable of contentsInstalling/Configuring InstallationFor everything you should need to install PhpRedis on your system, see the INSTALL. md page PHP Session handlerphpredis can be used to store PHP sessions. To do this, configure 12 and 13 in your php. ini to tell phpredis where to store the sessions
13 can have a simple 15 format too, but you need to provide the 16 scheme if you want to use the parameters. The following parameters are available
Sessions have a lifetime expressed in seconds and stored in the INI variable "session. gc_maxlifetime". Bạn có thể thay đổi nó bằng 17. Trình xử lý phiên yêu cầu phiên bản Redis hỗ trợ các tùy chọn 18 và 19 của lệnh 20 (ít nhất 2. 6. 12). phpredis cũng có thể kết nối với một ổ cắm tên miền unix. 21khóa phiênỦng hộ. Tính năng khóa hiện chỉ được hỗ trợ cho thiết lập Redis với phiên bản chính duy nhất (e. g. môi trường Sentinel chính/nô lệ cổ điển). Vì vậy, khóa có thể không hoạt động bình thường trong môi trường RedisArray hoặc RedisCluster Các biến INI sau có thể được sử dụng để định cấu hình khóa phiên
Running the unit testsphpredis uses a small custom unit test suite for testing functionality of the various classes. Để chạy thử nghiệm, chỉ cần làm như sau
Note that it is possible to run only tests which match a substring of the test itself by passing the additional argument '--test ' when invoking Classes and methodsUsageClass RedisDescription. Creates a Redis client Example$redis = new Redis(); Starting from version 6. 0. 0 it's possible to specify configuration options. This allows to connect lazily to the server without explicitly invoking 22 commandExample$redis = new Redis([ 'host' => '127.0.0.1', 'port' => 6379, 'connectTimeout' => 2.5, 'auth' => ['phpredis', 'phpredis'], 'ssl' => ['verify_peer' => false], 'backoff' => [ 'algorithm' => Redis::BACKOFF_ALGORITHM_DECORRELATED_JITTER, 'base' => 500, 'cap' => 750, ], ]); Parametershost. chuỗi. can be a host, or the path to a unix domain socket Class RedisExceptionphpredis throws a object if it can't reach the Redis server. That can happen in case of connectivity issues, if the Redis service is down, or if the redis host is overloaded. In any other problematic case that does not involve an unreachable server (such as a key not existing, an invalid command, etc), phpredis will return 23Predefined constantsDescription. Available Redis Constants Redis data types, as returned by
@TODO. OPT_SERIALIZER, AFTER, BEFORE, Connection
connect, openDescription. Kết nối với một phiên bản Redis Parametershost. string. can be a host, or the path to a unix domain socket. Starting from version 5. 0. 0 it is possible to specify schema Return valueBOOL. 24 on success, 23 on errorExample$redis->connect('127.0.0.1', 6379); $redis->connect('127.0.0.1'); // port 6379 by default $redis->connect('tls://127.0.0.1', 6379); // enable transport level security. $redis->connect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->connect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout. $redis->connect('/tmp/redis.sock'); // unix domain socket. $redis->connect('127.0.0.1', 6379, 1, '', 100); // 1 sec timeout, 100ms delay between reconnection attempts. $redis->connect('/tmp/redis.sock', 0, 1.5, NULL, 0, 1.5); // Unix socket with 1.5s timeouts (connect and read) /* With PhpRedis >= 5.3.0 you can specify authentication and stream information on connect */ $redis->connect('127.0.0.1', 6379, 1, '', 0, 0, ['auth' => ['phpredis', 'phpredis']]); Note. 26 is an alias for 22 and will be removed in future versions of phprediskết nối, mởSự miêu tả. Kết nối với phiên bản Redis hoặc sử dụng lại kết nối đã được thiết lập với 28/ 29Kết nối sẽ không bị đóng khi kết thúc yêu cầu cho đến khi quá trình php kết thúc. So be prepared for too many open FD's errors (specially on redis server side) when using persistent connections on many servers connecting to one redis server Also more than one persistent connection can be made identified by either host + port + timeout or host + persistent_id or unix socket + timeout Starting from version 4. 2. 1, it became possible to use connection pooling by setting INI variable 30 to 1This feature is not available in threaded versions. 28 and 29 then working like their non persistent equivalentsParametershost. string. can be a host, or the path to a unix domain socket. Starting from version 5. 0. 0 it is possible to specify schema Return valueBOOL. 24 on success, 23 on errorExample$redis->pconnect('127.0.0.1', 6379); $redis->pconnect('127.0.0.1'); // port 6379 by default - same connection like before. $redis->pconnect('tls://127.0.0.1', 6379); // enable transport level security. $redis->pconnect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->pconnect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout and would be another connection than the two before. $redis->pconnect('127.0.0.1', 6379, 2.5, 'x'); // x is sent as persistent_id and would be another connection than the three before. $redis->pconnect('/tmp/redis.sock'); // unix domain socket - would be another connection than the four before. Note. 29 is an alias for 28 and will be removed in future versions of phpredisauthDescription. Authenticate the connection using a password or a username and password. Warning. The password is sent in plain-text over the network ParametersMIXED. password Return valueBOOL. 24 if the connection is authenticated, 23 otherwiseNote. In order to authenticate with a username and password you need Redis >= 6. 0 Example/* Authenticate with the password 'foobared' */ $redis->auth('foobared'); /* Authenticate with the username 'phpredis', and password 'haxx00r' */ $redis->auth(['phpredis', 'haxx00r']); /* Authenticate with the password 'foobared' */ $redis->auth(['foobared']); /* You can also use an associative array specifying user and pass */ $redis->auth(['user' => 'phpredis', 'pass' => 'phpredis']); $redis->auth(['pass' => 'phpredis']); selectDescription. Change the selected database for the current connection ParametersINTEGER. dbindex, the database number to switch to Return value 24 in case of success, 23 in case of failureExampleSee method for example. swapdbDescription. Swap one Redis database with another atomically ParametersINTEGER. db1 Return value 24 on success and 23 on failureNote. Requires Redis >= 4. 0. 0 Example 0closeDescription. Disconnects from the Redis instance Note. Closing a persistent connection requires PhpRedis >= 4. 2. 0 ParametersNone Return valueBOOL. 24 on success, 23 on failuresetOptionDescription. Set client option Parametersparameter name Return valueBOOL. 24 on success, 23 on errorExample 1getOptionDescription. Get client option Parametersparameter name Return valueParameter value Example 2pingDescription. Check the current connection status Prototype 3Return valueMixed. This method returns 24 on success, or the passed string if called with an argumentExample 4Note. Prior to PhpRedis 5. 0. 0 lệnh này chỉ đơn giản là trả về chuỗi 48echoSự miêu tả. Gửi một chuỗi tới Redis, Redis trả lời bằng cùng một chuỗi ParametersCHUỖI. Tin nhắn để gửi Return valueSTRING. the same message Retry and backoffMaximum retriesYou can set and get the maximum retries upon connection issues using the 49 option. Note that this is the number of retries, meaning if you set this option to n, there will be a maximum n+1 attemps overall. Defaults to 10Example 5Backoff algorithmsYou can set the backoff algorithm using the 50 option and choose among the following algorithms described in this blog post by Marc Brooker from AWS. Exponential Backoff And Jitter
These algorithms depend on the base and cap parameters, both in milliseconds, which you can set using the 58 and 59 options, respectivelyExample 6Server
aclDescription. Thực thi lệnh Redis ACL Parametersvariable. Minumum of one argument for 60 and two for 61Example 7Note. In order to user the 62 command you must be communicating with Redis >= 6. 0 and be logged into an account that has access to administration commands such as ACL. Please reference this tutorial for an overview of Redis 6 ACLs and the redis command reference for every ACL subcommandNote. If you are connecting to Redis server >= 4. 0. 0 you can remove a key with the 63 method in the exact same way you would use 64. The Redis unlink command is non-blocking and will perform the actual deletion asynchronouslybgRewriteAOFDescription. Start the background rewrite of AOF (Append-Only File) ParametersNone Return valueBOOL. 24 in case of success, 23 in case of failureExample 8bgSaveDescription. Asynchronously save the dataset to disk (in background) ParametersNone Return valueBOOL. 24 in case of success, 23 in case of failure. If a save is already running, this command will fail and return 23Example 9cấu hìnhSự miêu tả. Nhận hoặc Đặt tham số cấu hình máy chủ Redis Prototype 0Return valueMảng kết hợp cho 70, (các) khóa -> (các) giá trịbool cho 20, 72 và 73ví dụ 1dbSizeSự miêu tả. Trả về số lượng khóa trong cơ sở dữ liệu đã chọn ParametersNone Return valuesố nguyên. Kích thước DB, theo số lượng khóa Example 2tuôn raTất cảSự miêu tả. Xóa tất cả các khóa khỏi tất cả các cơ sở dữ liệu Parametersasync (bool) yêu cầu phiên bản máy chủ 4. 0. 0 hoặc cao hơn Return valueBOOL. Luôn luôn 24Example 3tuôn raDbSự miêu tả. Xóa tất cả các khóa khỏi cơ sở dữ liệu hiện tại Prototype 4Return valueBOOL. Lệnh này trả về true nếu thành công và false nếu thất bại Example 5thông tinSự miêu tả. Nhận thông tin và số liệu thống kê về máy chủ Trả về một mảng kết hợp cung cấp thông tin về máy chủ. Không truyền đối số cho INFO sẽ gọi lệnh REDIS INFO tiêu chuẩn, trả về thông tin như sau
Bạn có thể chuyển nhiều tùy chọn cho INFO (theo tài liệu Redis), điều này sẽ sửa đổi những gì được trả về Parametersquyền mua. Tùy chọn cung cấp redis (e. g. "THỐNG KÊ LỆNH", "CPU") Example 6lần lưu cuối cùngSự miêu tả. Trả về dấu thời gian của lần lưu đĩa cuối cùng ParametersNone Return valueINT. dấu thời gian Example 7tiết kiệmSự miêu tả. Lưu đồng bộ tập dữ liệu vào đĩa (chờ hoàn tất) ParametersNone Return valueBOOL. 24 in case of success, 23 in case of failure. If a save is already running, this command will fail and return 23Example 8nô lệ củaSự miêu tả. Thay đổi trạng thái nô lệ ParametersMáy chủ (chuỗi) và cổng (int) hoặc không có tham số nào ngừng làm nô lệ Return valueBOOL. 24 in case of success, 23 in case of failureExample 9thời gianSự miêu tả. Trả về thời gian máy chủ hiện tại Parameters(không ai) Return valueNếu thành công, thời gian sẽ quay trở lại dưới dạng một mảng kết hợp với phần tử 0 là dấu thời gian unix và phần tử một là micro giây ví dụ 0Nhật ký chậmSự miêu tả. Truy cập Redis SlowLog ParametersHoạt động (chuỗi). Đây có thể là 70, 81 hoặc 82Độ dài (số nguyên), tùy chọn. Nếu thực hiện lệnh 83, bạn có thể truyền độ dài tùy chọnReturn valueGiá trị trả về của SLOWLOG sẽ phụ thuộc vào thao tác nào được thực hiện. CHẬM NHẬT KÝ. Mảng các mục nhập slowLog, được cung cấp bởi Redis SLOGLOG LEN. Số nguyên, độ dài của slowLog SLOWLOG RESET. Boolean, tùy thuộc vào thành công ví dụ 1Chìa khóa và ChuỗiDây
Keys
getDescription. Get the value related to the specified key Parameterskey Return valueString or Bool. If key didn't exist, 23 is returned. Otherwise, the value related to this key is returnedví dụ 2setDescription. Set the string value in argument as value of the key. If you're using Redis >= 2. 6. 12, you can pass extended options as explained below ParametersKey Return valueBool 24 if the command is successfulví dụ 3setEx, pSetExDescription. Set the string value in argument as value of the key, with a time to live. PSETEX uses a TTL in milliseconds ParametersKey TTL Value Return valueBool 24 if the command is successfulví dụ 4setNxSự miêu tả. Set the string value in argument as value of the key if the key doesn't already exist in the database Parameterskey value Return valueBool 24 in case of success, 23 in case of failureví dụ 5del, delete, unlinkDescription. Remove specified keys ParametersAn array of keys, or an undefined number of parameters, each a key. key1 key2 key3 . keyN Note. If you are connecting to Redis server >= 4. 0. 0 you can remove a key with the 63 method in the exact same way you would use 64. The Redis unlink command is non-blocking and will perform the actual deletion asynchronouslyReturn valueLong Number of keys deleted ví dụ 6Note. 91 is an alias for 64 and will be removed in future versions of phpredisexistsDescription. Verify if the specified key exists Parameterskey Return valuelong. The number of keys tested that do exist ví dụ 7Note. This function took a single argument and returned TRUE or FALSE in phpredis versions < 4. 0. 0 incr, incrByDescription. Increment the number stored at key by one. If the second argument is filled, it will be used as the integer value of the increment Parameterskey Return valueINT the new value ví dụ 8incrByFloatDescription. Increment the key with floating point precision Parameterskey Return valueFLOAT the new value ví dụ 9decr, decrByDescription. Decrement the number stored at key by one. If the second argument is filled, it will be used as the integer value of the decrement Parameterskey Return valueINT the new value ví dụ$redis = new Redis();0 mGet, getMultipleDescription. Get the values of all the specified keys. If one or more keys don't exist, the array will contain 23 at the position of the keyParametersArray. Array containing the list of the keys Return valueArray. Array containing the values related to keys in argument ví dụ$redis = new Redis();1 Note. 94 is an alias for 95 and will be removed in future versions of phpredisgetSetDescription. Sets a value and returns the previous entry at that key ParametersKey. key STRING. value Return valueA string, the previous value located at this key Example$redis = new Redis();2 randomKeyDescription. Returns a random key ParametersNone Return valueSTRING. an existing key in redis Example$redis = new Redis();3 moveDescription. Moves a key to a different database ParametersKey. chìa khóa, chìa khóa để di chuyển INTEGER. dbindex, the database number to move the key to Return valueBOOL. 24 in case of success, 23 in case of failureExample$redis = new Redis();4 rename, renameKeyDescription. Renames a key ParametersSTRING. srckey, the key to rename STRING. dstkey, the new name for the key Return valueBOOL. 24 in case of success, 23 in case of failureExample$redis = new Redis();5 Note. 00 is an alias for 01 and will be removed in future versions of phpredisrenameNxSự miêu tả. Tương tự như đổi tên, nhưng sẽ không thay thế khóa nếu đích đã tồn tại. Đây là hành vi tương tự như setNx hết hạn, hết hạnSự miêu tả. Đặt thời gian hết hạn cho một khóa trong giây hoặc mili giây Prototype$redis = new Redis();6 Return valueBOOL. 24 nếu thời hạn đã được đặt và 23 nếu không thành công hoặc nếu thời hạn không được đặt. Bạn có thể phân biệt giữa lỗi và thời hạn không được đặt bằng cách kiểm tra 04Example$redis = new Redis();7 Note. 05 is an alias for 06 and will be removed in future versions of phpredisexpireAt, pexpireAtDescription. Seta specific timestamp for a key to expire in seconds or milliseconds Prototype$redis = new Redis();8 Return valueBOOL. 24 if an expiration was set and 23 if one was not set or in the event on an error. You can detect an actual error by checking 04Example$redis = new Redis();9 keys, getKeysDescription. Returns the keys that match a certain pattern ParametersSTRING. pattern, using '*' as a wildcard Return valueArray of STRING. The keys that match a certain pattern Example$redis = new Redis([ 'host' => '127.0.0.1', 'port' => 6379, 'connectTimeout' => 2.5, 'auth' => ['phpredis', 'phpredis'], 'ssl' => ['verify_peer' => false], 'backoff' => [ 'algorithm' => Redis::BACKOFF_ALGORITHM_DECORRELATED_JITTER, 'base' => 500, 'cap' => 750, ], ]);0 Note. 10 is an alias for 11 and will be removed in future versions of phpredisscanDescription. Scan the keyspace for keys ParametersLONG (reference). Iterator, initialized to NULL STRING, Optional. Pattern to match LONG, Optional. Count of keys per iteration (only a suggestion to Redis) Return valueArray, boolean. This function will return an array of keys or FALSE if Redis returned zero keys Note. SCAN is a "directed node" command in Example$redis = new Redis([ 'host' => '127.0.0.1', 'port' => 6379, 'connectTimeout' => 2.5, 'auth' => ['phpredis', 'phpredis'], 'ssl' => ['verify_peer' => false], 'backoff' => [ 'algorithm' => Redis::BACKOFF_ALGORITHM_DECORRELATED_JITTER, 'base' => 500, 'cap' => 750, ], ]);1 mục tiêuDescription. Describes the object pointed to by a key ParametersThe information to retrieve (string) and the key (string). Info can be one of the following
Return valueSTRING for "encoding", LONG for "refcount" and "idletime", 23 if the key doesn't existExample$redis = new Redis([ 'host' => '127.0.0.1', 'port' => 6379, 'connectTimeout' => 2.5, 'auth' => ['phpredis', 'phpredis'], 'ssl' => ['verify_peer' => false], 'backoff' => [ 'algorithm' => Redis::BACKOFF_ALGORITHM_DECORRELATED_JITTER, 'base' => 500, 'cap' => 750, ], ]);2 typeDescription. Returns the type of data pointed by a given key ParametersKey. key Return valueDepending on the type of the data pointed by the key, this method will return the following value Example$redis = new Redis([ 'host' => '127.0.0.1', 'port' => 6379, 'connectTimeout' => 2.5, 'auth' => ['phpredis', 'phpredis'], 'ssl' => ['verify_peer' => false], 'backoff' => [ 'algorithm' => Redis::BACKOFF_ALGORITHM_DECORRELATED_JITTER, 'base' => 500, 'cap' => 750, ], ]);3 appendDescription. Append specified string to the string stored in specified key ParametersKey Value Return valueINTEGER. Size of the value after the append Example$redis = new Redis([ 'host' => '127.0.0.1', 'port' => 6379, 'connectTimeout' => 2.5, 'auth' => ['phpredis', 'phpredis'], 'ssl' => ['verify_peer' => false], 'backoff' => [ 'algorithm' => Redis::BACKOFF_ALGORITHM_DECORRELATED_JITTER, 'base' => 500, 'cap' => 750, ], ]);4 getRangeDescription. Return a substring of a larger string Parameterskey Return valueSTRING. the substring Example$redis = new Redis([ 'host' => '127.0.0.1', 'port' => 6379, 'connectTimeout' => 2.5, 'auth' => ['phpredis', 'phpredis'], 'ssl' => ['verify_peer' => false], 'backoff' => [ 'algorithm' => Redis::BACKOFF_ALGORITHM_DECORRELATED_JITTER, 'base' => 500, 'cap' => 750, ], ]);5 Note. 13 is an alias for 14 and will be removed in future versions of phpredissetRangeDescription. Changes a substring of a larger string Parametersgiá trị bù khóa Return valueSTRING. the length of the string after it was modified Example$redis = new Redis([ 'host' => '127.0.0.1', 'port' => 6379, 'connectTimeout' => 2.5, 'auth' => ['phpredis', 'phpredis'], 'ssl' => ['verify_peer' => false], 'backoff' => [ 'algorithm' => Redis::BACKOFF_ALGORITHM_DECORRELATED_JITTER, 'base' => 500, 'cap' => 750, ], ]);6 strLenDescription. Get the length of a string value Parameterskey Return valueINTEGER Example$redis = new Redis([ 'host' => '127.0.0.1', 'port' => 6379, 'connectTimeout' => 2.5, 'auth' => ['phpredis', 'phpredis'], 'ssl' => ['verify_peer' => false], 'backoff' => [ 'algorithm' => Redis::BACKOFF_ALGORITHM_DECORRELATED_JITTER, 'base' => 500, 'cap' => 750, ], ]);7 getBitDescription. Return a single bit out of a larger string Parameterskey Return valueLONG. the bit value (0 or 1) Example$redis = new Redis([ 'host' => '127.0.0.1', 'port' => 6379, 'connectTimeout' => 2.5, 'auth' => ['phpredis', 'phpredis'], 'ssl' => ['verify_peer' => false], 'backoff' => [ 'algorithm' => Redis::BACKOFF_ALGORITHM_DECORRELATED_JITTER, 'base' => 500, 'cap' => 750, ], ]);8 setBitDescription. Changes a single bit of a string Parameterskey Return valueLONG. 0 or 1, the value of the bit before it was set Example$redis = new Redis([ 'host' => '127.0.0.1', 'port' => 6379, 'connectTimeout' => 2.5, 'auth' => ['phpredis', 'phpredis'], 'ssl' => ['verify_peer' => false], 'backoff' => [ 'algorithm' => Redis::BACKOFF_ALGORITHM_DECORRELATED_JITTER, 'base' => 500, 'cap' => 750, ], ]);9 bitOpDescription. Bitwise operation on multiple keys Parametersoperation. either "AND", "OR", "NOT", "XOR" Return valueLONG. The size of the string stored in the destination key bitCountDescription. Count bits in a string Parameterskey Return valueLONG. The number of bits set to 1 in the value behind the input key sortDescription. Sort the elements in a list, set or sorted set ParametersKey. key Options. [key => value, . ] - optional, with the following keys and values 0Return valueAn array of values, or a number corresponding to the number of elements stored if that was used Example 1ttl, pttlDescription. Returns the time to live left for a given key in seconds (ttl), or milliseconds (pttl) ParametersKey. key Return valueLONG. The time to live in seconds. If the key has no ttl, 15 will be returned, and 16 if the key doesn't existExample 2persistDescription. Remove the expiration timer from a key ParametersKey. key Return valueBOOL. 24 if a timeout was removed, 23 if the key didn’t exist or didn’t have an expiration timerExample 3mSet, mSetNxSự miêu tả. Sets multiple key-value pairs in one atomic command. MSETNX only returns TRUE if all the keys were set (see SETNX) ParametersPairs. [key => value, . ] Return valueBool 24 in case of success, 23 in case of failureExample 4Output 5dumpDescription. Dump a key out of a redis database, the value of which can later be passed into redis using the RESTORE command. The data that comes out of DUMP is a binary representation of the key as Redis stores it Parameterskey string Return valueThe Redis encoded value of the key, or FALSE if the key doesn't exist ví dụ 6restoreDescription. Restore a key from the result of a DUMP operation Parameterskey string. The key name ví dụ 7migrateDescription. Migrates a key to a different Redis instance Note. Redis introduced migrating multiple keys in 3. 0. 6, so you must have at least that version in order to call 21 with an array of keysParametershost string. The destination host ví dụ 8Hashes
hSetDescription. Adds a value to the hash stored at key Parameterskey Return valueLONG 22 if value didn't exist and was added successfully, 23 if the value was already present and was replaced, 23 if there was an errorExample 9hSetNxDescription. Adds a value to the hash stored at key only if this field isn't already in the hash Return valueBOOL 24 if the field was set, 23 if it was already presentExample$redis->connect('127.0.0.1', 6379); $redis->connect('127.0.0.1'); // port 6379 by default $redis->connect('tls://127.0.0.1', 6379); // enable transport level security. $redis->connect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->connect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout. $redis->connect('/tmp/redis.sock'); // unix domain socket. $redis->connect('127.0.0.1', 6379, 1, '', 100); // 1 sec timeout, 100ms delay between reconnection attempts. $redis->connect('/tmp/redis.sock', 0, 1.5, NULL, 0, 1.5); // Unix socket with 1.5s timeouts (connect and read) /* With PhpRedis >= 5.3.0 you can specify authentication and stream information on connect */ $redis->connect('127.0.0.1', 6379, 1, '', 0, 0, ['auth' => ['phpredis', 'phpredis']]);0 hGetDescription. Gets a value from the hash stored at key. If the hash table doesn't exist, or the key doesn't exist, 23 is returnedParameterskey Return valueSTRING The value, if the command executed successfully 23 in case of failurehLenDescription. Returns the length of a hash, in number of items Parameterskey Return valueLONG the number of items in a hash, 23 if the key doesn't exist or isn't a hashExample$redis->connect('127.0.0.1', 6379); $redis->connect('127.0.0.1'); // port 6379 by default $redis->connect('tls://127.0.0.1', 6379); // enable transport level security. $redis->connect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->connect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout. $redis->connect('/tmp/redis.sock'); // unix domain socket. $redis->connect('127.0.0.1', 6379, 1, '', 100); // 1 sec timeout, 100ms delay between reconnection attempts. $redis->connect('/tmp/redis.sock', 0, 1.5, NULL, 0, 1.5); // Unix socket with 1.5s timeouts (connect and read) /* With PhpRedis >= 5.3.0 you can specify authentication and stream information on connect */ $redis->connect('127.0.0.1', 6379, 1, '', 0, 0, ['auth' => ['phpredis', 'phpredis']]);1 hDelDescription. Removes a value from the hash stored at key. If the hash table doesn't exist, or the key doesn't exist, 23 is returnedParameterskey Return valueLONG số lượng khóa đã xóa, 0 nếu khóa không tồn tại, 23 nếu khóa không phải là hàm bămhKeysSự miêu tả. Trả về các khóa ở dạng băm, dưới dạng một chuỗi các chuỗi ParametersKey. key Return valueMột mảng các phần tử, các khóa của hàm băm. Điều này hoạt động giống như mảng_keys() của PHP Example$redis->connect('127.0.0.1', 6379); $redis->connect('127.0.0.1'); // port 6379 by default $redis->connect('tls://127.0.0.1', 6379); // enable transport level security. $redis->connect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->connect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout. $redis->connect('/tmp/redis.sock'); // unix domain socket. $redis->connect('127.0.0.1', 6379, 1, '', 100); // 1 sec timeout, 100ms delay between reconnection attempts. $redis->connect('/tmp/redis.sock', 0, 1.5, NULL, 0, 1.5); // Unix socket with 1.5s timeouts (connect and read) /* With PhpRedis >= 5.3.0 you can specify authentication and stream information on connect */ $redis->connect('127.0.0.1', 6379, 1, '', 0, 0, ['auth' => ['phpredis', 'phpredis']]);2 Output $redis->connect('127.0.0.1', 6379); $redis->connect('127.0.0.1'); // port 6379 by default $redis->connect('tls://127.0.0.1', 6379); // enable transport level security. $redis->connect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->connect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout. $redis->connect('/tmp/redis.sock'); // unix domain socket. $redis->connect('127.0.0.1', 6379, 1, '', 100); // 1 sec timeout, 100ms delay between reconnection attempts. $redis->connect('/tmp/redis.sock', 0, 1.5, NULL, 0, 1.5); // Unix socket with 1.5s timeouts (connect and read) /* With PhpRedis >= 5.3.0 you can specify authentication and stream information on connect */ $redis->connect('127.0.0.1', 6379, 1, '', 0, 0, ['auth' => ['phpredis', 'phpredis']]);3 The order is random and corresponds to redis' own internal representation of the set structure hValsDescription. Returns the values in a hash, as an array of strings ParametersKey. key Return valueAn array of elements, the values of the hash. This works like PHP's array_values() Example$redis->connect('127.0.0.1', 6379); $redis->connect('127.0.0.1'); // port 6379 by default $redis->connect('tls://127.0.0.1', 6379); // enable transport level security. $redis->connect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->connect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout. $redis->connect('/tmp/redis.sock'); // unix domain socket. $redis->connect('127.0.0.1', 6379, 1, '', 100); // 1 sec timeout, 100ms delay between reconnection attempts. $redis->connect('/tmp/redis.sock', 0, 1.5, NULL, 0, 1.5); // Unix socket with 1.5s timeouts (connect and read) /* With PhpRedis >= 5.3.0 you can specify authentication and stream information on connect */ $redis->connect('127.0.0.1', 6379, 1, '', 0, 0, ['auth' => ['phpredis', 'phpredis']]);4 Output $redis->connect('127.0.0.1', 6379); $redis->connect('127.0.0.1'); // port 6379 by default $redis->connect('tls://127.0.0.1', 6379); // enable transport level security. $redis->connect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->connect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout. $redis->connect('/tmp/redis.sock'); // unix domain socket. $redis->connect('127.0.0.1', 6379, 1, '', 100); // 1 sec timeout, 100ms delay between reconnection attempts. $redis->connect('/tmp/redis.sock', 0, 1.5, NULL, 0, 1.5); // Unix socket with 1.5s timeouts (connect and read) /* With PhpRedis >= 5.3.0 you can specify authentication and stream information on connect */ $redis->connect('127.0.0.1', 6379, 1, '', 0, 0, ['auth' => ['phpredis', 'phpredis']]);5 The order is random and corresponds to redis' own internal representation of the set structure hGetAllDescription. Returns the whole hash, as an array of strings indexed by strings ParametersKey. key Return valueAn array of elements, the contents of the hash Example$redis->connect('127.0.0.1', 6379); $redis->connect('127.0.0.1'); // port 6379 by default $redis->connect('tls://127.0.0.1', 6379); // enable transport level security. $redis->connect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->connect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout. $redis->connect('/tmp/redis.sock'); // unix domain socket. $redis->connect('127.0.0.1', 6379, 1, '', 100); // 1 sec timeout, 100ms delay between reconnection attempts. $redis->connect('/tmp/redis.sock', 0, 1.5, NULL, 0, 1.5); // Unix socket with 1.5s timeouts (connect and read) /* With PhpRedis >= 5.3.0 you can specify authentication and stream information on connect */ $redis->connect('127.0.0.1', 6379, 1, '', 0, 0, ['auth' => ['phpredis', 'phpredis']]);6 Output $redis->connect('127.0.0.1', 6379); $redis->connect('127.0.0.1'); // port 6379 by default $redis->connect('tls://127.0.0.1', 6379); // enable transport level security. $redis->connect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->connect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout. $redis->connect('/tmp/redis.sock'); // unix domain socket. $redis->connect('127.0.0.1', 6379, 1, '', 100); // 1 sec timeout, 100ms delay between reconnection attempts. $redis->connect('/tmp/redis.sock', 0, 1.5, NULL, 0, 1.5); // Unix socket with 1.5s timeouts (connect and read) /* With PhpRedis >= 5.3.0 you can specify authentication and stream information on connect */ $redis->connect('127.0.0.1', 6379, 1, '', 0, 0, ['auth' => ['phpredis', 'phpredis']]);7 The order is random and corresponds to redis' own internal representation of the set structure hExistsDescription. Verify if the specified member exists in a key Parameterskey Return valueBOOL. If the member exists in the hash table, return 24, otherwise return 23ví dụ$redis->connect('127.0.0.1', 6379); $redis->connect('127.0.0.1'); // port 6379 by default $redis->connect('tls://127.0.0.1', 6379); // enable transport level security. $redis->connect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->connect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout. $redis->connect('/tmp/redis.sock'); // unix domain socket. $redis->connect('127.0.0.1', 6379, 1, '', 100); // 1 sec timeout, 100ms delay between reconnection attempts. $redis->connect('/tmp/redis.sock', 0, 1.5, NULL, 0, 1.5); // Unix socket with 1.5s timeouts (connect and read) /* With PhpRedis >= 5.3.0 you can specify authentication and stream information on connect */ $redis->connect('127.0.0.1', 6379, 1, '', 0, 0, ['auth' => ['phpredis', 'phpredis']]);8 hIncrByDescription. Increments the value of a member from a hash by a given amount Parameterskey Return valueLONG the new value ví dụ$redis->connect('127.0.0.1', 6379); $redis->connect('127.0.0.1'); // port 6379 by default $redis->connect('tls://127.0.0.1', 6379); // enable transport level security. $redis->connect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->connect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout. $redis->connect('/tmp/redis.sock'); // unix domain socket. $redis->connect('127.0.0.1', 6379, 1, '', 100); // 1 sec timeout, 100ms delay between reconnection attempts. $redis->connect('/tmp/redis.sock', 0, 1.5, NULL, 0, 1.5); // Unix socket with 1.5s timeouts (connect and read) /* With PhpRedis >= 5.3.0 you can specify authentication and stream information on connect */ $redis->connect('127.0.0.1', 6379, 1, '', 0, 0, ['auth' => ['phpredis', 'phpredis']]);9 hIncrByFloatDescription. Increments the value of a hash member by the provided float value Parameterskey Return valueFLOAT the new value ví dụ$redis->pconnect('127.0.0.1', 6379); $redis->pconnect('127.0.0.1'); // port 6379 by default - same connection like before. $redis->pconnect('tls://127.0.0.1', 6379); // enable transport level security. $redis->pconnect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->pconnect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout and would be another connection than the two before. $redis->pconnect('127.0.0.1', 6379, 2.5, 'x'); // x is sent as persistent_id and would be another connection than the three before. $redis->pconnect('/tmp/redis.sock'); // unix domain socket - would be another connection than the four before.0 hMSetDescription. Điền vào toàn bộ hàm băm. Non-string values are converted to string, using the standard 34 cast. NULL values are stored as empty stringsParameterskey Return valueBOOL ví dụ$redis->pconnect('127.0.0.1', 6379); $redis->pconnect('127.0.0.1'); // port 6379 by default - same connection like before. $redis->pconnect('tls://127.0.0.1', 6379); // enable transport level security. $redis->pconnect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->pconnect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout and would be another connection than the two before. $redis->pconnect('127.0.0.1', 6379, 2.5, 'x'); // x is sent as persistent_id and would be another connection than the three before. $redis->pconnect('/tmp/redis.sock'); // unix domain socket - would be another connection than the four before.1 hMGetDescription. Retrieve the values associated to the specified fields in the hash Parameterskey Return valueArray An array of elements, the values of the specified fields in the hash, with the hash keys as array keys ví dụ$redis->pconnect('127.0.0.1', 6379); $redis->pconnect('127.0.0.1'); // port 6379 by default - same connection like before. $redis->pconnect('tls://127.0.0.1', 6379); // enable transport level security. $redis->pconnect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->pconnect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout and would be another connection than the two before. $redis->pconnect('127.0.0.1', 6379, 2.5, 'x'); // x is sent as persistent_id and would be another connection than the three before. $redis->pconnect('/tmp/redis.sock'); // unix domain socket - would be another connection than the four before.2 hScanDescription. Scan a HASH value for members, with an optional pattern and count Parameterskey. String Return valueArray An array of members that match our pattern ví dụ$redis->pconnect('127.0.0.1', 6379); $redis->pconnect('127.0.0.1'); // port 6379 by default - same connection like before. $redis->pconnect('tls://127.0.0.1', 6379); // enable transport level security. $redis->pconnect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->pconnect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout and would be another connection than the two before. $redis->pconnect('127.0.0.1', 6379, 2.5, 'x'); // x is sent as persistent_id and would be another connection than the three before. $redis->pconnect('/tmp/redis.sock'); // unix domain socket - would be another connection than the four before.3 hStrLenDescription. Get the string length of the value associated with field in the hash stored at key Parameterskey. String Return valueLONG the string length of the value associated with field, or zero when field is not present in the hash or key does not exist at all Lists
blPop, brPopDescription. Là một nguyên thủy chặn lPop(rPop). If at least one of the lists contains at least one element, the element will be popped from the head of the list and returned to the caller. If all the list identified by the keys passed in arguments are empty, blPop will block during the specified timeout until an element is pushed to one of those lists. This element will be popped ParametersARRAY Array containing the keys of the lists Return valueARRAY ['listName', 'element'] Example$redis->pconnect('127.0.0.1', 6379); $redis->pconnect('127.0.0.1'); // port 6379 by default - same connection like before. $redis->pconnect('tls://127.0.0.1', 6379); // enable transport level security. $redis->pconnect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->pconnect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout and would be another connection than the two before. $redis->pconnect('127.0.0.1', 6379, 2.5, 'x'); // x is sent as persistent_id and would be another connection than the three before. $redis->pconnect('/tmp/redis.sock'); // unix domain socket - would be another connection than the four before.4 bRPopLPushDescription. A blocking version of 35, with an integral timeout in the third parameterParametersKey. srckey Return valueSTRING Phần tử đã được di chuyển trong trường hợp thành công, 23 trong trường hợp hết thời gian chờlChỉ mục, lNhậnSự miêu tả. Trả về phần tử đã chỉ định của danh sách được lưu trữ tại khóa đã chỉ định 0 phần tử đầu tiên, 1 phần thứ hai Return 23 in case of a bad index or a key that doesn't point to a listParameterskey Return valueString the element at this index 23 if the key identifies a non-string data type, or no value corresponds to this index in the list 39Example$redis->pconnect('127.0.0.1', 6379); $redis->pconnect('127.0.0.1'); // port 6379 by default - same connection like before. $redis->pconnect('tls://127.0.0.1', 6379); // enable transport level security. $redis->pconnect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->pconnect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout and would be another connection than the two before. $redis->pconnect('127.0.0.1', 6379, 2.5, 'x'); // x is sent as persistent_id and would be another connection than the three before. $redis->pconnect('/tmp/redis.sock'); // unix domain socket - would be another connection than the four before.5 Note. 40 is an alias for 41 and will be removed in future versions of phpredislInsertDescription. Insert value in the list before or after the pivot value The parameter options specify the position of the insert (before or after). If the list didn't exists, or the pivot didn't exists, the value is not inserted Parameterskey Return valueThe number of the elements in the list, -1 if the pivot didn't exists Example$redis->pconnect('127.0.0.1', 6379); $redis->pconnect('127.0.0.1'); // port 6379 by default - same connection like before. $redis->pconnect('tls://127.0.0.1', 6379); // enable transport level security. $redis->pconnect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->pconnect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout and would be another connection than the two before. $redis->pconnect('127.0.0.1', 6379, 2.5, 'x'); // x is sent as persistent_id and would be another connection than the three before. $redis->pconnect('/tmp/redis.sock'); // unix domain socket - would be another connection than the four before.6 lPopDescription. Return and remove the first element of the list Parameterskey Return valueSTRING if command executed successfully 23 in case of failure (empty list)Example$redis->pconnect('127.0.0.1', 6379); $redis->pconnect('127.0.0.1'); // port 6379 by default - same connection like before. $redis->pconnect('tls://127.0.0.1', 6379); // enable transport level security. $redis->pconnect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->pconnect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout and would be another connection than the two before. $redis->pconnect('127.0.0.1', 6379, 2.5, 'x'); // x is sent as persistent_id and would be another connection than the three before. $redis->pconnect('/tmp/redis.sock'); // unix domain socket - would be another connection than the four before.7 lPushDescription. Adds one or more values to the head of a LIST. Tạo danh sách nếu khóa không tồn tại. If the key exists and is not a list, 23 is returnedPrototype$redis->pconnect('127.0.0.1', 6379); $redis->pconnect('127.0.0.1'); // port 6379 by default - same connection like before. $redis->pconnect('tls://127.0.0.1', 6379); // enable transport level security. $redis->pconnect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->pconnect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout and would be another connection than the two before. $redis->pconnect('127.0.0.1', 6379, 2.5, 'x'); // x is sent as persistent_id and would be another connection than the three before. $redis->pconnect('/tmp/redis.sock'); // unix domain socket - would be another connection than the four before.8 Return valueLONG The new length of the list in case of success, 23 in case of Failureví dụ$redis->pconnect('127.0.0.1', 6379); $redis->pconnect('127.0.0.1'); // port 6379 by default - same connection like before. $redis->pconnect('tls://127.0.0.1', 6379); // enable transport level security. $redis->pconnect('tls://127.0.0.1'); // enable transport level security, port 6379 by default. $redis->pconnect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout and would be another connection than the two before. $redis->pconnect('127.0.0.1', 6379, 2.5, 'x'); // x is sent as persistent_id and would be another connection than the three before. $redis->pconnect('/tmp/redis.sock'); // unix domain socket - would be another connection than the four before.9 lPushxDescription. Adds the string value to the head (left) of the list if the list exists Parameterskey Return valueLONG The new length of the list in case of success, 23 in case of Failureví dụ/* Authenticate with the password 'foobared' */ $redis->auth('foobared'); /* Authenticate with the username 'phpredis', and password 'haxx00r' */ $redis->auth(['phpredis', 'haxx00r']); /* Authenticate with the password 'foobared' */ $redis->auth(['foobared']); /* You can also use an associative array specifying user and pass */ $redis->auth(['user' => 'phpredis', 'pass' => 'phpredis']); $redis->auth(['pass' => 'phpredis']);0 lRange, lGetRangeDescription. Returns the specified elements of the list stored at the specified key in the range [start, end]. start and stop are interpreted as indices Parameterskey Return valueArray containing the values in specified range Example/* Authenticate with the password 'foobared' */ $redis->auth('foobared'); /* Authenticate with the username 'phpredis', and password 'haxx00r' */ $redis->auth(['phpredis', 'haxx00r']); /* Authenticate with the password 'foobared' */ $redis->auth(['foobared']); /* You can also use an associative array specifying user and pass */ $redis->auth(['user' => 'phpredis', 'pass' => 'phpredis']); $redis->auth(['pass' => 'phpredis']);1 Note. 46 is an alias for 47 and will be removed in future versions of phpredislRem, lRemoveDescription. Removes the first 48 occurrences of the value element from the list. If count is zero, all the matching elements are removed. If count is negative, elements are removed from tail to headNote. The argument order is not the same as in the Redis documentation. This difference is kept for compatibility reasons Parameterskey Return valueLONG the number of elements to remove 23 if the value identified by key is not a listExample/* Authenticate with the password 'foobared' */ $redis->auth('foobared'); /* Authenticate with the username 'phpredis', and password 'haxx00r' */ $redis->auth(['phpredis', 'haxx00r']); /* Authenticate with the password 'foobared' */ $redis->auth(['foobared']); /* You can also use an associative array specifying user and pass */ $redis->auth(['user' => 'phpredis', 'pass' => 'phpredis']); $redis->auth(['pass' => 'phpredis']);2 Note. 50 is an alias for 51 and will be removed in future versions of phpredislSetDescription. Set the list at index with the new value Parameterskey Return valueBOOL 24 if the new value was set. 23 if the index is out of range, or data type identified by key is not a listExample/* Authenticate with the password 'foobared' */ $redis->auth('foobared'); /* Authenticate with the username 'phpredis', and password 'haxx00r' */ $redis->auth(['phpredis', 'haxx00r']); /* Authenticate with the password 'foobared' */ $redis->auth(['foobared']); /* You can also use an associative array specifying user and pass */ $redis->auth(['user' => 'phpredis', 'pass' => 'phpredis']); $redis->auth(['pass' => 'phpredis']);3 lTrim, listTrimDescription. Trims an existing list so that it will contain only a specified range of elements Parameterskey Return valueArray 23 if the key identify a non-list valueExample/* Authenticate with the password 'foobared' */ $redis->auth('foobared'); /* Authenticate with the username 'phpredis', and password 'haxx00r' */ $redis->auth(['phpredis', 'haxx00r']); /* Authenticate with the password 'foobared' */ $redis->auth(['foobared']); /* You can also use an associative array specifying user and pass */ $redis->auth(['user' => 'phpredis', 'pass' => 'phpredis']); $redis->auth(['pass' => 'phpredis']);4 Note. 55 is an alias for 56 and will be removed in future versions of phpredisrPopDescription. Returns and removes the last element of the list Parameterskey Return valueSTRING if command executed successfully 23 in case of failure (empty list)Example/* Authenticate with the password 'foobared' */ $redis->auth('foobared'); /* Authenticate with the username 'phpredis', and password 'haxx00r' */ $redis->auth(['phpredis', 'haxx00r']); /* Authenticate with the password 'foobared' */ $redis->auth(['foobared']); /* You can also use an associative array specifying user and pass */ $redis->auth(['user' => 'phpredis', 'pass' => 'phpredis']); $redis->auth(['pass' => 'phpredis']);5 rPopLPushDescription. Pops a value from the tail of a list, and pushes it to the front of another list. Also return this value. (redis >= 1. 1) ParametersKey. srckey Return valueSTRING The element that was moved in case of success, 23 in case of failureExample/* Authenticate with the password 'foobared' */ $redis->auth('foobared'); /* Authenticate with the username 'phpredis', and password 'haxx00r' */ $redis->auth(['phpredis', 'haxx00r']); /* Authenticate with the password 'foobared' */ $redis->auth(['foobared']); /* You can also use an associative array specifying user and pass */ $redis->auth(['user' => 'phpredis', 'pass' => 'phpredis']); $redis->auth(['pass' => 'phpredis']);6 Output /* Authenticate with the password 'foobared' */ $redis->auth('foobared'); /* Authenticate with the username 'phpredis', and password 'haxx00r' */ $redis->auth(['phpredis', 'haxx00r']); /* Authenticate with the password 'foobared' */ $redis->auth(['foobared']); /* You can also use an associative array specifying user and pass */ $redis->auth(['user' => 'phpredis', 'pass' => 'phpredis']); $redis->auth(['pass' => 'phpredis']);7 rPushDescription. Adds one or more entries to the tail of a LIST. Redis will create the list if it doesn't exist Prototype/* Authenticate with the password 'foobared' */ $redis->auth('foobared'); /* Authenticate with the username 'phpredis', and password 'haxx00r' */ $redis->auth(['phpredis', 'haxx00r']); /* Authenticate with the password 'foobared' */ $redis->auth(['foobared']); /* You can also use an associative array specifying user and pass */ $redis->auth(['user' => 'phpredis', 'pass' => 'phpredis']); $redis->auth(['pass' => 'phpredis']);8 Return valueLONG The new length of the list in case of success, 23 in case of Failureví dụ/* Authenticate with the password 'foobared' */ $redis->auth('foobared'); /* Authenticate with the username 'phpredis', and password 'haxx00r' */ $redis->auth(['phpredis', 'haxx00r']); /* Authenticate with the password 'foobared' */ $redis->auth(['foobared']); /* You can also use an associative array specifying user and pass */ $redis->auth(['user' => 'phpredis', 'pass' => 'phpredis']); $redis->auth(['pass' => 'phpredis']);9 rPushXSự miêu tả. Adds the string value to the tail (right) of the list if the list exists. 23 in case of FailureParameterskey Return valueLONG The new length of the list in case of success, 23 in case of Failureví dụ 00lLen, lSizeDescription. Returns the size of a list identified by Key If the list didn't exist or is empty, the command returns 0. If the data type identified by Key is not a list, the command return 23ParametersKey Return valueLONG The size of the list identified by Key exists 23 if the data type identified by Key is not listExample 01Note. 64 is an alias for 65 and will be removed in future versions of phpredisSets
sAddDescription. Adds a value to the set value stored at key Parameterskey Return valueLONG the number of elements added to the set Example 02sCard, sSizeDescription. Returns the cardinality of the set identified by key Parameterskey Return valueLONG the cardinality of the set identified by key, 0 if the set doesn't exist Example 03Note. 66 is an alias for 67 and will be removed in future versions of phpredissDiffDescription. Performs the difference between N sets and returns it ParametersKeys. key1, key2, . , keyN. Any number of keys corresponding to sets in redis Return valueArray of strings. The difference of the first set will all the others Example 04Return value. all elements of s0 that are neither in s1 nor in s2 05sDiffStoreDescription. Thực hiện hành động tương tự như sDiff, nhưng lưu trữ kết quả trong khóa đầu tiên ParametersKey. dstkey, the key to store the diff into Keys. key1, key2, . , keyN. Any number of keys corresponding to sets in redis Return valueINTEGER. The cardinality of the resulting set, or 23 in case of a missing keyExample 06Return value. the number of elements of s0 that are neither in s1 nor in s2 07sInterDescription. Returns the members of a set resulting from the intersection of all the sets held at the specified keys If just a single key is specified, then this command produces the members of this set. If one of the keys is missing, 23 is returnedParameterskey1, key2, keyN. keys identifying the different sets on which we will apply the intersection Return valueArray, contain the result of the intersection between those keys. If the intersection between the different sets is empty, the return value will be empty array ví dụ 08Output 09sInterStoreDescription. Performs a sInter command and stores the result in a new set ParametersKey. dstkey, the key to store the diff into Keys. key1, key2. keyN. key1. keyN are intersected as in sInter Return valueINTEGER. The cardinality of the resulting set, or 23 in case of a missing keyExample 10Output 11sIsMember, sContainsDescription. Checks if 71 is a member of the set stored at the key 72Parameterskey Return valueBOOL 24 if 71 is a member of the set at key 72, 23 otherwiseExample 12Note. 77 is an alias for 78 and will be removed in future versions of phpredissMembers, sGetMembersDescription. Returns the contents of a set ParametersKey. key Return valueAn array of elements, the contents of the set Example 13Output 14The order is random and corresponds to redis' own internal representation of the set structure Note. 79 is an alias for 80 and will be removed in future versions of phpredissMoveDescription. Moves the specified member from the set at srcKey to the set at dstKey ParameterssrcKey Return valueBOOL If the operation is successful, return 24. If the srcKey and/or dstKey didn't exist, and/or the member didn't exist in srcKey, 23 is returnedExample 15sPopDescription. Removes and returns a random element from the set value at Key Parameterskey Return value (without count argument)String "popped" value 23 if set identified by key is empty or doesn't existReturn value (with count argument)Array. Member(s) returned or an empty array if the set doesn't exist 23 on error if the key is not a setExample 16sRandMemberDescription. Returns a random element from the set value at Key, without removing it Parameterskey Return valueIf no count is provided, a random String value from the set will be returned. If a count is provided, an array of values from the set will be returned. Read about the different ways to use the count here. SRANDMEMBER Bool 23 if set identified by key is empty or doesn't existExample 17sRem, sRemoveDescription. Removes the specified member from the set value stored at key Parameterskey Return valueLONG Số phần tử bị xóa khỏi tập hợp Example 18Ghi chú. 86 is an alias for 87 and will be removed in future versions of phpredissUnionDescription. Performs the union between N sets and returns it ParametersKeys. key1, key2, . , keyN. Any number of keys corresponding to sets in redis Return valueArray of strings. The union of all these sets Note. 88 can also take a single array with keys (see example below)Example 19Return value. all elements that are either in s0 or in s1 or in s2 20sUnionStoreDescription. Performs the same action as sUnion, but stores the result in the first key ParametersKey. dstkey, the key to store the diff into Keys. key1, key2, . , keyN. Any number of keys corresponding to sets in redis Return valueINTEGER. The cardinality of the resulting set, or 23 in case of a missing keyExample 21Return value. the number of elements that are either in s0 or in s1 or in s2 22sScanDescription. Scan a set for members ParametersKey. The set to search Return valueArray, boolean. PHPRedis will return an array of keys or FALSE when we're done iterating Example 23Sorted sets
bzPopDescription. Block until Redis can pop the highest or lowest scoring members from one or more ZSETs. There are two commands ( 90 and 91 for popping the lowest and highest scoring elements respectively. )Prototype 24Return valueARRAY. Either an array with the key member and score of the highest or lowest element or an empty array if the timeout was reached without an element to pop Example 25Note. Calling these functions with an array of keys or with a variable number of arguments is functionally identical zAddDescription. Add one or more members to a sorted set or update its score if it already exists Prototype 26Parameterskey. string options. array (optional) score. double Return valueLong 1 if the element is added. 0 otherwise Example 27zCard, zSizeDescription. Returns the cardinality of an ordered set Parameterskey Return valueLong, the set's cardinality Example 28Note. 92 is an alias for 93 and will be removed in future versions of phprediszCountDescription. Returns the number of elements of the sorted set stored at the specified key which have scores in the range [start,end]. Adding a parenthesis before 94 or 95 excludes it from the range. +inf and -inf are also valid limitsParameterskey Return valueDÀI kích thước của zRangeByScore tương ứng Example 29zIncrByDescription. Increments the score of a member from a sorted set by a given amount Parameterskey Return valueDOUBLE the new value ví dụ 30zinterstore, zInterDescription. Creates an intersection of sorted sets given in second argument. The result of the union will be stored in the sorted set defined by the first argument The third optional argument defines 96 to apply to the sorted sets in input. In this case, the 96 will be multiplied by the score of each element in the sorted set before applying the aggregation. The forth argument defines the 98 option which specify how the results of the union are aggregatedParameterskeyOutput Return valueLONG The number of values in the new sorted set Example 31Note. 99 is an alias for $redis = new Redis();00 and will be removed in future versions of phpredis zPopDescription. Can pop the highest or lowest scoring members from one ZSETs. There are two commands ( $redis = new Redis();01 and $redis = new Redis();02 for popping the lowest and highest scoring elements respectively. ) Prototype 32Return valueARRAY. Either an array with the key member and score of the highest or lowest element or an empty array if there is no element available Example 33zRangeDescription. Trả về một dải các phần tử từ tập hợp có thứ tự được lưu trữ tại khóa đã chỉ định, với các giá trị trong dải [bắt đầu, kết thúc] Start and stop are interpreted as zero-based indices 23 the first element, 22 the second 15 the last element, 16 the penultimate Parameterskey start. Dài Return valueArray containing the values in specified range Example 34zRangeByScore, zRevRangeByScoreSự miêu tả. Trả về các phần tử của tập hợp đã sắp xếp được lưu trữ tại khóa đã chỉ định có điểm số trong phạm vi [bắt đầu, kết thúc]. Thêm dấu ngoặc đơn trước 94 hoặc 95 sẽ loại trừ nó khỏi phạm vi. +inf và -inf cũng là các giới hạn hợp lệ. zRevRangeByScore trả về các mục tương tự theo thứ tự ngược lại, khi các tham số 94 và 95 được hoán đổiParameterskey Hai tùy chọn có sẵn. $redis = new Redis();11 và $redis = new Redis();12 Return valueArray containing the values in specified range Example 35zRangeByLexSự miêu tả. Trả về một phạm vi từ điển của các phần tử trong một tập hợp được sắp xếp, giả sử các phần tử có cùng số điểm. Các giá trị tối thiểu và tối đa bắt buộc phải bắt đầu bằng '(' (không bao gồm), '[' (bao gồm) hoặc chính xác là các giá trị '-' (inf phủ định) hoặc '+' (inf khẳng định). Lệnh phải được gọi với ba hoặc năm đối số hoặc sẽ trả về FALSE ParametersChìa khóa. ZSET mà bạn muốn đối đầu Return valueArray containing the values in the specified range Example 36zRank, zRevRankDescription. Returns the rank of a given member in the specified sorted set, starting at 0 for the item with the smallest score. zRevRank starts at 0 for the item with the largest score Parameterskey Return valueLong, the item's rank Example 37zRem, zDelete, zRemoveDescription. Delete one or more members from a sorted set Prototype 38Return valueLONG. The number of members deleted Example 39Note. $redis = new Redis();13 and $redis = new Redis();14 are an alias for $redis = new Redis();15 and will be removed in future versions of phpredis zRemRangeByRank, zDeleteRangeByRankDescription. Deletes the elements of the sorted set stored at the specified key which have rank in the range [start,end] Parameterskey Return valueLONG The number of values deleted from the sorted set Example 40Note. $redis = new Redis();16 is an alias for $redis = new Redis();17 and will be removed in future versions of phpredis zRemRangeByScore, zDeleteRangeByScore, zRemoveRangeByScoreDescription. Deletes the elements of the sorted set stored at the specified key which have scores in the range [start,end] Parameterskey Return valueLONG The number of values deleted from the sorted set Example 41Note. $redis = new Redis();18 and $redis = new Redis();19 are an alias for $redis = new Redis();20 and will be removed in future versions of phpredis zRevRangeDescription. Returns the elements of the sorted set stored at the specified key in the range [start, end] in reverse order. start and stop are interpreted as zero-based indices 23 the first element, 22 the second 15 the last element, 16 the penultimate Parameterskey Return valueArray containing the values in specified range Example 42zScoreDescription. Returns the score of a given member in the specified sorted set Parameterskey Return valueDouble or FALSE when the value is not found Example 43zunionstore, zUnionDescription. Creates an union of sorted sets given in second argument. The result of the union will be stored in the sorted set defined by the first argument The third optional argument defines 96 to apply to the sorted sets in input. In this case, the 96 will be multiplied by the score of each element in the sorted set before applying the aggregation. The forth argument defines the 98 option which specify how the results of the union are aggregatedParameterskeyOutput Return valueLONG The number of values in the new sorted set Example 44Note. $redis = new Redis();28 is an alias for $redis = new Redis();29 and will be removed in future versions of phpredis zScanDescription. Scan a sorted set for members, with optional pattern and count Parameterskey. String, the set to scan Return valueArray, boolean PHPRedis will return matching keys from Redis, or FALSE when iteration is complete Example 45HyperLogLogspfAddDescription. Adds the specified elements to the specified HyperLogLog Prototype 46ParametersKey Return valueInteger. 1 if at least 1 HyperLogLog internal register was altered. 0 otherwise Example 47pfCountDescription. Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s) Prototype 48ParametersKey or Array of keys Return valueInteger. The approximated number of unique elements observed via Example 49pfMergeDescription. Merge N different HyperLogLogs into a single one Prototype 50ParametersDestination Key Return valueBOOL. 24 on success, 23 on errorExample 51Geocodingthêm địa lýPrototype 52Description. Thêm một hoặc nhiều mục không gian địa lý vào khóa đã chỉ định. This function must be called with at least one longitude, latitude, member triplet Return valueInteger. The number of elements added to the geospatial key Example 53geoHashPrototype 54Description. Retrieve Geohash strings for one or more elements of a geospatial index Return valueArray. One or more Redis Geohash encoded strings Example 55Output 56geoPosPrototype 57Description. Return longitude, latitude positions for each requested member Return valueArray. One or more longitude/latitude positions Example 58Output 59GeoDistPrototype 60Description. Return the distance between two members in a geospatial set. If units are passed it must be one of the following values
Return valueDouble. The distance between the two passed members in the units requested (meters by default) Example 61Output 62geoRadiusPrototype 63Description. Return members of a set with geospatial information that are within the radius specified by the caller Options ArrayThe georadius command can be called with various options that control how Redis returns results. The following table describes the options phpredis supports. All options are case insensitive KeyValueDescriptionCOUNTinteger > 0Limit how many results are returnedWITHCOORDReturn longitude and latitude of matching membersWITHDISTReturn the distance from the centerWITHHASHReturn the raw geohash-encoded scoreASCSort results in ascending orderDESCSort results in descending orderSTOREkeyStore results in keySTOREDISTkeyStore the results as distances in keyNote. It doesn't make sense to pass both $redis = new Redis();32 and $redis = new Redis();33 options but if both are passed the last one passed will be used Note. When using $redis = new Redis();34 in Redis Cluster, the store key must has to the same slot as the query key or you will get a $redis = new Redis();35 error Return valueMixed. When no $redis = new Redis();36 option is passed, this function returns an array of results. If it is passed this function returns the number of stored entries Example 64Output 65geoRadiusByMemberPrototype 66Description. This method is identical to except that instead of passing a longitude and latitude as the "source" you pass an existing member in the geospatial set Options ArraySee command for options array Return valueArray. The zero or more entries that are close enough to the member given the distance and radius specified Example 67Output 68Streams
xAckPrototype 69Description. Acknowledge one or more messages on behalf of a consumer group Return valuelong. The number of messages Redis reports as acknowledged Example 70xAddPrototype 71Description. Add a message to a stream Return valueString. The added message ID Example 72xClaimPrototype 73Description. Claim ownership of one or more pending messages Options Array 74Return valueMảng. Either an array of message IDs along with corresponding data, or just an array of IDs (if the 'JUSTID' option was passed) Example 75xDelPrototype 76Description. Delete one or more messages from a stream Return valuelong. The number of messages removed Example 77xGroupPrototype 78Description. This command is used in order to create, destroy, or manage consumer groups Return valueMixed. This command returns different types depending on the specific XGROUP command executed Example 79xInfoPrototype 80Description. Get information about a stream or consumer groups Return valueMixed. This command returns different types depending on which subcommand is used Example 81xLenPrototype 82Description. Get the length of a given stream Return valueDài. Số lượng tin nhắn trong luồng Example 83xĐang chờ xử lýPrototype 84Sự miêu tả. Get information about pending messages in a given stream Return valueArray. Information about the pending messages, in various forms depending on the specific invocation of XPENDING ví dụ 85xRangePrototype 86Description. Nhận một loạt tin nhắn từ một luồng nhất định Return valueMảng. Các tin nhắn trong luồng trong phạm vi được yêu cầu Example 87xĐọcPrototype 88Sự miêu tả. Đọc dữ liệu từ một hoặc nhiều luồng và chỉ trả lại ID lớn hơn ID được gửi trong lệnh Return valueMảng. Tin nhắn trong luồng mới hơn ID được chuyển đến Redis (nếu có) Example 89xReadGroupPrototype 90Sự miêu tả. Phương pháp này tương tự như xRead ngoại trừ việc nó hỗ trợ đọc tin nhắn cho một nhóm người tiêu dùng cụ thể Return valueMảng. Các tin nhắn gửi đến nhóm người tiêu dùng này (nếu có) ví dụ 91xRevRangePrototype 92Sự miêu tả. Điều này giống với xRange ngoại trừ kết quả trả về theo thứ tự ngược lại. Cũng lưu ý rằng Redis đảo ngược thứ tự "bắt đầu" và "kết thúc" Return valueMảng. Các tin nhắn trong phạm vi được chỉ định Example 93xTrimPrototype 94Sự miêu tả. Cắt bớt độ dài luồng đến mức tối đa nhất định. Nếu cờ "gần đúng" bị bỏ qua, Redis sẽ sử dụng kích thước của bạn làm gợi ý nhưng chỉ cắt bớt cây trong toàn bộ nút (điều này hiệu quả hơn) Return valueDài. Số lượng tin nhắn được cắt bớt từ luồng Example 95Quán rượu/phụ
pĐăng kýSự miêu tả. Đăng ký kênh theo mẫu Parametershoa văn. Một loạt các mẫu để phù hợp Example 96publishSự miêu tả. Xuất bản tin nhắn lên các kênh. Cảnh báo. chức năng này có thể sẽ thay đổi trong tương lai Parameterskênh truyền hình. một kênh để xuất bản lên Example 97đặt muaSự miêu tả. Đăng ký kênh. Cảnh báo. chức năng này có thể sẽ thay đổi trong tương lai Parameterskênh truyền hình. một loạt các kênh để đăng ký Example 98quán rượuSự miêu tả. Một lệnh cho phép bạn lấy thông tin trên hệ thống Redis pub/sub Parameterstừ khóa. Chuỗi, có thể là. "channels", "numsub", or "numpat" Return valueKÊNH TRUYỀN HÌNH. Trả về một mảng trong đó các thành viên là các kênh phù hợp Example 99Chung
rawCommandSự miêu tả. Một phương thức để thực thi bất kỳ lệnh tùy ý nào đối với máy chủ Redis ParametersPhương thức này có nhiều biến thể và nhận một số đối số động thuộc nhiều loại khác nhau (chuỗi, dài, kép), nhưng phải được truyền ít nhất một đối số (chính từ khóa lệnh) Return valueThe return value can be various types depending on what the server itself returns. No post processing is done to the returned value and must be handled by the client code Example 00Transactions
multi, exec, discardDescription. Vào và thoát khỏi chế độ giao dịch Parameters(optional) $redis = new Redis();37 or $redis = new Redis();38. Defaults to $redis = new Redis();37. A $redis = new Redis();37 block of commands runs as a single transaction; a $redis = new Redis();38 block is simply transmitted faster to the server, but without any guarantee of atomicity. $redis = new Redis();42 cancels a transaction Return value$redis = new Redis();43 trả về phiên bản Redis và chuyển sang đa chế độ. Khi ở chế độ đa phương thức, tất cả các cuộc gọi phương thức tiếp theo đều trả về cùng một đối tượng cho đến khi _____14_______44 được gọi Example 01watch, unwatchSự miêu tả. Theo dõi một khóa để sửa đổi bởi một khách hàng khác If the key is modified between $redis = new Redis();45 and $redis = new Redis();46, the MULTI/EXEC transaction will fail (return 23). $redis = new Redis();48 cancels all the watching of all keys by this client Parameterskeys. string for one key or array for a list of keys Example 02Scripting
đánh giáDescription. Evaluate a LUA script serverside Parametersscript string Return valueMixed. What is returned depends on what the LUA script itself returns, which could be a scalar value (int/string), or an array. Các mảng được trả về cũng có thể chứa các mảng khác, nếu đó là cách nó được thiết lập trong tập lệnh LUA của bạn. If there is an error executing the LUA script, the getLastError() function can tell you the message that came back from Redis (e. g. compile error) ví dụ 03evalShaSự miêu tả. Đánh giá phía máy chủ tập lệnh LUA, từ hàm băm SHA1 của tập lệnh thay vì chính tập lệnh đó Để chạy lệnh này, Redis sẽ phải tải tập lệnh, bằng cách chạy tập lệnh hoặc thông qua lệnh SCRIPT LOAD Parameterschuỗi script_sha. The sha1 encoded hash of the script you want to run Return valueTrộn. Xem EVAL ví dụ 04scriptSự miêu tả. Thực thi lệnh Redis SCRIPT để thực hiện các thao tác khác nhau trên hệ thống con tập lệnh Usage 05Return value
khách hàngDescription. Ban hành lệnh CLIENT với các đối số khác nhau The Redis CLIENT command can be used in four ways
Usage 06Return valueĐiều này sẽ khác nhau tùy thuộc vào lệnh máy khách nào được thực thi
Ghi chú. phpredis sẽ cố gắng kết nối lại để bạn thực sự có thể hủy kết nối của chính mình nhưng có thể không nhận thấy việc mất kết nối đó getLastErrorDescription. Thông báo lỗi cuối cùng (nếu có) Parametersnone Return valueA string with the last returned script based error message, or NULL if there is no error ví dụ 07ClearLastErrorSự miêu tả. Xóa thông báo lỗi cuối cùng Parametersnone Return valueĐÚNG SỰ THẬT ví dụ 08_tiếp đầu ngữSự miêu tả. Một phương thức tiện ích để thêm tiền tố vào giá trị với cài đặt tiền tố cho phpredis Parameterschuỗi giá trị. Giá trị bạn muốn tiền tố Return valueNếu tiền tố được thiết lập, giá trị hiện có tiền tố. Nếu không có tiền tố, giá trị sẽ được trả về không thay đổi ví dụ 09_serializeSự miêu tả. Một phương pháp tiện ích để tuần tự hóa các giá trị theo cách thủ công Phương pháp này cho phép bạn tuần tự hóa một giá trị với bất kỳ bộ tuần tự hóa nào được định cấu hình, theo cách thủ công. Điều này có thể hữu ích cho việc tuần tự hóa/hủy tuần tự hóa dữ liệu vào và ra khỏi các lệnh EVAL vì phpredis không thể tự động thực hiện việc này. Lưu ý rằng nếu không có bộ nối tiếp nào được đặt, phpredis sẽ thay đổi giá trị Mảng thành 'Mảng' và Đối tượng thành 'Đối tượng' Parametersvalue. Mixed. The value to be serialized ví dụ 10_unserializeDescription. Một phương thức tiện ích để hủy xác thực dữ liệu với bất kỳ bộ nối tiếp nào được thiết lập Nếu không có bộ nối tiếp nào được đặt, giá trị sẽ được trả về không thay đổi. If there is a serializer set up, and the data passed in is malformed, an exception will be thrown. This can be useful if phpredis is serializing values, and you return something from redis in a LUA script that is serialized Parameterschuỗi giá trị. The value to be unserialized ví dụ 11Introspectionđã kết nốiDescription. Một phương pháp để xác định xem một đối tượng phpredis có nghĩ rằng nó được kết nối với máy chủ hay không ParametersNone Return valueBoolean Returns TRUE if phpredis thinks it's connected and FALSE if not getHostDescription. Truy xuất máy chủ lưu trữ hoặc ổ cắm unix mà chúng tôi đã kết nối với ParametersNone Return valueMixed The host or unix socket we're connected to or FALSE if we're not connected getPortSự miêu tả. Get the port we're connected to ParametersNone Return valueHỗn hợp Trả về cổng chúng tôi đã kết nối hoặc FALSE nếu chúng tôi không kết nối getDbNumSự miêu tả. Get the database number phpredis is pointed to ParametersNone Return valueMixed Returns the database number (LONG) phpredis thinks it's pointing to or FALSE if we're not connected getTimeoutDescription. Nhận thời gian chờ (ghi) được sử dụng cho phpredis ParametersNone Return valueHỗn hợp Thời gian chờ (DOUBLE) được chỉ định trong cuộc gọi kết nối của chúng tôi hoặc SAI nếu chúng tôi không được kết nối getReadTimeoutSự miêu tả. Nhận thời gian chờ đọc được chỉ định cho phpredis hoặc FALSE nếu chúng tôi không được kết nối ParametersNone Return valueMixed Returns the read timeout (which can be set using setOption and Redis. OPT_READ_TIMEOUT) hoặc FALSE nếu chúng tôi không được kết nối getPersistentIDSự miêu tả. Nhận ID liên tục mà phpredis đang sử dụng ParametersNone Return valueKết hợp Trả về id liên tục mà phpredis đang sử dụng (sẽ chỉ được đặt nếu được kết nối với pconnect), NULL nếu chúng tôi không sử dụng ID liên tục và FALSE nếu chúng tôi không kết nối getAuthDescription. Lấy mật khẩu (hoặc tên người dùng và mật khẩu nếu sử dụng Redis 6 ACL) được sử dụng để xác thực kết nối ParametersNone Return valueHỗn hợp Trả về NULL nếu không có tên người dùng/mật khẩu nào được đặt, chuỗi mật khẩu nếu mật khẩu được đặt và mảng $redis = new Redis();49 nếu được xác thực bằng tên người dùng và mật khẩu How to enable Redis in PHP?php //Kết nối với máy chủ Redis trên máy chủ cục bộ $redis = new Redis(); . 0. 0. 1', 6379); . " . // Get the stored data and print it echo "Stored string in redis:: " .
Làm cách nào để sử dụng Redis với PHP MySQL?Máy chủ Redis được thiết lập bằng cách làm theo Cách cài đặt và bảo mật Redis trên Ubuntu 20. 04 - Quickstart tutorial. . Step 1 — Installing the Redis Library for PHP. . Bước 2 - Thiết lập cơ sở dữ liệu thử nghiệm, bảng và dữ liệu mẫu. . Bước 3 — Thiết kế tập lệnh PHP để tìm nạp và lưu vào bộ đệm dữ liệu MySQL. . Bước 4 — Kiểm tra PHP Script How to install Redis extension?Để cài đặt Redis . Log in to your cPanel server via SSH Run these commands to download the rpm files for Redis. . Enter and run these commands to install Redis. . Run this command to enable Redis. . Open the redis. conf file and enter/copy these lines at the end of the file Làm cách nào để cài đặt tiện ích mở rộng Redis cho PHP 8?Cài đặt tiện ích mở rộng PHP Redis cho PHP 8. 0 . Sudo apt-get cài đặt libzstd-dev yes . sudo pecl cài đặt redis tiếng vang sudo "phần mở rộng = redis. vậy" > /etc/php/8. 0/mods-available/redis. ban đầu Sudo ln -sf /etc/php/8. 0/mod-sẵn/redis. ini /etc/php/8. 0/fpm/conf. d/20-redis. ban đầu |