ledisdb/doc/commands.md

1540 lines
28 KiB
Markdown
Raw Normal View History

2014-06-25 10:22:48 +04:00
## Total
ledisdb use redis protocol called RESP(REdis Serialization Protocol), [here](http://redis.io/topics/protocol).
2014-06-25 13:43:47 +04:00
ledisdb all commands return RESP fomrat and it will use int64 instead of RESP integer, string instead of RESP simple string, bulk string instead of RESP bulk string, and array instead of RESP arrays below.
2014-06-25 10:22:48 +04:00
## KV
2014-07-01 13:29:37 +04:00
### DECR key
2014-06-25 10:22:48 +04:00
Decrements the number stored at key by one. If the key does not exist, it is set to 0 before decrementing.
An error returns if the value for the key is a wrong type that can not be represented as a signed 64 bit integer.
**Return value**
int64: the value of key after the decrement
**Examples**
```
2014-07-01 13:29:37 +04:00
ledis> DECR mykey
2014-06-25 10:22:48 +04:00
(integer) -1
2014-07-01 13:29:37 +04:00
ledis> DECR mykey
2014-06-25 10:22:48 +04:00
(integer) -2
ledis> SET mykey "234293482390480948029348230948"
OK
2014-07-01 13:29:37 +04:00
ledis> DECR mykey
2014-06-25 10:22:48 +04:00
ERR strconv.ParseInt: parsing "234293482390480948029348230948“: invalid syntax
```
2014-07-01 13:29:37 +04:00
### DECRBY key decrement
Decrements the number stored at key by decrement. like DECR.
2014-06-25 10:22:48 +04:00
**Return value**
int64: the value of key after the decrement
**Examples**
```
2014-07-01 13:29:37 +04:00
ledis> SET mykey “10“
2014-06-25 10:22:48 +04:00
OK
2014-07-01 13:29:37 +04:00
ledis> DECRBY mykey “5“
2014-06-25 10:22:48 +04:00
(integer) 5
```
2014-07-01 13:29:37 +04:00
### DEL key [key ...]
2014-06-25 10:22:48 +04:00
Removes the specified keys.
**Return value**
int64: The number of input keys
**Examples**
```
2014-07-01 13:29:37 +04:00
ledis> SET key1 "hello"
2014-06-25 10:22:48 +04:00
OK
2014-07-01 13:29:37 +04:00
ledis> SET key2 "world"
2014-06-25 10:22:48 +04:00
OK
2014-07-01 13:29:37 +04:00
ledis> DEL key1 key2
2014-06-25 10:22:48 +04:00
(integer) 2
```
2014-07-01 13:29:37 +04:00
### EXISTS key
2014-06-25 10:22:48 +04:00
Returns if key exists
**Return value**
int64, specifically:
2014-07-01 13:29:37 +04:00
2014-06-25 10:22:48 +04:00
- 1 if the key exists.
- 0 if the key does not exists.
**Examples**
```
2014-07-01 13:29:37 +04:00
ledis> SET key1 "hello"
2014-06-25 10:22:48 +04:00
OK
2014-07-01 13:29:37 +04:00
ledis> EXISTS key1
2014-06-25 10:22:48 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> EXISTS key2
2014-06-25 10:22:48 +04:00
(integer) 0
```
2014-07-01 13:29:37 +04:00
### GET key
2014-06-25 10:22:48 +04:00
Get the value of key. If the key does not exists, it returns nil value.
**Return value**
bulk: the value of key, or nil when key does not exist.
**Examples**
```
2014-07-01 13:29:37 +04:00
ledis> GET nonexisting
2014-06-25 13:43:47 +04:00
(nil)
2014-07-01 13:29:37 +04:00
ledis> SET mykey "hello"
2014-06-25 13:43:47 +04:00
OK
2014-07-01 13:29:37 +04:00
ledis> GET mykey
2014-06-25 13:43:47 +04:00
"hello"
2014-06-25 10:22:48 +04:00
```
2014-07-01 13:29:37 +04:00
### GETSET key value
2014-06-25 13:43:47 +04:00
Atomically sets key to value and returns the old value stored at key.
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-25 13:43:47 +04:00
bulk: the old value stored at key, or nil when key did not exists.
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-25 13:43:47 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> SET mykey "hello"
2014-06-25 13:43:47 +04:00
OK
2014-07-01 13:29:37 +04:00
ledis> GETSET mykey "world"
2014-06-25 13:43:47 +04:00
"hello"
2014-07-01 13:29:37 +04:00
ledis> GET mykey
2014-06-25 13:43:47 +04:00
"world"
```
2014-07-01 13:29:37 +04:00
### INCR key
2014-06-25 13:43:47 +04:00
2014-07-01 13:29:37 +04:00
Increments the number stored at key by one. If the key does not exists, it is SET to 0 before incrementing.
2014-06-25 13:43:47 +04:00
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-25 13:43:47 +04:00
int64: the value of key after the increment
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-25 13:43:47 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> SET mykey "10"
2014-06-25 13:43:47 +04:00
OK
2014-07-01 13:29:37 +04:00
ledis> INCR mykey
2014-06-25 13:43:47 +04:00
(integer) 11
2014-07-01 13:29:37 +04:00
ledis> GET mykey
2014-06-25 13:43:47 +04:00
"11"
```
2014-07-01 13:29:37 +04:00
### INCRBY key increment
2014-06-25 13:43:47 +04:00
2014-07-01 13:29:37 +04:00
Increments the number stored at key by increment. If the key does not exists, it is SET to 0 before incrementing.
2014-06-25 13:43:47 +04:00
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-25 13:43:47 +04:00
int64: the value of key after the increment
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-25 13:43:47 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> SET mykey "10"
2014-06-25 13:43:47 +04:00
OK
2014-07-01 13:29:37 +04:00
ledis> INCRBY mykey 5
2014-06-25 13:43:47 +04:00
(integer) 15
```
2014-07-01 13:29:37 +04:00
### MGET key [key ...]
2014-06-25 13:43:47 +04:00
Returns the values of all specified keys. If the key does not exists, a nil will return.
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-25 13:43:47 +04:00
array: list of values at the specified keys
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-25 13:43:47 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> SET key1 "hello"
2014-06-25 13:43:47 +04:00
OK
2014-07-01 13:29:37 +04:00
ledis> SET key2 "world"
2014-06-25 13:43:47 +04:00
OK
2014-07-01 13:29:37 +04:00
ledis> MGET key1 key2 nonexisting
2014-06-25 13:43:47 +04:00
1) "hello"
2) "world"
3) (nil)
```
2014-07-01 13:29:37 +04:00
### MSET key value [key value ...]
2014-06-25 13:43:47 +04:00
Sets the given keys to their respective values.
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-25 13:43:47 +04:00
string: always OK
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-25 13:43:47 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> MSET key1 "hello" key2 "world"
2014-06-25 13:43:47 +04:00
OK
2014-07-01 13:29:37 +04:00
ledis> GET key1
2014-06-25 13:43:47 +04:00
"hello"
2014-07-01 13:29:37 +04:00
ledis> GET key2
2014-06-25 13:43:47 +04:00
"world"
```
2014-07-01 13:29:37 +04:00
### SET key value
2014-06-25 13:43:47 +04:00
Set key to the value.
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-25 13:43:47 +04:00
string: OK
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-25 13:43:47 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> SET mykey "hello"
2014-06-25 13:43:47 +04:00
OK
2014-07-01 13:29:37 +04:00
ledis> GET mykey
2014-06-25 13:43:47 +04:00
"hello"
```
2014-07-01 13:29:37 +04:00
### SETNX key value
2014-06-25 13:43:47 +04:00
Set key to the value if key does not exist. If key already holds a value, no operation is performed.
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-25 13:43:47 +04:00
int64:
2014-07-01 13:29:37 +04:00
- 1 if the key was SET
- 0 if the key was not SET
2014-06-25 13:43:47 +04:00
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-25 13:43:47 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> SETNX mykey "hello"
2014-06-25 13:43:47 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> SETNX mykey "world"
2014-06-25 13:43:47 +04:00
(integer) 0
2014-07-01 13:29:37 +04:00
ledis> GET mykey
2014-06-25 13:43:47 +04:00
"hello"
```
2014-07-01 13:29:37 +04:00
### EXPIRE key seconds
2014-06-25 13:43:47 +04:00
Set a timeout on key. After the timeout has expired, the key will be deleted.
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-25 13:43:47 +04:00
int64:
- 1 if the timeout was set
- 0 if key does not exist or the timeout could not be set
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-25 13:43:47 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> SET mykey "hello"
2014-06-25 13:43:47 +04:00
OK
2014-07-01 13:29:37 +04:00
ledis> EXPIRE mykey 60
2014-06-25 13:43:47 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> EXPIRE mykey 60
2014-06-25 13:43:47 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> TTL mykey
2014-06-25 13:43:47 +04:00
(integer) 58
2014-07-01 13:29:37 +04:00
ledis> PERSIST mykey
2014-06-25 13:43:47 +04:00
(integer) 1
```
2014-07-01 13:29:37 +04:00
### EXPIREAT key timestamp
2014-06-25 13:43:47 +04:00
Set an expired unix timestamp on key.
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-25 13:43:47 +04:00
int64:
- 1 if the timeout was set
- 0 if key does not exist or the timeout could not be set
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-25 13:43:47 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> SET mykey "Hello"
2014-06-25 13:43:47 +04:00
OK
2014-07-01 13:29:37 +04:00
ledis> EXPIREAT mykey 1293840000
2014-06-25 13:43:47 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> EXISTS mykey
2014-06-25 13:43:47 +04:00
(integer) 0
```
2014-07-01 13:29:37 +04:00
### TTL key
2014-06-25 13:43:47 +04:00
Returns the remaining time to live of a key that has a timeout. If the key was not set a timeout, -1 returns.
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-25 13:43:47 +04:00
int64: TTL in seconds
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-25 13:43:47 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> SET mykey "hello"
2014-06-25 13:43:47 +04:00
OK
2014-07-01 13:29:37 +04:00
ledis> EXPIRE mykey 10
2014-06-25 13:43:47 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> TTL mykey
2014-06-25 13:43:47 +04:00
(integer) 8
```
2014-07-01 13:29:37 +04:00
### PERSIST key
2014-06-25 13:43:47 +04:00
Remove the existing timeout on key
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-25 13:43:47 +04:00
int64:
- 1 if the timeout was removed
- 0 if key does not exist or does not have an timeout
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-25 13:43:47 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> SET mykey "hello"
2014-06-25 13:43:47 +04:00
OK
2014-07-01 13:29:37 +04:00
ledis> EXPIRE mykey 60
2014-06-25 13:43:47 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> TTL mykey
2014-06-25 13:43:47 +04:00
(integer) 57
2014-07-01 13:29:37 +04:00
ledis> PERSIST mykey
2014-06-25 13:43:47 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> TTL mykey
2014-06-25 13:43:47 +04:00
(integer) -1
```
2014-07-01 13:29:37 +04:00
2014-06-25 10:22:48 +04:00
## Hash
2014-07-01 13:29:37 +04:00
### HDEL key field [field ...]
2014-06-26 12:26:09 +04:00
Removes the specified fiedls from the hash stored at key.
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-26 12:26:09 +04:00
int64: the number of fields that were removed from the hash.
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-26 12:26:09 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> HSET myhash field1 "foo"
2014-06-26 12:26:09 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> HDEL myhash field1 field2
2014-06-26 12:26:09 +04:00
(integer) 1
```
2014-07-01 13:29:37 +04:00
### HEXISTS key field
2014-06-26 12:26:09 +04:00
Returns if field is an existing field in the hash stored at key.
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-26 12:26:09 +04:00
int64:
- 1 if the hash contains field
- 0 if the hash does not contain field, or key does not exist.
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-26 12:26:09 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> HSET myhash field1 "foo"
2014-06-26 12:26:09 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> HEXISTS myhash field1
2014-06-26 12:26:09 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> HEXISTS myhash field2
2014-06-26 12:26:09 +04:00
(integer) 0
```
2014-07-01 13:29:37 +04:00
### HGET key field
2014-06-26 12:26:09 +04:00
Returns the value associated with field in the hash stored at key.
**Return value**
bulk: the value associated with field, or nil.
**Examples**
```
2014-07-01 13:29:37 +04:00
ledis> HSET myhash field1 "foo"
2014-06-26 12:26:09 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> HGET myhash field1
2014-06-26 12:26:09 +04:00
"foo"
2014-07-01 13:29:37 +04:00
ledis> HGET myhash field2
2014-06-26 12:26:09 +04:00
(nil)
```
2014-07-01 13:29:37 +04:00
### HGETALL key
2014-06-26 12:26:09 +04:00
Returns all fields and values of the hash stored at key.
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-26 12:26:09 +04:00
array: list of fields and their values stored in the hash, or an empty list (using nil in ledis-cli)
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-26 12:26:09 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> HSET myhash field1 "hello"
2014-06-26 12:26:09 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> HSET myhash field2 "world"
2014-06-26 12:26:09 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> HGETALL myhash
2014-06-26 12:26:09 +04:00
1) "field1"
2) "hello"
3) "field2"
4) "world"
```
2014-07-01 13:29:37 +04:00
### HINCRBY key field increment
2014-06-26 12:26:09 +04:00
Increments the number stored at field in the hash stored at key by increment. If key does not exist, a new hash key is created.
If field does not exists the value is set to 0 before incrementing.
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-26 12:26:09 +04:00
int64: the value at field after the increment.
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-26 12:26:09 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> HINCRBY myhash field 1
2014-06-26 12:26:09 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> HGET myhash field
2014-06-26 12:26:09 +04:00
"1"
2014-07-01 13:29:37 +04:00
ledis> HINCRBY myhash field 5
2014-06-26 12:26:09 +04:00
(integer) 6
2014-07-01 13:29:37 +04:00
ledis> HINCRBY myhash field -10
2014-06-26 12:26:09 +04:00
(integer) -4
```
2014-07-01 13:29:37 +04:00
### HKEYS key
2014-06-26 12:26:09 +04:00
Return all fields in the hash stored at key.
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-26 12:26:09 +04:00
array: list of fields in the hash, or an empty list.
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-26 12:26:09 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> HSET myhash field1 "hello"
2014-06-26 12:26:09 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> HSET myhash field2 "world"
2014-06-26 12:26:09 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> HKEYS myhash
2014-06-26 12:26:09 +04:00
1) "field1"
2) "field2"
```
2014-07-01 13:29:37 +04:00
### HLEN key
2014-06-26 12:26:09 +04:00
Returns the number of fields contained in the hash stored at key
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-26 12:26:09 +04:00
int64: number of fields in the hash, or 0 when key does not exist.
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-26 12:26:09 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> HSET myhash field1 "hello"
2014-06-26 12:26:09 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> HSET myhash field2 "world"
2014-06-26 12:26:09 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> HLEN myhash
2014-06-26 12:26:09 +04:00
(integer) 2
```
2014-07-01 13:29:37 +04:00
### HMGET key field [field ...]
2014-06-26 12:26:09 +04:00
Returns the values associated with the specified fields in the hash stored at key. If field does not exist in the hash, a nil value is returned.
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-26 12:26:09 +04:00
array: list of values associated with the given fields.
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-26 12:26:09 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> HSET myhash field1 "hello"
2014-06-26 12:26:09 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> HSET myhash field2 "world"
2014-06-26 12:26:09 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> HMGET myhash field1 field2 nofield
2014-06-26 12:26:09 +04:00
1) "hello"
2) "world"
3) (nil)
```
2014-07-01 13:29:37 +04:00
### HMSET key field value [field value ...]
2014-06-26 12:26:09 +04:00
Sets the specified fields to their respective values in the hash stored at key.
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-26 12:26:09 +04:00
string: OK
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-26 12:26:09 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> HMSET myhash field1 "hello" field2 "world"
2014-06-26 12:26:09 +04:00
OK
2014-07-01 13:29:37 +04:00
ledis> HMGET myhash field1 field2
2014-06-26 12:26:09 +04:00
1) "hello"
2) "world"
```
2014-07-01 13:29:37 +04:00
### HSET key field value
2014-06-26 12:26:09 +04:00
Sets field in the hash stored at key to value. If key does not exists, a new hash key is created.
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-26 12:26:09 +04:00
int64:
- 1 if field is a new field in the hash and value was set.
- 0 if field already exists in the hash and the value was updated.
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-26 12:26:09 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> HSET myhash field1 "hello"
2014-06-26 12:26:09 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> HGET myhash field1
2014-06-26 12:26:09 +04:00
"hello"
2014-07-01 13:29:37 +04:00
ledis> HSET myhash field1 "world"
2014-06-26 12:26:09 +04:00
(integer) 0
2014-07-01 13:29:37 +04:00
ledis> HGET myhash field1
2014-06-26 12:26:09 +04:00
"world"
```
2014-07-01 13:29:37 +04:00
### HVALS key
2014-06-26 12:26:09 +04:00
Returns all values in the hash stored at key.
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-26 12:26:09 +04:00
array: list of values in the hash, or an empty list.
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-26 12:26:09 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> HSET myhash field1 "hello"
2014-06-26 12:26:09 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> HSET myhash field2 "world"
2014-06-26 12:26:09 +04:00
(integer) 1
2014-07-01 13:29:37 +04:00
ledis> HVALS myhash
2014-06-26 12:26:09 +04:00
1) "hello"
2) "world"
```
2014-07-01 13:29:37 +04:00
### HCLEAR key
2014-06-26 12:26:09 +04:00
Deletes the specified hash keys
2014-06-26 12:26:09 +04:00
2014-06-25 10:22:48 +04:00
**Return value**
int64: the number of fields in the hash stored at key
2014-06-26 12:26:09 +04:00
2014-06-25 10:22:48 +04:00
**Examples**
2014-06-26 12:26:09 +04:00
```
2014-07-01 13:29:37 +04:00
ledis> HMSET myhash field1 "hello" field2 "world"
2014-06-26 12:26:09 +04:00
OK
2014-07-01 13:29:37 +04:00
ledis> HCLEAR myhash
2014-06-26 12:26:09 +04:00
(integer) 2
```
2014-07-01 13:29:37 +04:00
### HMCLEAR key [key...]
Deletes the specified hash keys
**Return value**
int64: the number of input keys
**Examples**
```
2014-07-01 13:29:37 +04:00
ledis> HMSET myhash field1 "hello" field2 "world"
OK
2014-07-01 13:29:37 +04:00
ledis> HMCLEAR myhash
(integer) 1
```
2014-07-01 13:29:37 +04:00
### HEXPIRE key seconds
2014-06-26 12:26:09 +04:00
Sets a hash key's time to live in seconds, like expire similarly.
2014-07-01 13:29:37 +04:00
**Return value**
int64:
- 1 if the timeout was set
- 0 if key does not exist or the timeout could not be set
**Examples**
```
27.0.0.1:6666> HSET myhash a 100
(integer) 1
127.0.0.1:6666> HGET myhash a
100
127.0.0.1:6666> HEXPIRE myhash 100
(integer) 1
127.0.0.1:6666> HTTL myhash
(integer) 94
127.0.0.1:6666> HPERSIST myhash
(integer) 1
127.0.0.1:6666> HTTL myhash
(integer) -1
127.0.0.1:6666> HEXPIRE not_exists_key 100
(integer) 0
```
### HEXPIREAT key timestamp
2014-06-26 12:26:09 +04:00
Sets the expiration for a hash key as a unix timestamp, like expireat similarly.
2014-07-01 13:29:37 +04:00
**Return value**
2014-06-26 12:26:09 +04:00
2014-07-01 13:29:37 +04:00
int64:
2014-06-26 12:26:09 +04:00
2014-07-01 13:29:37 +04:00
- 1 if the timeout was set
- 0 if key does not exist or the timeout could not be set
**Examples**
```
127.0.0.1:6666> HSET myhash a 100
(integer) 1
127.0.0.1:6666> HEXPIREAT myhash 1404999999
(integer) 1
127.0.0.1:6666> HTTL myhash
(integer) 802475
127.0.0.1:6666> HEXPIREAT not_exists_key 1404999999
(integer) 0
```
### HTTL key
Returns the remaining time to live of a key that has a timeout. If the key was not set a timeout, -1 returns.
**Return value**
int64: TTL in seconds
**Examples**
```
127.0.0.1:6666> HSET myhash a 100
(integer) 1
127.0.0.1:6666> HEXPIREAT myhash 1404999999
(integer) 1
127.0.0.1:6666> HTTL myhash
(integer) 802475
127.0.0.1:6666> HTTL not_set_timeout
(integer) -1
```
### HPERSIST key
2014-06-26 12:26:09 +04:00
Remove the expiration from a hash key, like persist similarly.
2014-07-01 13:29:37 +04:00
Remove the existing timeout on key
**Return value**
int64:
- 1 if the timeout was removed
- 0 if key does not exist or does not have an timeout
```
127.0.0.1:6666> HSET myhash a 100
(integer) 1
127.0.0.1:6666> HEXPIREAT myhash 1404999999
(integer) 1
127.0.0.1:6666> HTTL myhash
(integer) 802475
127.0.0.1:6666> HPERSIST myhash
(integer) 1
127.0.0.1:6666> HTTL myhash
(integer) -1
127.0.0.1:6666> HPERSIST not_exists_key
(integer) 0
```
2014-06-26 12:26:09 +04:00
2014-06-25 10:22:48 +04:00
## List
2014-07-01 13:29:37 +04:00
### LINDEX key index
Returns the element at index index in the list stored at key. The index is zero-based, so 0 means the first element, 1 the second element and so on. Negative indices can be used to designate elements starting at the tail of the list. Here, -1 means the last element, -2 means the penultimate and so forth.
When the value at key is not a list, an error is returned.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
string: the requested element, or nil when index is out of range.
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > RPUSH a 1 2 3
(integer) 3
ledis > LINDEX a 0
1
ledis > LINDEX a 1
2
ledis > LINDEX a 2
3
ledis > LINDEX a 3
(nil)
ledis > LINDEX a -1
3
```
### LLEN key
Returns the length of the list stored at key. If key does not exist, it is interpreted as an empty list and 0 is returned. An error is returned when the value stored at key is not a list.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
int64: the length of the list at key.
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > RPUSH a 'foo'
(integer) 1
ledis > RPUSH a 'bar'
(integer) 2
ledis > LLEN a
(integer) 2
```
### LPOP key
Removes and returns the first element of the list stored at key.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
bulk: the value of the first element, or nil when key does not exist.
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > RPUSH a 'one'
(integer) 1
ledis > RPUSH a 'two'
(integer) 2
ledis > RPUSH a 'three'
(integer) 3
ledis > LPOP a
one
```
### LRANGE key start stop
Returns the specified elements of the list stored at key. The offsets start and stop are zero-based indexes, with 0 being the first element of the list (the head of the list), 1 being the next element and so on.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
array: list of elements in the specified range.
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > RPUSH a 'one' 'two' 'three'
(integer) 3
ledis > LRANGE a 0 0
1) "one"
ledis > LRANGE a -100 100
1) "one"
2) "two"
3) "three"
ledis > LRANGE a -3 2
1) "one"
2) "two"
3) "three"
ledis > LRANGE a 0 -1
(empty list or set)
```
### LPUSH key value [value ...]
Insert all the specified values at the head of the list stored at key. If key does not exist, it is created as empty list before performing the push operations. When key holds a value that is not a list, an error is returned.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
int64: the length of the list after the push operations.
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > LPUSH a 1
(integer) 1
ledis > LPUSH a 2
(integer) 2
ledis > LRANGE a 0 2
1) "2"
2) "1"
```
### RPOP key
Removes and returns the last element of the list stored at key.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
bulk: the value of the last element, or nil when key does not exist.
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
edis > RPUSH a 1
(integer) 1
ledis > RPUSH a 2
(integer) 2
ledis > RPUSH a 3
(integer) 3
ledis > RPOP a
3
ledis > LRANGE a 0 3
1) "1"
2) "2"
```
### RPUSH key value [value ...]
Insert all the specified values at the tail of the list stored at key. If key does not exist, it is created as empty list before performing the push operation. When key holds a value that is not a list, an error is returned.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
int64: the length of the list after the push operation.
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > RPUSH a 'hello'
(integer) 1
ledis > RPUSH a 'world'
(integer) 2
ledis > LRANGE a 0 2
1) "hello"
2) "world"
```
### LCLEAR key
Deletes the specified list key
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
int64: the number of values in the list stored at key
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > RPUSH a 1 2 3
(integer) 3
ledis > LLEN a
(integer) 3
ledis > LCLEAR a
(integer) 3
ledis > LLEN a
(integer) 0
```
### LEXPIRE key seconds
Set a timeout on key. After the timeout has expired, the key will be deleted.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
int64:
- 1 if the timeout was set
- 0 if key does not exist or the timeout could not be set
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > RPUSH a 1
(integer) 1
ledis > LEXPIRE a 100
(integer) 1
ledis > LTTL a
(integer) 96
ledis > LPERSIST a
(integer) 1
ledis > LTTL a
(integer) -1
```
### LEXPIREAT key timestamp
Set an expired unix timestamp on key.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
int64:
- 1 if the timeout was set
- 0 if key does not exist or the timeout could not be set
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > RPUSH a 1
(integer) 1
ledis > LEXPIREAT a 1404140183
(integer) 1
ledis > LTTL a
(integer) 570
ledis > LPERSIST a
(integer) 1
ledis > LTTL a
(integer) -1
ledis >
```
### LTTL key
Returns the remaining time to live of a key that has a timeout. If the key was not set a timeout, -1 returns.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
int64: TTL in seconds
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > RPUSH a 1
(integer) 1
ledis > LEXPIREAT a 1404140183
(integer) 1
ledis > LTTL a
(integer) 570
ledis > LPERSIST a
(integer) 1
ledis > LTTL a
(integer) -1
```
### LPERSIST key
Remove the existing timeout on key
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
int64:
- 1 if the timeout was removed
- 0 if key does not exist or does not have an timeout
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > RPUSH a 1
(integer) 1
ledis > LEXPIREAT a 1404140183
(integer) 1
ledis > LTTL a
(integer) 570
ledis > LPERSIST a
(integer) 1
ledis > LTTL a
(integer) -1
ledis > LPERSIST b
(integer) 0
```
2014-06-25 10:22:48 +04:00
## ZSet
2014-07-01 13:29:37 +04:00
### ZADD key score member [score member ...]
Adds all the specified members with the specified scores to the sorted set stored at key. It is possible to specify multiple score / member pairs. If a specified member is already a member of the sorted set, the score is updated and the element reinserted at the right position to ensure the correct ordering.
If key does not exist, a new sorted set with the specified members as sole members is created, like if the sorted set was empty. If the key exists but does not hold a sorted set, an error is returned.
The score values should be the string representation of a double precision floating point number. +inf and -inf values are valid values as well.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
int64, specifically:
The number of elements added to the sorted sets, ** not ** including elements already existing for which the score was updated.
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > ZADD myset 1 'one'
(integer) 1
ledis > ZADD myset 1 'uno'
(integer) 1
ledis > ZADD myset 2 'two' 3 'three'
(integer) 2
ledis > ZRANGE myset 0 -1 WITHSCORES
1) "one"
2) "1"
3) "uno"
4) "1"
5) "two"
6) "2"
7) "three"
8) "3"
```
### ZCARD key
Returns the sorted set cardinality (number of elements) of the sorted set stored at key.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
int64: the cardinality (number of elements) of the sorted set, or 0 if key does not exist.
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
edis > ZADD myset 1 'one'
(integer) 1
ledis > ZADD myset 1 'uno'
(integer) 1
ledis > ZADD myset 2 'two' 3 'three'
(integer) 2
ledis > ZRANGE myset 0 -1 WITHSCORES
1) "one"
2) "1"
3) "uno"
4) "1"
5) "two"
6) "2"
7) "three"
8) "3"
ledis > zcard myset
(integer) 4
```
### ZCOUNT key min max
Returns the number of elements in the sorted set at key with a score between min and max.
The min and max arguments have the same semantic as described for ZRANGEBYSCORE.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
int64: the number of elements in the specified score range.
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > ZADD myset 1 'one'
(integer) 1
ledis > ZADD myset 1 'uno'
(integer) 1
ledis > ZADD myset 2 'two' 3 'three'
(integer) 2
ledis > ZRANGE myset 0 -1 WITHSCORES
1) "one"
2) "1"
3) "uno"
4) "1"
5) "two"
6) "2"
7) "three"
8) "3"
ledis > zcount myset -inf +inf
(integer) 4
ledis > zcount myset (1 3
(integer) 2
```
### ZINCRBY key increment member
Increments the score of member in the sorted set stored at key by increment. If member does not exist in the sorted set, it is added with increment as its score (as if its previous score was 0.0). If key does not exist, a new sorted set with the specified member as its sole member is created.
An error is returned when key exists but does not hold a sorted set.
The score value should be the string representation of a numeric value, and accepts double precision floating point numbers. It is possible to provide a negative value to decrement the score.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
bulk: the new score of member (a double precision floating point number), represented as string.
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > ZADD myset 1 'one'
(integer) 1
ledis > ZADD myset 2 'two'
(integer) 1
ledis > ZINCRBY myset 2 'one'
3
ledis > ZRANGE myset 0 -1 WITHSCORES
1) "two"
2) "2"
3) "one"
4) "3"
```
### ZRANGE key start stop [WITHSCORES]
Returns the specified range of elements in the sorted set stored at key. The elements are considered to be ordered from the lowest to the highest score. Lexicographical order is used for elements with equal score.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
array: list of elements in the specified range (optionally with their scores).
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > ZADD myset 1 'one'
(integer) 1
ledis > ZADD myset 2 'two'
(integer) 1
ledis > ZADD myset 3 'three'
(integer) 1
ledis > ZRANGE myset 0 -1
1) "one"
2) "two"
3) "three"
ledis > ZRANGE myset 2 3
1) "three"
ledis > ZRANGE myset -2 -1
1) "two"
2) "three"
```
### ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]
Returns all the elements in the sorted set at key with a score between min and max (including elements with score equal to min or max). The elements are considered to be ordered from low to high scores.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
array: list of elements in the specified score range (optionally with their scores).
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
127.0.0.1:6666> ZADD myzset 1 'one'
(integer) 1
127.0.0.1:6666> ZADD myzset 2 'two'
(integer) 1
127.0.0.1:6666> ZADD myzset 3 'three'
(integer) 1
127.0.0.1:6666> ZRANGEBYSCORE myzset -inf +inf WITHSCORES
1) "one"
2) "1"
3) "two"
4) "2"
5) "three"
6) "3"
127.0.0.1:6666> ZRANGEBYSCORE myzset -inf +inf WITHSCORES LIMIT 2 5
1) "three"
2) "3"
127.0.0.1:6666> ZRANGEBYSCORE myzset (1 2 WITHSCORES
1) "two"
2) "2"
127.0.0.1:6666> ZRANGEBYSCORE myzset (1 (2 WITHSCORES
```
### ZRANK key member
Returns the rank of member in the sorted set stored at key, with the scores ordered from low to high. The rank (or index) is 0-based, which means that the member with the lowest score has rank 0.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
Return value
- If member exists in the sorted set, Integer reply: the rank of member.
- If member does not exist in the sorted set or key does not exist, Bulk string reply: nil.
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
127.0.0.1:6666> ZADD myzset 1 'one'
(integer) 1
127.0.0.1:6666> ZADD myzset 2 'two'
(integer) 1
127.0.0.1:6666> ZADD myzset 3 'three'
(integer) 1
127.0.0.1:6666> ZRANGEBYSCORE myzset -inf +inf WITHSCORES
1) "one"
2) "1"
3) "two"
4) "2"
5) "three"
6) "3"
127.0.0.1:6666> ZRANK myzset 'three'
(integer) 2
```
### ZREM key member [member ...]
Removes the specified members from the sorted set stored at key. Non existing members are ignored.
An error is returned when key exists and does not hold a sorted set.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
int64 reply, specifically:
The number of members removed from the sorted set, not including non existing members.
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
127.0.0.1:6666> ZADD myset 1 one 2 two 3 three 4 four
(integer) 3
127.0.0.1:6666> ZRANGE myset 0 -1
1) "one"
2) "two"
3) "three"
4) "four"
127.0.0.1:6666> ZREM myset three
(integer) 1
127.0.0.1:6666> ZREM myset one four three
(integer) 2
```
### ZREMRANGEBYRANK key start stop
Removes all elements in the sorted set stored at key with rank between start and stop. Both start and stop are 0 -based indexes with 0 being the element with the lowest score. These indexes can be negative numbers, where they indicate offsets starting at the element with the highest score. For example: -1 is the element with the highest score, -2 the element with the second highest score and so forth.
**Return value**
int64: the number of elements removed.
**Examples**
```
127.0.0.1:6666> ZADD myset 1 one 2 two 3 three 4 four
(integer) 3
127.0.0.1:6666> ZREMRANGEBYRANK myset 0 2
(integer) 3
127.0.0.1:6666> ZRANGE myset 0 -1 WITHSCORES
1) "four"
2) "4"
```
### ZREMRANGEBYSCORE key min max
Removes all elements in the sorted set stored at key with a score between min and max (inclusive).
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
int64: the number of elements removed.
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
127.0.0.1:6666> ZADD myset 1 one 2 two 3 three 4 four
(integer) 4
127.0.0.1:6666> ZREMRANGEBYSCORE myset -inf (2
(integer) 1
127.0.0.1:6666> ZRANGE myset 0 -1 WITHSCORES
1) "two"
2) "2"
3) "three"
4) "3"
5) "four"
6) "4"
```
### ZREVRANGE key start stop [WITHSCORES]
Returns the specified range of elements in the sorted set stored at key. The elements are considered to be ordered from the highest to the lowest score. Descending lexicographical order is used for elements with equal score.
Apart from the reversed ordering, ZREVRANGE is similar to ZRANGE.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
array: list of elements in the specified range (optionally with their scores).
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
127.0.0.1:6666> ZADD myset 1 one 2 two 3 three 4 four
(integer) 4
127.0.0.1:6666> ZREVRANGE myset 0 -1
1) "four"
2) "three"
3) "two"
4) "one"
```
### ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]
Returns all the elements in the sorted set at key with a score between max and min (including elements with score equal to max or min). In contrary to the default ordering of sorted sets, for this command the elements are considered to be ordered from high to low scores.
The elements having the same score are returned in reverse lexicographical order.
Apart from the reversed ordering, ZREVRANGEBYSCORE is similar to ZRANGEBYSCORE.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
array: list of elements in the specified score range (optionally with their scores).
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
127.0.0.1:6666> ZADD myset 1 one 2 two 3 three 4 four
(integer) 4
127.0.0.1:6666> ZREVRANGEBYSCORE myset +inf -inf
1) "four"
2) "three"
3) "two"
4) "one"
127.0.0.1:6666> ZREVRANGEBYSCORE myset 2 1
1) "two"
2) "one"
127.0.0.1:6666> ZREVRANGEBYSCORE myset 2 (1
1) "two"
127.0.0.1:6666> ZREVRANGEBYSCORE myset (2 (1
(empty list or set)
127.0.0.1:6666> ZREVRANGEBYSCORE myset +inf -inf WITHSCORES LIMIT 1 2
1) "three"
2) "3"
3) "two"
4) "2"
```
### ZSCORE key member
Returns the score of member in the sorted set at key.
If member does not exist in the sorted set, or key does not exist, nil is returned.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
bulk: the score of member (a double precision floating point number), represented as string.
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > ZADD myset 1 'one'
(integer) 1
ledis > ZSCORE myset 'one'
1
```
### ZCLEAR key
Delete the specified key
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
int64: the number of members in the zset stored at key
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > ZADD myset 1 'one'
(integer) 1
ledis > ZADD myset 2 'two'
(integer) 1
ledis > ZADD myset 3 'three'
(integer) 1
ledis > ZRANGE myset 0 -1
1) "one"
2) "two"
3) "three"
ledis > ZCLEAR myset
(integer) 3
```
### ZMCLEAR key [key ...]
Delte multiple keys one time.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
int64: the number of input keys
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > ZADD myset1 1 'one'
(integer) 1
ledis > ZADD myset2 2 'two'
(integer) 1
ledis > ZMCLEAR myset1 myset2
(integer) 2
```
### ZEXPIRE key seconds
Set a timeout on key. After the timeout has expired, the key will be deleted.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
int64:
- 1 if the timeout was set
- 0 if key does not exist or the timeout could not be set
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > ZADD myset 1 'one'
(integer) 1
ledis > ZEXPIRE myset 100
(integer) 1
ledis > ZTTL myset
(integer) 97
ledis > ZPERSIST myset
(integer) 1
ledis > ZTTL mset
(integer) -1
ledis > ZEXPIRE myset1 100
(integer) 0
```
### ZEXPIREAT key timestamp
Set an expired unix timestamp on key. Similar to ZEXPIRE.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
int64:
- 1 if the timeout was set
- 0 if key does not exist or the timeout could not be set
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > ZADD myset 1 'one'
(integer) 1
ledis > ZEXPIREAT myset 1404149999
(integer) 1
ledis > ZTTL myset
(integer) 7155
ledis > ZPERSIST myset
(integer) 1
ledis > ZTTL mset
(integer) -1
ledis > ZEXPIREAT myset1 1404149999
(integer) 0
```
### ZTTL key
Returns the remaining time to live of a key that has a timeout. If the key was not set a timeout, -1 returns.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
int64: TTL in seconds
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > zadd myset 1 'one'
(integer) 1
ledis > zexpire myset 100
(integer) 1
ledis > zttl myset
(integer) 97
ledis > zttl myset2
(integer) -1
```
### ZPERSIST key
Remove the existing timeout on key.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
int64:
- 1 if the timeout was removed
- 0 if key does not exist or does not have an timeout
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > ZADD myset 1 'one'
(integer) 1
ledis > ZEXPIRE myset 100
(integer) 1
ledis > ZTTL myset
(integer) 97
ledis > ZPERSIST myset
(integer) 1
ledis > ZTTL mset
(integer) -1
```
2014-06-25 10:22:48 +04:00
## Replication
2014-07-01 13:29:37 +04:00
### SLAVEOF
2014-06-25 10:22:48 +04:00
**Return value**
**Examples**
2014-07-01 13:29:37 +04:00
### FULLSYNC
2014-06-25 10:22:48 +04:00
**Return value**
**Examples**
2014-07-01 13:29:37 +04:00
### SYNC
2014-06-25 10:22:48 +04:00
**Return value**
**Examples**
2014-07-01 13:29:37 +04:00
2014-06-25 10:22:48 +04:00
## Server
2014-07-01 13:29:37 +04:00
### PING
Returns PONG. This command is often used to test if a connection is still alive, or to measure latency.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
String
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > PING
PONG
ledis > PING
dial tcp 127.0.0.1:6665: connection refused
ledis >
```
### ECHO message
Returns message.
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
bulk string reply
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > ECHO "hello"
hello
```
### SELECT index
Select the DB with having the specified zero-based numeric index. New connections always use DB 0. Currently, We support 16 DBs(0-15).
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
Simple string reply
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
ledis > SELECT 2
OK
ledis > SELECT 15
OK
ledis > SELECT 16
ERR invalid db index 16
```