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

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ự án

PhpRedis 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 contents
Installing/Configuring

Installation

For everything you should need to install PhpRedis on your system, see the INSTALL. md page

PHP Session handler

phpredis can be used to store PHP sessions. To do this, configure

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
12 and
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
13 in your php. ini to tell phpredis where to store the sessions

session.save_handler = redis
session.save_path = "tcp://host1:6379?weight=1, tcp://host2:6379?weight=2&timeout=2.5, tcp://host3:6379?weight=2&read_timeout=2.5"

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
13 can have a simple
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
15 format too, but you need to provide the
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
16 scheme if you want to use the parameters. The following parameters are available

  • weight [integer]. the weight of a host is used in comparison with the others in order to customize the session distribution on several hosts. If host A has twice the weight of host B, it will get twice the amount of sessions. In the example, host1 stores 20% of all the sessions [1/[1+2+2]] while host2 and host3 each store 40% [2/[1+2+2]]. The target host is determined once and for all at the start of the session, and doesn't change. The default weight is 1
  • timeout [float]. the connection timeout to a redis host, expressed in seconds. If the host is unreachable in that amount of time, the session storage will be unavailable for the client. The default timeout is very high [86400 seconds]
  • persistent [integer, should be 1 or 0]. defines if a persistent connection should be used
  • prefix [string, defaults to "PHPREDIS_SESSION. "]. used as a prefix to the Redis key in which the session is stored. The key is composed of the prefix followed by the session ID
  • auth [string, or an array with one or two elements]. used to authenticate with the server prior to sending commands
  • database [integer]. selects a different database

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

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
17. Trình xử lý phiên yêu cầu phiên bản Redis hỗ trợ các tùy chọn
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
18 và
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
19 của lệnh
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
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.
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
21

khó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

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000

Running the unit tests

phpredis 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

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel

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

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo

Classes and methods

Usage

Class Redis

Description. 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

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
22 command

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,
    ],
]];

Parameters

host. chuỗi. can be a host, or the path to a unix domain socket
port. int [default is 6379, should be -1 for unix domain socket]
connectTimeout. float, value in seconds [default is 0 meaning unlimited]
retryInterval. int, value in milliseconds [optional]
readTimeout. float, value in seconds [default is 0 meaning unlimited]
persistent. mixed, if value is string then it used as persistend id, else value casts to boolean
auth. mixed, authentication information
ssl. array, SSL context options

Class RedisException

phpredis 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

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23

Predefined constants

Description. Available Redis Constants

Redis data types, as returned by

Redis::REDIS_STRING - String
Redis::REDIS_SET - Set
Redis::REDIS_LIST - List
Redis::REDIS_ZSET - Sorted set
Redis::REDIS_HASH - Hash
Redis::REDIS_NOT_FOUND - Not found / other

@TODO. OPT_SERIALIZER, AFTER, BEFORE,

Connection

  1. - Connect to a server
  2. - Connect to a server [persistent]
  3. - Authenticate to the server
  4. - Change the selected database for the current connection
  5. - Swaps two Redis databases
  6. - Close the connection
  7. - Set client option
  8. - Get client option
  9. - Ping the server
  10. - Echo the given string

connect, open

Description. Kết nối với một phiên bản Redis

Parameters

host. 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
port. int, optional
timeout. float, value in seconds [optional, default is 0 meaning it will use default_socket_timeout]
reserved. should be '' if retry_interval is specified
retry_interval. int, value in milliseconds [optional]
read_timeout. float, value in seconds [optional, default is 0 meaning it will use default_socket_timeout]
others. array, with PhpRedis >= 5. 3. 0, it allows setting auth and stream configuration

Return value

BOOL.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 on success,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 on error

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']]];

Note.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
26 is an alias for
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
22 and will be removed in future versions of phpredis

kế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

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
28/
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
29

Kế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

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
30 to 1

This feature is not available in threaded versions.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
28 and
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
29 then working like their non persistent equivalents

Parameters

host. 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
port. int, optional
timeout. float, value in seconds [optional, default is 0 meaning it will use default_socket_timeout]
persistent_id. string. identity for the requested persistent connection
retry_interval. int, value in milliseconds [optional]
read_timeout. float, value in seconds [optional, default is 0 meaning it will use default_socket_timeout]

Return value

BOOL.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 on success,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 on error

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.

Note.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
29 is an alias for
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
28 and will be removed in future versions of phpredis

auth

Description. Authenticate the connection using a password or a username and password. Warning. The password is sent in plain-text over the network

Parameters

MIXED. password

Return value

BOOL.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 if the connection is authenticated,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 otherwise

Note. 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']];

select

Description. Change the selected database for the current connection

Parameters

INTEGER. dbindex, the database number to switch to

Return value

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 in case of success,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 in case of failure

Example

See method for example.

swapdb

Description. Swap one Redis database with another atomically

Parameters

INTEGER. db1
INTEGER. db2

Return value

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 on success and
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 on failure

Note. Requires Redis >= 4. 0. 0

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
0

close

Description. Disconnects from the Redis instance

Note. Closing a persistent connection requires PhpRedis >= 4. 2. 0

Parameters

None

Return value

BOOL.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 on success,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 on failure

setOption

Description. Set client option

Parameters

parameter name
parameter value

Return value

BOOL.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 on success,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 on error

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
1

getOption

Description. Get client option

Parameters

parameter name

Return value

Parameter value

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
2

ping

Description. Check the current connection status

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
3

Return value

Mixed. This method returns

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 on success, or the passed string if called with an argument

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
4

Note. Prior to PhpRedis 5. 0. 0 lệnh này chỉ đơn giản là trả về chuỗi

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
48

echo

Sự miêu tả. Gửi một chuỗi tới Redis, Redis trả lời bằng cùng một chuỗi

Parameters

CHUỖI. Tin nhắn để gửi

Return value

STRING. the same message

Retry and backoff

Maximum retries

You can set and get the maximum retries upon connection issues using the

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
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 10

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
5

Backoff algorithms

You can set the backoff algorithm using the

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
50 option and choose among the following algorithms described in this blog post by Marc Brooker from AWS. Exponential Backoff And Jitter

  • Default.
    # Run tests for Redis class [note this is the default]
    php tests/TestRedis.php --class Redis
    
    # Run tests for RedisArray class
    tests/mkring.sh start
    php tests/TestRedis.php --class RedisArray
    tests/mkring.sh stop
    
    # Run tests for the RedisCluster class
    tests/make-cluster.sh start
    php tests/TestRedis.php --class RedisCluster
    tests/make-cluster.sh stop
    
    # Run tests for RedisSentinel class
    php tests/TestRedis.php --class RedisSentinel
    
    51
  • Decorrelated jitter.
    # Run tests for Redis class [note this is the default]
    php tests/TestRedis.php --class Redis
    
    # Run tests for RedisArray class
    tests/mkring.sh start
    php tests/TestRedis.php --class RedisArray
    tests/mkring.sh stop
    
    # Run tests for the RedisCluster class
    tests/make-cluster.sh start
    php tests/TestRedis.php --class RedisCluster
    tests/make-cluster.sh stop
    
    # Run tests for RedisSentinel class
    php tests/TestRedis.php --class RedisSentinel
    
    52
  • Full jitter.
    # Run tests for Redis class [note this is the default]
    php tests/TestRedis.php --class Redis
    
    # Run tests for RedisArray class
    tests/mkring.sh start
    php tests/TestRedis.php --class RedisArray
    tests/mkring.sh stop
    
    # Run tests for the RedisCluster class
    tests/make-cluster.sh start
    php tests/TestRedis.php --class RedisCluster
    tests/make-cluster.sh stop
    
    # Run tests for RedisSentinel class
    php tests/TestRedis.php --class RedisSentinel
    
    53
  • Equal jitter.
    # Run tests for Redis class [note this is the default]
    php tests/TestRedis.php --class Redis
    
    # Run tests for RedisArray class
    tests/mkring.sh start
    php tests/TestRedis.php --class RedisArray
    tests/mkring.sh stop
    
    # Run tests for the RedisCluster class
    tests/make-cluster.sh start
    php tests/TestRedis.php --class RedisCluster
    tests/make-cluster.sh stop
    
    # Run tests for RedisSentinel class
    php tests/TestRedis.php --class RedisSentinel
    
    54
  • Exponential.
    # Run tests for Redis class [note this is the default]
    php tests/TestRedis.php --class Redis
    
    # Run tests for RedisArray class
    tests/mkring.sh start
    php tests/TestRedis.php --class RedisArray
    tests/mkring.sh stop
    
    # Run tests for the RedisCluster class
    tests/make-cluster.sh start
    php tests/TestRedis.php --class RedisCluster
    tests/make-cluster.sh stop
    
    # Run tests for RedisSentinel class
    php tests/TestRedis.php --class RedisSentinel
    
    55
  • Uniform.
    # Run tests for Redis class [note this is the default]
    php tests/TestRedis.php --class Redis
    
    # Run tests for RedisArray class
    tests/mkring.sh start
    php tests/TestRedis.php --class RedisArray
    tests/mkring.sh stop
    
    # Run tests for the RedisCluster class
    tests/make-cluster.sh start
    php tests/TestRedis.php --class RedisCluster
    tests/make-cluster.sh stop
    
    # Run tests for RedisSentinel class
    php tests/TestRedis.php --class RedisSentinel
    
    56
  • Constant.
    # Run tests for Redis class [note this is the default]
    php tests/TestRedis.php --class Redis
    
    # Run tests for RedisArray class
    tests/mkring.sh start
    php tests/TestRedis.php --class RedisArray
    tests/mkring.sh stop
    
    # Run tests for the RedisCluster class
    tests/make-cluster.sh start
    php tests/TestRedis.php --class RedisCluster
    tests/make-cluster.sh stop
    
    # Run tests for RedisSentinel class
    php tests/TestRedis.php --class RedisSentinel
    
    57

These algorithms depend on the base and cap parameters, both in milliseconds, which you can set using the

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
58 and
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
59 options, respectively

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
6

Server

  1. - Manage Redis ACLs
  2. - Asynchronously rewrite the append-only file
  3. - Asynchronously save the dataset to disk [in background]
  4. - Get or Set the Redis server configuration parameters
  5. - Return the number of keys in selected database
  6. - Remove all keys from all databases
  7. - Remove all keys from the current database
  8. - Get information and statistics about the server
  9. - Get the timestamp of the last disk save
  10. - Synchronously save the dataset to disk [wait to complete]
  11. - Make the server a slave of another instance, or promote it to master
  12. - Return the current server time
  13. - Access the Redis slowLog entries

acl

Description. Thực thi lệnh Redis ACL

Parameters

variable. Minumum of one argument for

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
60 and two for
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
61

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
7

Note. In order to user the

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
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 subcommand

Note. If you are connecting to Redis server >= 4. 0. 0 you can remove a key with the

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
63 method in the exact same way you would use
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
64. The Redis unlink command is non-blocking and will perform the actual deletion asynchronously

bgRewriteAOF

Description. Start the background rewrite of AOF [Append-Only File]

Parameters

None

Return value

BOOL.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 in case of success,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 in case of failure

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
8

bgSave

Description. Asynchronously save the dataset to disk [in background]

Parameters

None

Return value

BOOL.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 in case of success,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 in case of failure. If a save is already running, this command will fail and return
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
9

cấu hình

Sự miêu tả. Nhận hoặc Đặt tham số cấu hình máy chủ Redis

Prototype

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
0

Return value

Mảng kết hợp cho

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
70, [các] khóa -> [các] giá trị
bool cho
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
20,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
72 và
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
73

ví dụ

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
1

dbSize

Sự miêu tả. Trả về số lượng khóa trong cơ sở dữ liệu đã chọn

Parameters

None

Return value

số nguyên. Kích thước DB, theo số lượng khóa

Example

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
2

tuô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

Parameters

async [bool] yêu cầu phiên bản máy chủ 4. 0. 0 hoặc cao hơn

Return value

BOOL. Luôn luôn

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24

Example

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
3

tuôn raDb

Sự miêu tả. Xóa tất cả các khóa khỏi cơ sở dữ liệu hiện tại

Prototype

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
4

Return value

BOOL. Lệnh này trả về true nếu thành công và false nếu thất bại

Example

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
5

thông tin

Sự 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

  • redis_version
  • Arch_bits
  • thời gian hoạt động_in_giây
  • thời gian hoạt động_trong_ngày
  • connect_clients
  • kết nối_slaves
  • used_memory
  • changes_since_last_save
  • bgsave_in_progress
  • last_save_time
  • tổng_kết nối_đã nhận
  • tổng_lệnh_đã xử lý
  • vai diễn

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ề

Parameters

quyền mua. Tùy chọn cung cấp redis [e. g. "THỐNG KÊ LỆNH", "CPU"]

Example

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
6

lần lưu cuối cùng

Sự miêu tả. Trả về dấu thời gian của lần lưu đĩa cuối cùng

Parameters

None

Return value

INT. dấu thời gian

Example

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
7

tiết kiệm

Sự miêu tả. Lưu đồng bộ tập dữ liệu vào đĩa [chờ hoàn tất]

Parameters

None

Return value

BOOL.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 in case of success,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 in case of failure. If a save is already running, this command will fail and return
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23

Example

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
8

nô lệ của

Sự miêu tả. Thay đổi trạng thái nô lệ

Parameters

Máy chủ [chuỗi] và cổng [int] hoặc không có tham số nào ngừng làm nô lệ

Return value

BOOL.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 in case of success,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 in case of failure

Example

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
9

thời gian

Sự miêu tả. Trả về thời gian máy chủ hiện tại

Parameters

[không ai]

Return value

Nế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ụ

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
0

Nhật ký chậm

Sự miêu tả. Truy cập Redis SlowLog

Parameters

Hoạt động [chuỗi]. Đây có thể là

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
70,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
81 hoặc
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
82
Độ dài [số nguyên], tùy chọn. Nếu thực hiện lệnh
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
83, bạn có thể truyền độ dài tùy chọn

Return value

Giá 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ụ

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
1

Chìa khóa và Chuỗi

Dây

  • - Nối một giá trị vào một khóa
  • - Đếm các bit đã đặt trong một chuỗi
  • - Thực hiện các hoạt động bitwise giữa các chuỗi
  • - Giảm giá trị của khóa
  • - Lấy giá trị của một khóa
  • - Trả về giá trị bit ở phần bù trong giá trị chuỗi được lưu trữ tại khóa
  • - Lấy một chuỗi con của chuỗi được lưu trữ tại một khóa
  • - Đặt giá trị chuỗi của khóa và trả về giá trị cũ của nó
  • - Tăng giá trị của khóa
  • - Tăng giá trị float của một khóa theo số lượng đã cho
  • - Get the values of all the given keys
  • - Set multiple keys to multiple values
  • - Set the string value of a key
  • - Sets or clears the bit at offset in the string value stored at key
  • - Set the value and expiration of a key
  • - Set the value of a key, only if the key does not exist
  • - Overwrite part of a string at key starting at the specified offset
  • - Get the length of the value stored in a key

Keys

  • - Delete a key
  • - Return a serialized version of the value stored at the specified key
  • - Determine if a key exists
  • - Set a key's time to live in seconds
  • - Set the expiration for a key as a UNIX timestamp
  • - Find all keys matching the given pattern
  • - Scan for keys in the keyspace [Redis >= 2. 8. 0]
  • - Atomically transfer a key from a Redis instance to another one
  • - Move a key to another database
  • - Inspect the internals of Redis objects
  • - Remove the expiration from a key
  • - Trả về một khóa ngẫu nhiên từ keyspace
  • - Đổi tên khóa
  • - Rename a key, only if the new key does not exist
  • - Determine the type stored at key
  • - Sort the elements in a list, set or sorted set
  • - Get the time to live for a key
  • - Create a key using the provided serialized value, previously obtained with

get

Description. Get the value related to the specified key

Parameters

key

Return value

String or Bool. If key didn't exist,

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 is returned. Otherwise, the value related to this key is returned

ví dụ

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
2

set

Description. 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

Parameters

Key
Value
Timeout or Options Array [optional]. If you pass an integer, phpredis will redirect to SETEX, and will try to use Redis >= 2. 6. 12 extended options if you pass an array with valid values

Return value

Bool

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 if the command is successful

ví dụ

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
3

setEx, pSetEx

Description. Set the string value in argument as value of the key, with a time to live. PSETEX uses a TTL in milliseconds

Parameters

Key TTL Value

Return value

Bool

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 if the command is successful

ví dụ

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
4

setNx

Sự miêu tả. Set the string value in argument as value of the key if the key doesn't already exist in the database

Parameters

key value

Return value

Bool

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 in case of success,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 in case of failure

ví dụ

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
5

del, delete, unlink

Description. Remove specified keys

Parameters

An 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

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
63 method in the exact same way you would use
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
64. The Redis unlink command is non-blocking and will perform the actual deletion asynchronously

Return value

Long Number of keys deleted

ví dụ

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
6

Note.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
91 is an alias for
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
64 and will be removed in future versions of phpredis

exists

Description. Verify if the specified key exists

Parameters

key

Return value

long. The number of keys tested that do exist

ví dụ

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
7

Note. This function took a single argument and returned TRUE or FALSE in phpredis versions < 4. 0. 0

incr, incrBy

Description. 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

Parameters

key
value. value that will be added to key [only for incrBy]

Return value

INT the new value

ví dụ

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
8

incrByFloat

Description. Increment the key with floating point precision

Parameters

key
value. [float] value that will be added to the key

Return value

FLOAT the new value

ví dụ

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
9

decr, decrBy

Description. 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

Parameters

key
value. value that will be subtracted to key [only for decrBy]

Return value

INT the new value

ví dụ

$redis = new Redis[];
0

mGet, getMultiple

Description. Get the values of all the specified keys. If one or more keys don't exist, the array will contain

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 at the position of the key

Parameters

Array. Array containing the list of the keys

Return value

Array. Array containing the values related to keys in argument

ví dụ

$redis = new Redis[];
1

Note.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
94 is an alias for
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
95 and will be removed in future versions of phpredis

getSet

Description. Sets a value and returns the previous entry at that key

Parameters

Key. key

STRING. value

Return value

A string, the previous value located at this key

Example

$redis = new Redis[];
2

randomKey

Description. Returns a random key

Parameters

None

Return value

STRING. an existing key in redis

Example

$redis = new Redis[];
3

move

Description. Moves a key to a different database

Parameters

Key. chìa khóa, chìa khóa để di chuyển

INTEGER. dbindex, the database number to move the key to

Return value

BOOL.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 in case of success,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 in case of failure

Example

$redis = new Redis[];
4

rename, renameKey

Description. Renames a key

Parameters

STRING. srckey, the key to rename

STRING. dstkey, the new name for the key

Return value

BOOL.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 in case of success,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 in case of failure

Example

$redis = new Redis[];
5

Note.

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
00 is an alias for
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
01 and will be removed in future versions of phpredis

renameNx

Sự 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ạn

Sự 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 value

BOOL.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 nếu thời hạn đã được đặt và
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
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
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
04

Example

$redis = new Redis[];
7

Note.

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
05 is an alias for
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
06 and will be removed in future versions of phpredis

expireAt, pexpireAt

Description. Seta specific timestamp for a key to expire in seconds or milliseconds

Prototype

$redis = new Redis[];
8

Return value

BOOL.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 if an expiration was set and
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 if one was not set or in the event on an error. You can detect an actual error by checking
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
04

Example

$redis = new Redis[];
9

keys, getKeys

Description. Returns the keys that match a certain pattern

Parameters

STRING. pattern, using '*' as a wildcard

Return value

Array 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.

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
10 is an alias for
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
11 and will be removed in future versions of phpredis

scan

Description. Scan the keyspace for keys

Parameters

LONG [reference]. Iterator, initialized to NULL STRING, Optional. Pattern to match LONG, Optional. Count of keys per iteration [only a suggestion to Redis]

Return value

Array, 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êu

Description. Describes the object pointed to by a key

Parameters

The information to retrieve [string] and the key [string]. Info can be one of the following

  • "encoding"
  • "refcount"
  • "idletime"
Return value

STRING for "encoding", LONG for "refcount" and "idletime",

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 if the key doesn't exist

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,
    ],
]];
2

type

Description. Returns the type of data pointed by a given key

Parameters

Key. key

Return value

Depending on the type of the data pointed by the key, this method will return the following value
string. Redis. REDIS_STRING
set. Redis. REDIS_SET
list. Redis. REDIS_LIST
zset. Redis. REDIS_ZSET
hash. Redis. REDIS_HASH
other. Redis. REDIS_NOT_FOUND

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

append

Description. Append specified string to the string stored in specified key

Parameters

Key Value

Return value

INTEGER. 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

getRange

Description. Return a substring of a larger string

Parameters

key
start
end

Return value

STRING. 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.

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
13 is an alias for
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
14 and will be removed in future versions of phpredis

setRange

Description. Changes a substring of a larger string

Parameters

giá trị bù khóa

Return value

STRING. 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

strLen

Description. Get the length of a string value

Parameters

key

Return value

INTEGER

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

getBit

Description. Return a single bit out of a larger string

Parameters

key
offset

Return value

LONG. 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

setBit

Description. Changes a single bit of a string

Parameters

key
offset
value. bool or int [1 or 0]

Return value

LONG. 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

bitOp

Description. Bitwise operation on multiple keys

Parameters

operation. either "AND", "OR", "NOT", "XOR"
ret_key. return key
key1
key2

Return value

LONG. The size of the string stored in the destination key

bitCount

Description. Count bits in a string

Parameters

key

Return value

LONG. The number of bits set to 1 in the value behind the input key

sort

Description. Sort the elements in a list, set or sorted set

Parameters

Key. key Options. [key => value, . ] - optional, with the following keys and values

Redis::REDIS_STRING - String
Redis::REDIS_SET - Set
Redis::REDIS_LIST - List
Redis::REDIS_ZSET - Sorted set
Redis::REDIS_HASH - Hash
Redis::REDIS_NOT_FOUND - Not found / other
0

Return value

An array of values, or a number corresponding to the number of elements stored if that was used

Example

Redis::REDIS_STRING - String
Redis::REDIS_SET - Set
Redis::REDIS_LIST - List
Redis::REDIS_ZSET - Sorted set
Redis::REDIS_HASH - Hash
Redis::REDIS_NOT_FOUND - Not found / other
1

ttl, pttl

Description. Returns the time to live left for a given key in seconds [ttl], or milliseconds [pttl]

Parameters

Key. key

Return value

LONG. The time to live in seconds. If the key has no ttl,

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
15 will be returned, and
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
16 if the key doesn't exist

Example

Redis::REDIS_STRING - String
Redis::REDIS_SET - Set
Redis::REDIS_LIST - List
Redis::REDIS_ZSET - Sorted set
Redis::REDIS_HASH - Hash
Redis::REDIS_NOT_FOUND - Not found / other
2

persist

Description. Remove the expiration timer from a key

Parameters

Key. key

Return value

BOOL.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 if a timeout was removed,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 if the key didn’t exist or didn’t have an expiration timer

Example

Redis::REDIS_STRING - String
Redis::REDIS_SET - Set
Redis::REDIS_LIST - List
Redis::REDIS_ZSET - Sorted set
Redis::REDIS_HASH - Hash
Redis::REDIS_NOT_FOUND - Not found / other
3

mSet, mSetNx

Sự miêu tả. Sets multiple key-value pairs in one atomic command. MSETNX only returns TRUE if all the keys were set [see SETNX]

Parameters

Pairs. [key => value, . ]

Return value

Bool

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 in case of success,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 in case of failure

Example

Redis::REDIS_STRING - String
Redis::REDIS_SET - Set
Redis::REDIS_LIST - List
Redis::REDIS_ZSET - Sorted set
Redis::REDIS_HASH - Hash
Redis::REDIS_NOT_FOUND - Not found / other
4

Output

Redis::REDIS_STRING - String
Redis::REDIS_SET - Set
Redis::REDIS_LIST - List
Redis::REDIS_ZSET - Sorted set
Redis::REDIS_HASH - Hash
Redis::REDIS_NOT_FOUND - Not found / other
5

dump

Description. 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

Parameters

key string

Return value

The Redis encoded value of the key, or FALSE if the key doesn't exist

ví dụ

Redis::REDIS_STRING - String
Redis::REDIS_SET - Set
Redis::REDIS_LIST - List
Redis::REDIS_ZSET - Sorted set
Redis::REDIS_HASH - Hash
Redis::REDIS_NOT_FOUND - Not found / other
6

restore

Description. Restore a key from the result of a DUMP operation

Parameters

key string. The key name
ttl integer. How long the key should live [if zero, no expire will be set on the key]
value string [binary]. The Redis encoded key value [from DUMP]

ví dụ

Redis::REDIS_STRING - String
Redis::REDIS_SET - Set
Redis::REDIS_LIST - List
Redis::REDIS_ZSET - Sorted set
Redis::REDIS_HASH - Hash
Redis::REDIS_NOT_FOUND - Not found / other
7

migrate

Description. 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

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
21 with an array of keys

Parameters

host string. The destination host
port integer. The TCP port to connect to
key[s] string or array
destination-db integer. The target DB
timeout integer. The maximum amount of time given to this transfer
copy boolean, optional. Should we send the COPY flag to redis
replace boolean, optional. Should we send the REPLACE flag to redis

ví dụ

Redis::REDIS_STRING - String
Redis::REDIS_SET - Set
Redis::REDIS_LIST - List
Redis::REDIS_ZSET - Sorted set
Redis::REDIS_HASH - Hash
Redis::REDIS_NOT_FOUND - Not found / other
8

Hashes

  • - Delete one or more hash fields
  • - Determine if a hash field exists
  • - Get the value of a hash field
  • - Get all the fields and values in a hash
  • - Increment the integer value of a hash field by the given number
  • - Increment the float value of a hash field by the given amount
  • - Get all the fields in a hash
  • - Get the number of fields in a hash
  • - Get the values of all the given hash fields
  • - Set multiple hash fields to multiple values
  • - Set the string value of a hash field
  • - Set the value of a hash field, only if the field does not exist
  • - Get all the values in a hash
  • - Scan a hash key for members
  • - Get the string length of the value associated with field in the hash

hSet

Description. Adds a value to the hash stored at key

Parameters

key
hashKey
value

Return value

LONG

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
22 if value didn't exist and was added successfully,
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
23 if the value was already present and was replaced,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 if there was an error

Example

Redis::REDIS_STRING - String
Redis::REDIS_SET - Set
Redis::REDIS_LIST - List
Redis::REDIS_ZSET - Sorted set
Redis::REDIS_HASH - Hash
Redis::REDIS_NOT_FOUND - Not found / other
9

hSetNx

Description. Adds a value to the hash stored at key only if this field isn't already in the hash

Return value

BOOL

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 if the field was set,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 if it was already present

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']]];
0

hGet

Description. Gets a value from the hash stored at key. If the hash table doesn't exist, or the key doesn't exist,

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 is returned

Parameters

key
hashKey

Return value

STRING The value, if the command executed successfully
BOOL

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 in case of failure

hLen

Description. Returns the length of a hash, in number of items

Parameters

key

Return value

LONG the number of items in a hash,

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 if the key doesn't exist or isn't a 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']]];
1

hDel

Description. Removes a value from the hash stored at key. If the hash table doesn't exist, or the key doesn't exist,

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 is returned

Parameters

key
hashKey1
hashKey2
...

Return value

LONG số lượng khóa đã xóa, 0 nếu khóa không tồn tại,

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 nếu khóa không phải là hàm băm

hKeys

Sự 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

Parameters

Key. key

Return value

Mộ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

hVals

Description. Returns the values in a hash, as an array of strings

Parameters

Key. key

Return value

An 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

hGetAll

Description. Returns the whole hash, as an array of strings indexed by strings

Parameters

Key. key

Return value

An 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

hExists

Description. Verify if the specified member exists in a key

Parameters

key
memberKey

Return value

BOOL. If the member exists in the hash table, return

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24, otherwise return
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23

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']]];
8

hIncrBy

Description. Increments the value of a member from a hash by a given amount

Parameters

key
member
value. [integer] value that will be added to the member's value

Return value

LONG 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

hIncrByFloat

Description. Increments the value of a hash member by the provided float value

Parameters

key
member
value. [float] value that will be added to the member's value

Return value

FLOAT 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

hMSet

Description. Điền vào toàn bộ hàm băm. Non-string values are converted to string, using the standard

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
34 cast. NULL values are stored as empty strings

Parameters

key
members. key → value array

Return value

BOOL

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

hMGet

Description. Retrieve the values associated to the specified fields in the hash

Parameters

key
memberKeys Array

Return value

Array 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

hScan

Description. Scan a HASH value for members, with an optional pattern and count

Parameters

key. String
iterator. Long [reference]
pattern. Optional pattern to match against
count. How many keys to return in a go [only a suggestion to Redis]

Return value

Array 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

hStrLen

Description. Get the string length of the value associated with field in the hash stored at key

Parameters

key. String
field. String

Return value

LONG 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

  • - Remove and get the first/last element in a list
  • - Pop a value from a list, push it to another list and return it
  • - Get an element from a list by its index
  • - Insert an element before or after another element in a list
  • - Get the length/size of a list
  • - Remove and get the first element in a list
  • - Prepend one or multiple values to a list
  • - Prepend a value to a list, only if the list exists
  • - Get a range of elements from a list
  • - Remove elements from a list
  • - Set the value of an element in a list by its index
  • - Trim a list to the specified range
  • - Remove and get the last element in a list
  • - Remove the last element in a list, append it to another list and return it [redis >= 1. 1]
  • - Append one or multiple values to a list
  • - Append a value to a list, only if the list exists

blPop, brPop

Description. 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

Parameters

ARRAY Array containing the keys of the lists
INTEGER Timeout
Or
STRING Key1
STRING Key2
STRING Key3
...
STRING Keyn
INTEGER Timeout

Return value

ARRAY ['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

bRPopLPush

Description. A blocking version of

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
35, with an integral timeout in the third parameter

Parameters

Key. srckey
Key. dstkey
Long. hết giờ

Return value

STRING Phần tử đã được di chuyển trong trường hợp thành công,

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 trong trường hợp hết thời gian chờ

lChỉ mục, lNhận

Sự 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
-1 phần tử cuối cùng, -2 phần tử áp chót

Return

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 in case of a bad index or a key that doesn't point to a list

Parameters

key
index

Return value

String the element at this index
Bool

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 if the key identifies a non-string data type, or no value corresponds to this index in the list
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
39

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.
5

Note.

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
40 is an alias for
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
41 and will be removed in future versions of phpredis

lInsert

Description. 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

Parameters

key
position Redis. BEFORE . Redis. AFTER
pivot
value

Return value

The 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

lPop

Description. Return and remove the first element of the list

Parameters

key

Return value

STRING if command executed successfully
BOOL

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
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

lPush

Description. 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,

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 is returned

Prototype

$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 value

LONG The new length of the list in case of success,

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 in case of Failure

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.
9

lPushx

Description. Adds the string value to the head [left] of the list if the list exists

Parameters

key
value String, value to push in key

Return value

LONG The new length of the list in case of success,

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 in case of Failure

ví 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, lGetRange

Description. Returns the specified elements of the list stored at the specified key in the range [start, end]. start and stop are interpreted as indices
0 phần tử đầu tiên, 1 phần thứ hai
-1 phần tử cuối cùng, -2 phần tử áp chót

Parameters

key
start
end

Return value

Array 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.

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
46 is an alias for
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
47 and will be removed in future versions of phpredis

lRem, lRemove

Description. Removes the first

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
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 head

Note. The argument order is not the same as in the Redis documentation. This difference is kept for compatibility reasons

Parameters

key
value
count

Return value

LONG the number of elements to remove
BOOL

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 if the value identified by key is not a 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']];
2

Note.

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
50 is an alias for
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
51 and will be removed in future versions of phpredis

lSet

Description. Set the list at index with the new value

Parameters

key
index
value

Return value

BOOL

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 if the new value was set.
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 if the index is out of range, or data type identified by key is not a 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']];
3

lTrim, listTrim

Description. Trims an existing list so that it will contain only a specified range of elements

Parameters

key
start
stop

Return value

Array
Bool return

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 if the key identify a non-list value

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']];
4

Note.

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
55 is an alias for
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
56 and will be removed in future versions of phpredis

rPop

Description. Returns and removes the last element of the list

Parameters

key

Return value

STRING if command executed successfully
BOOL

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
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

rPopLPush

Description. 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]

Parameters

Key. srckey
Key. dstkey

Return value

STRING The element that was moved in case of success,

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 in case of failure

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']];
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

rPush

Description. 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 value

LONG The new length of the list in case of success,

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 in case of Failure

ví 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

rPushX

Sự miêu tả. Adds the string value to the tail [right] of the list if the list exists.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 in case of Failure

Parameters

key
value String, value to push in key

Return value

LONG The new length of the list in case of success,

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 in case of Failure

ví dụ

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
00

lLen, lSize

Description. 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

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23

Parameters

Key

Return value

LONG The size of the list identified by Key exists
BOOL

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 if the data type identified by Key is not list

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
01

Note.

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
64 is an alias for
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
65 and will be removed in future versions of phpredis

Sets

  • - Thêm một hoặc nhiều thành viên vào một bộ
  • - Get the number of members in a set
  • - Subtract multiple sets
  • - Subtract multiple sets and store the resulting set in a key
  • - Intersect multiple sets
  • - Intersect multiple sets and store the resulting set in a key
  • - Determine if a given value is a member of a set
  • - Get all the members in a set
  • - Move a member from one set to another
  • - Remove and return one or more members of a set at random
  • - Get one or multiple random members from a set
  • - Remove one or more members from a set
  • - Add multiple sets
  • - Add multiple sets and store the resulting set in a key
  • - Scan a set for members

sAdd

Description. Adds a value to the set value stored at key

Parameters

key
value

Return value

LONG the number of elements added to the set

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
02

sCard, sSize

Description. Returns the cardinality of the set identified by key

Parameters

key

Return value

LONG the cardinality of the set identified by key, 0 if the set doesn't exist

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
03

Note.

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
66 is an alias for
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
67 and will be removed in future versions of phpredis

sDiff

Description. Performs the difference between N sets and returns it

Parameters

Keys. key1, key2, . , keyN. Any number of keys corresponding to sets in redis

Return value

Array of strings. The difference of the first set will all the others

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
04

Return value. all elements of s0 that are neither in s1 nor in s2

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
05

sDiffStore

Description. 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

Parameters

Key. dstkey, the key to store the diff into

Keys. key1, key2, . , keyN. Any number of keys corresponding to sets in redis

Return value

INTEGER. The cardinality of the resulting set, or

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 in case of a missing key

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
06

Return value. the number of elements of s0 that are neither in s1 nor in s2

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
07

sInter

Description. 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,

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 is returned

Parameters

key1, key2, keyN. keys identifying the different sets on which we will apply the intersection

Return value

Array, 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ụ

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
08

Output

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
09

sInterStore

Description. Performs a sInter command and stores the result in a new set

Parameters

Key. dstkey, the key to store the diff into

Keys. key1, key2. keyN. key1. keyN are intersected as in sInter

Return value

INTEGER. The cardinality of the resulting set, or

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 in case of a missing key

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
10

Output

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
11

sIsMember, sContains

Description. Checks if

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
71 is a member of the set stored at the key
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
72

Parameters

key
value

Return value

BOOL

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 if
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
71 is a member of the set at key
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
72,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 otherwise

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
12

Note.

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
77 is an alias for
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
78 and will be removed in future versions of phpredis

sMembers, sGetMembers

Description. Returns the contents of a set

Parameters

Key. key

Return value

An array of elements, the contents of the set

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
13

Output

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
14

The order is random and corresponds to redis' own internal representation of the set structure

Note.

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
79 is an alias for
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
80 and will be removed in future versions of phpredis

sMove

Description. Moves the specified member from the set at srcKey to the set at dstKey

Parameters

srcKey
dstKey
member

Return value

BOOL If the operation is successful, return

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24. If the srcKey and/or dstKey didn't exist, and/or the member didn't exist in srcKey,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 is returned

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
15

sPop

Description. Removes and returns a random element from the set value at Key

Parameters

key
đếm. Integer, optional

Return value [without count argument]

String "popped" value
Bool

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 if set identified by key is empty or doesn't exist

Return value [with count argument]

Array. Member[s] returned or an empty array if the set doesn't exist
Bool.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 on error if the key is not a set

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
16

sRandMember

Description. Returns a random element from the set value at Key, without removing it

Parameters

key
count [Integer, optional]

Return value

If 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

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 if set identified by key is empty or doesn't exist

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
17

sRem, sRemove

Description. Removes the specified member from the set value stored at key

Parameters

key
member

Return value

LONG Số phần tử bị xóa khỏi tập hợp

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
18

Ghi chú.

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
86 is an alias for
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
87 and will be removed in future versions of phpredis

sUnion

Description. Performs the union between N sets and returns it

Parameters

Keys. key1, key2, . , keyN. Any number of keys corresponding to sets in redis

Return value

Array of strings. The union of all these sets

Note.

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
88 can also take a single array with keys [see example below]

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
19

Return value. all elements that are either in s0 or in s1 or in s2

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
20

sUnionStore

Description. Performs the same action as sUnion, but stores the result in the first key

Parameters

Key. dstkey, the key to store the diff into

Keys. key1, key2, . , keyN. Any number of keys corresponding to sets in redis

Return value

INTEGER. The cardinality of the resulting set, or

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 in case of a missing key

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
21

Return value. the number of elements that are either in s0 or in s1 or in s2

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
22

sScan

Description. Scan a set for members

Parameters

Key. The set to search
iterator. LONG [reference] to the iterator as we go
pattern. String, optional pattern to match against
count. Số lượng thành viên trả lại cùng một lúc [Redis có thể trả lại một số tiền khác]

Return value

Array, boolean. PHPRedis will return an array of keys or FALSE when we're done iterating

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
23

Sorted sets

  • - Block until Redis can pop the highest or lowest scoring member from one or more ZSETs
  • - Add one or more members to a sorted set or update its score if it already exists
  • - Get the number of members in a sorted set
  • - Count the members in a sorted set with scores within the given values
  • - Increment the score of a member in a sorted set
  • - Intersect multiple sorted sets and store the resulting sorted set in a new key
  • - Redis can pop the highest or lowest scoring member from one a ZSET
  • - Return a range of members in a sorted set, by index
  • - Return a range of members in a sorted set, by score
  • - Return a lexicographical range from members that share the same score
  • - Determine the index of a member in a sorted set
  • - Remove one or more members from a sorted set
  • - Remove all members in a sorted set within the given indexes
  • - Remove all members in a sorted set within the given scores
  • - Return a range of members in a sorted set, by index, with scores ordered from high to low
  • - Get the score associated with the given member in a sorted set
  • - Add multiple sorted sets and store the resulting sorted set in a new key
  • - Scan a sorted set for members

bzPop

Description. Block until Redis can pop the highest or lowest scoring members from one or more ZSETs. There are two commands [

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
90 and
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
91 for popping the lowest and highest scoring elements respectively. ]

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
24

Return value

ARRAY. 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

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
25

Note. Calling these functions with an array of keys or with a variable number of arguments is functionally identical

zAdd

Description. Add one or more members to a sorted set or update its score if it already exists

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
26

Parameters

key. string options. array [optional] score. double
value. string score1. double value1. string

Return value

Long 1 if the element is added. 0 otherwise

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
27

zCard, zSize

Description. Returns the cardinality of an ordered set

Parameters

key

Return value

Long, the set's cardinality

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
28

Note.

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
92 is an alias for
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
93 and will be removed in future versions of phpredis

zCount

Description. 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

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
94 or
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
95 excludes it from the range. +inf and -inf are also valid limits

Parameters

key
start. string
end. string

Return value

DÀI kích thước của zRangeByScore tương ứng

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
29

zIncrBy

Description. Increments the score of a member from a sorted set by a given amount

Parameters

key
value. [double] value that will be added to the member's score
member

Return value

DOUBLE the new value

ví dụ

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
30

zinterstore, zInter

Description. 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

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
96 to apply to the sorted sets in input. In this case, the
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
96 will be multiplied by the score of each element in the sorted set before applying the aggregation. The forth argument defines the
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
98 option which specify how the results of the union are aggregated

Parameters

keyOutput
arrayZSetKeys
arrayWeights
aggregateFunction Either "SUM", "MIN", or "MAX". defines the behaviour to use on duplicate entries during the zinterstore

Return value

LONG The number of values in the new sorted set

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
31

Note.

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
99 is an alias for
$redis = new Redis[];
00 and will be removed in future versions of phpredis

zPop

Description. 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

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
32

Return value

ARRAY. 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

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
33

zRange

Description. 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

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
23 the first element,
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
22 the second
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
15 the last element,
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
16 the penultimate

Parameters

key start. Dài
kết thúc. Dài
có điểm. bool = sai

Return value

Array containing the values in specified range

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
34

zRangeByScore, zRevRangeByScore

Sự 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

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
94 hoặc
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
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ố
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
94 và
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
95 được hoán đổi

Parameters

key
start. string
end. string
tùy chọn. mảng

Hai tùy chọn có sẵn.

$redis = new Redis[];
11 và
$redis = new Redis[];
12

Return value

Array containing the values in specified range

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
35

zRangeByLex

Sự 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

Parameters

Chìa khóa. ZSET mà bạn muốn đối đầu
tối thiểu. Giá trị chữ và số tối thiểu bạn muốn nhận
tối đa. Giá trị chữ và số tối đa bạn muốn nhận
offset. Optional argument if you wish to start somewhere other than the first element
limit. Optional argument if you wish to limit the number of elements returned

Return value

Array containing the values in the specified range

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
36

zRank, zRevRank

Description. 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

Parameters

key
member

Return value

Long, the item's rank

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
37

zRem, zDelete, zRemove

Description. Delete one or more members from a sorted set

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
38

Return value

LONG. The number of members deleted

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
39

Note.

$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, zDeleteRangeByRank

Description. Deletes the elements of the sorted set stored at the specified key which have rank in the range [start,end]

Parameters

key
start. LONG
end. LONG

Return value

LONG The number of values deleted from the sorted set

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
40

Note.

$redis = new Redis[];
16 is an alias for
$redis = new Redis[];
17 and will be removed in future versions of phpredis

zRemRangeByScore, zDeleteRangeByScore, zRemoveRangeByScore

Description. Deletes the elements of the sorted set stored at the specified key which have scores in the range [start,end]

Parameters

key
start. double or "+inf" or "-inf" string
end. double or "+inf" or "-inf" string

Return value

LONG The number of values deleted from the sorted set

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
41

Note.

$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

zRevRange

Description. 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

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
23 the first element,
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
22 the second
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
15 the last element,
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
16 the penultimate

Parameters

key
start. long
kết thúc. Dài
có điểm. bool = sai

Return value

Array containing the values in specified range

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
42

zScore

Description. Returns the score of a given member in the specified sorted set

Parameters

key
member

Return value

Double or FALSE when the value is not found

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
43

zunionstore, zUnion

Description. 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

# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
96 to apply to the sorted sets in input. In this case, the
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
96 will be multiplied by the score of each element in the sorted set before applying the aggregation. The forth argument defines the
# Just run the 'echo' test
php tests/TestRedis.php --class Redis --test echo
98 option which specify how the results of the union are aggregated

Parameters

keyOutput
arrayZSetKeys
arrayWeights
aggregateFunction Either "SUM", "MIN", or "MAX". defines the behaviour to use on duplicate entries during the zunionstore

Return value

LONG The number of values in the new sorted set

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
44

Note.

$redis = new Redis[];
28 is an alias for
$redis = new Redis[];
29 and will be removed in future versions of phpredis

zScan

Description. Scan a sorted set for members, with optional pattern and count

Parameters

key. String, the set to scan
iterator. Long [reference], initialized to NULL
pattern. String [optional], the pattern to match
count. How many keys to return per iteration [Redis might return a different number]

Return value

Array, boolean PHPRedis will return matching keys from Redis, or FALSE when iteration is complete

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
45

HyperLogLogs

pfAdd

Description. Adds the specified elements to the specified HyperLogLog

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
46

Parameters

Key
Array of values

Return value

Integer. 1 if at least 1 HyperLogLog internal register was altered. 0 otherwise

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
47

pfCount

Description. Return the approximated cardinality of the set[s] observed by the HyperLogLog at key[s]

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
48

Parameters

Key or Array of keys

Return value

Integer. The approximated number of unique elements observed via

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
49

pfMerge

Description. Merge N different HyperLogLogs into a single one

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
50

Parameters

Destination Key
Mảng khóa nguồn

Return value

BOOL.

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
24 on success,
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23 on error

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
51

Geocoding

thêm địa lý

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
52

Description. 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 value

Integer. The number of elements added to the geospatial key

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
53

geoHash

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
54

Description. Retrieve Geohash strings for one or more elements of a geospatial index

Return value

Array. One or more Redis Geohash encoded strings

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
55

Output

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
56

geoPos

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
57

Description. Return longitude, latitude positions for each requested member

Return value

Array. One or more longitude/latitude positions

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
58

Output

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
59

GeoDist

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
60

Description. Return the distance between two members in a geospatial set. If units are passed it must be one of the following values

  • 'm' => Meters
  • 'km' => Kilometers
  • 'mi' => Miles
  • 'ft' => Feet
Return value

Double. The distance between the two passed members in the units requested [meters by default]

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
61

Output

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
62

geoRadius

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
63

Description. Return members of a set with geospatial information that are within the radius specified by the caller

Options Array

The 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 key

Note. 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 value

Mixed. 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

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
64

Output

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
65

geoRadiusByMember

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
66

Description. 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 Array

See command for options array

Return value

Array. The zero or more entries that are close enough to the member given the distance and radius specified

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
67

Output

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
68

Streams

  • - Acknowledge one or more pending messages
  • - Add a message to a stream
  • - Acquire ownership of a pending message
  • - Remove a message from a stream
  • - Manage consumer groups
  • - Get information about a stream
  • - Get the length of a stream
  • - Inspect pending messages in a stream
  • - Query a range of messages from a stream
  • - Read message[s] from a stream
  • - Read stream messages with a group and consumer
  • - Query one or more messages from end to start
  • - Trim a stream's size

xAck

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
69

Description. Acknowledge one or more messages on behalf of a consumer group

Return value

long. The number of messages Redis reports as acknowledged

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
70

xAdd

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
71

Description. Add a message to a stream

Return value

String. The added message ID

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
72

xClaim

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
73

Description. Claim ownership of one or more pending messages

Options Array

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
74

Return value

Mảng. Either an array of message IDs along with corresponding data, or just an array of IDs [if the 'JUSTID' option was passed]

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
75

xDel

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
76

Description. Delete one or more messages from a stream

Return value

long. The number of messages removed

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
77

xGroup

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
78

Description. This command is used in order to create, destroy, or manage consumer groups

Return value

Mixed. This command returns different types depending on the specific XGROUP command executed

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
79

xInfo

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
80

Description. Get information about a stream or consumer groups

Return value

Mixed. This command returns different types depending on which subcommand is used

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
81

xLen

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
82

Description. Get the length of a given stream

Return value

Dài. Số lượng tin nhắn trong luồng

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
83

xĐang chờ xử lý

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
84

Sự miêu tả. Get information about pending messages in a given stream

Return value

Array. Information about the pending messages, in various forms depending on the specific invocation of XPENDING

ví dụ

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
85

xRange

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
86

Description. Nhận một loạt tin nhắn từ một luồng nhất định

Return value

Mảng. Các tin nhắn trong luồng trong phạm vi được yêu cầu

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
87

xĐọc

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
88

Sự 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 value

Mảng. Tin nhắn trong luồng mới hơn ID được chuyển đến Redis [nếu có]

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
89

xReadGroup

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
90

Sự 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 value

Mảng. Các tin nhắn gửi đến nhóm người tiêu dùng này [nếu có]

ví dụ

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
91

xRevRange

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
92

Sự 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 value

Mảng. Các tin nhắn trong phạm vi được chỉ định

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
93

xTrim

Prototype

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
94

Sự 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 value

Dài. Số lượng tin nhắn được cắt bớt từ luồng

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
95

Quán rượu/phụ

  • - Subscribe to channels by pattern
  • - Đăng tin nhắn lên một kênh
  • - Đăng ký kênh
  • - Nội quan vào hệ thống phụ quán rượu / phụ

pĐăng ký

Sự miêu tả. Đăng ký kênh theo mẫu

Parameters

hoa văn. Một loạt các mẫu để phù hợp
gọi lại. Một chuỗi hoặc một mảng với một đối tượng và phương thức. Cuộc gọi lại sẽ nhận được bốn đối số [$redis, $pattern, $channel, $message]
giá trị trả về. Trộn. Bất kỳ giá trị trả về khác null nào trong cuộc gọi lại sẽ được trả lại cho người gọi

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
96

publish

Sự 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

Parameters

kênh truyền hình. một kênh để xuất bản lên
thông điệp. chuỗi

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
97

đặt mua

Sự 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

Parameters

kênh truyền hình. một loạt các kênh để đăng ký
gọi lại. một chuỗi hoặc một Mảng[$instance, 'method_name']. Hàm gọi lại nhận 3 tham số. phiên bản redis, tên kênh và thông báo. giá trị trả về. Trộn. Bất kỳ giá trị trả về khác null nào trong cuộc gọi lại sẽ được trả lại cho người gọi

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
98

quán rượu

Sự 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

Parameters

từ khóa. Chuỗi, có thể là. "channels", "numsub", or "numpat"
argument. Tùy chọn, biến thể. Đối với lệnh con "kênh", bạn có thể chuyển một mẫu chuỗi. Đối với "numsub" một mảng tên kênh

Return value

KÊ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
NUMSUB. Trả về một mảng khóa/giá trị trong đó các khóa là tên kênh và giá trị là số lượng của chúng
NUMPAT. Trả về số nguyên chứa số đăng ký mẫu đang hoạt động

Example

; Should the locking be enabled? Defaults to: 0.
redis.session.locking_enabled = 1
; How long should the lock live [in seconds]? Defaults to: value of max_execution_time.
redis.session.lock_expire = 60
; How long to wait between attempts to acquire lock, in microseconds [µs]?. Defaults to: 20000
redis.session.lock_wait_time = 50000
; Maximum number of times to retry [-1 means infinite]. Defaults to: 100
redis.session.lock_retries = 2000
99

Chung

  1. - Thực thi bất kỳ lệnh chung nào đối với máy chủ

rawCommand

Sự 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

Parameters

Phươ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 value

The 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

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
00

Transactions

  1. - Enter and exit transactional mode
  2. - Xem khóa để sửa đổi bởi khách hàng khác

multi, exec, discard

Description. 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

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
01

watch, unwatch

Sự 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
# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
23].
$redis = new Redis[];
48 cancels all the watching of all keys by this client

Parameters

keys. string for one key or array for a list of keys

Example

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
02

Scripting

  • - Evaluate a LUA script serverside
  • - Evaluate a LUA script serverside, from the SHA1 hash of the script instead of the script itself
  • - Execute the Redis SCRIPT command to perform various operations on the scripting subsystem
  • - The last error message [if any]
  • - Clear the last error message
  • - A utility method to prefix the value with the prefix setting for phpredis
  • - A utility method to unserialize data with whatever serializer is set up
  • - A utility method to serialize data with whatever serializer is set up

đánh giá

Description. Evaluate a LUA script serverside

Parameters

script string
args array, optional
num_keys int, optional

Return value

Mixed. 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ụ

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
03

evalSha

Sự 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

Parameters

chuỗi script_sha. The sha1 encoded hash of the script you want to run
mảng args, tùy chọn. Các đối số để chuyển đến tập lệnh LUA
num_keys int, tùy chọn. Số lượng đối số sẽ đi vào mảng KEYS, so với. mảng ARGV khi Redis quay tập lệnh

Return value

Trộn. Xem EVAL

ví dụ

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
04

script

Sự 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

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
05

Return value
  • SCRIPT LOAD sẽ trả về hàm băm SHA1 của tập lệnh đã truyền nếu thành công và FALSE nếu thất bại
  • SCRIPT FLUSH phải luôn trả về TRUE
  • SCRIPT KILL sẽ trả về true nếu script có thể bị kill và false nếu không
  • SCRIPT EXISTS sẽ trả về một mảng có TRUE hoặc FALSE cho mỗi tập lệnh được truyền

khách hàng

Description. 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

  • DANH SÁCH KHÁCH HÀNG
  • TÊN KHÁCH HÀNG
  • TÊN KHÁCH HÀNG [tên]
  • KHÁCH HÀNG GIẾT [ip. port]
Usage

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
06

Return 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

  • DANH SÁCH KHÁCH HÀNG sẽ trả về một mảng các mảng có thông tin khách hàng
  • CLIENT GETNAME sẽ trả về tên máy khách hoặc false nếu chưa đặt
  • CLIENT SETNAME will return true if it can be set and false if not
  • CLIENT KILL sẽ trả về true nếu client có thể bị giết và false nếu không

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 đó

getLastError

Description. Thông báo lỗi cuối cùng [nếu có]

Parameters

none

Return value

A string with the last returned script based error message, or NULL if there is no error

ví dụ

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
07

ClearLastError

Sự miêu tả. Xóa thông báo lỗi cuối cùng

Parameters

none

Return value

ĐÚNG SỰ THẬT

ví dụ

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
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

Parameters

chuỗi giá trị. Giá trị bạn muốn tiền tố

Return value

Nế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ụ

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
09

_serialize

Sự 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'

Parameters

value. Mixed. The value to be serialized

ví dụ

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
10

_unserialize

Description. 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

Parameters

chuỗi giá trị. The value to be unserialized

ví dụ

# Run tests for Redis class [note this is the default]
php tests/TestRedis.php --class Redis

# Run tests for RedisArray class
tests/mkring.sh start
php tests/TestRedis.php --class RedisArray
tests/mkring.sh stop

# Run tests for the RedisCluster class
tests/make-cluster.sh start
php tests/TestRedis.php --class RedisCluster
tests/make-cluster.sh stop

# Run tests for RedisSentinel class
php tests/TestRedis.php --class RedisSentinel
11

Introspection

đã kết nối

Description. 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

Parameters

None

Return value

Boolean Returns TRUE if phpredis thinks it's connected and FALSE if not

getHost

Description. 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

Parameters

None

Return value

Mixed The host or unix socket we're connected to or FALSE if we're not connected

getPort

Sự miêu tả. Get the port we're connected to

Parameters

None

Return value

Hỗ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

getDbNum

Sự miêu tả. Get the database number phpredis is pointed to

Parameters

None

Return value

Mixed Returns the database number [LONG] phpredis thinks it's pointing to or FALSE if we're not connected

getTimeout

Description. Nhận thời gian chờ [ghi] được sử dụng cho phpredis

Parameters

None

Return value

Hỗ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

getReadTimeout

Sự 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

Parameters

None

Return value

Mixed 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

getPersistentID

Sự miêu tả. Nhận ID liên tục mà phpredis đang sử dụng

Parameters

None

Return value

Kế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

getAuth

Description. 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

Parameters

None

Return value

Hỗ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

Chủ Đề