2014-07-03 05:19:36 +04:00
## Summary
2014-06-25 10:22:48 +04:00
ledisdb use redis protocol called RESP(REdis Serialization Protocol), [here ](http://redis.io/topics/protocol ).
2014-08-25 10:18:23 +04:00
ledisdb all commands return RESP format 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
2014-07-03 05:19:36 +04:00
Table of Contents
=================
- [Summary ](#summary )
- [KV ](#kv )
- [DECR key ](#decr-key )
- [DECRBY key decrement ](#decrby-key-decrement )
- [DEL key [key ...]](#del-key-key-)
- [EXISTS key ](#exists-key )
- [GET key ](#get-key )
- [GETSET key value ](#getset-key-value )
- [INCR key ](#incr-key )
- [INCRBY key increment ](#incrby-key-increment )
- [MGET key [key ...]](#mget-key-key-)
- [MSET key value [key value ...]](#mset-key-value-key-value-)
- [SET key value ](#set-key-value )
- [SETNX key value ](#setnx-key-value )
2014-10-26 10:15:43 +03:00
- [SETEX key seconds value ](#setex-key-seconds-value )
2014-07-03 05:19:36 +04:00
- [EXPIRE key seconds ](#expire-key-seconds )
- [EXPIREAT key timestamp ](#expireat-key-timestamp )
- [TTL key ](#ttl-key )
- [PERSIST key ](#persist-key )
2014-11-27 09:03:44 +03:00
- [DUMP key ](#dump-key )
2014-07-03 05:19:36 +04:00
- [Hash ](#hash )
- [HDEL key field [field ...]](#hdel-key-field-field-)
- [HEXISTS key field ](#hexists-key-field )
- [HGET key field ](#hget-key-field )
- [HGETALL key ](#hgetall-key )
- [HINCRBY key field increment ](#hincrby-key-field-increment )
- [HKEYS key ](#hkeys-key )
- [HLEN key ](#hlen-key )
- [HMGET key field [field ...]](#hmget-key-field-field-)
- [HMSET key field value [field value ...]](#hmset-key-field-value-field-value-)
- [HSET key field value ](#hset-key-field-value )
- [HVALS key ](#hvals-key )
- [HCLEAR key ](#hclear-key )
2014-10-17 07:41:15 +04:00
- [HMCLEAR key [key ...]](#hmclear-key-key)
2014-07-03 05:19:36 +04:00
- [HEXPIRE key seconds ](#hexpire-key-seconds )
- [HEXPIREAT key timestamp ](#hexpireat-key-timestamp )
- [HTTL key ](#httl-key )
- [HPERSIST key ](#hpersist-key )
2014-11-27 09:03:44 +03:00
- [HDUMP key ](#hdump-key )
2014-07-03 05:19:36 +04:00
- [List ](#list )
2014-10-17 07:41:15 +04:00
- [BLPOP key [key ...] timeout](#blpop-key-key--timeout)
- [BRPOP key [key ...] timeout](#brpop-key-key--timeout)
2014-07-03 05:19:36 +04:00
- [LINDEX key index ](#lindex-key-index )
- [LLEN key ](#llen-key )
- [LPOP key ](#lpop-key )
- [LRANGE key start stop ](#lrange-key-start-stop )
- [LPUSH key value [value ...]](#lpush-key-value-value-)
- [RPOP key ](#rpop-keuser-content-y )
- [RPUSH key value [value ...]](#rpush-key-value-value-)
- [LCLEAR key ](#lclear-key )
2014-07-08 18:05:50 +04:00
- [LMCLEAR key [key...]](#lmclear-key-key-)
2014-07-03 05:19:36 +04:00
- [LEXPIRE key seconds ](#lexpire-key-seconds )
- [LEXPIREAT key timestamp ](#lexpireat-key-timestamp )
- [LTTL key ](#lttl-key )
- [LPERSIST key ](#lpersist-key )
2014-11-27 09:03:44 +03:00
- [LDUMP key ](#ldump-key )
2014-08-15 13:30:15 +04:00
- [Set ](#set )
- [SADD key member [member ...]](#sadd-key-member-member-)
- [SCARD key ](#scard-key )
- [SDIFF key [key ...]](#sdiff-key-key-)
- [SDIFFSTORE destination key [key ...]](#sdiffstore-destination-key-key-)
- [SINTER key [key ...]](#sinter-key-key-)
- [SINTERSTORE destination key [key ...]](#sinterstore-destination-key-key-)
- [SISMEMBER key member ](#sismember-key-member )
- [SMEMBERS key ](#smembers-key )
2014-09-02 18:36:50 +04:00
- [SREM key member [member ...]](#srem-key-member-member-)
2014-08-15 13:30:15 +04:00
- [SUNION key [key ...]](#sunion-key-key-)
- [SUNIONSTORE destination key [key ...]](#sunionstore-destination-key-key-)
- [SCLEAR key ](#sclear-key )
- [SMCLEAR key [key...]](#smclear-key-key)
- [SEXPIRE key seconds ](#sexpire-key-seconds )
- [SEXPIREAT key timestamp ](#sexpireat-key-timestamp )
- [STTL key ](#sttl-key )
- [SPERSIST key ](#spersist-key )
2014-11-27 09:03:44 +03:00
- [SDUMP key ](#sdump-key )
2014-07-03 05:19:36 +04:00
- [ZSet ](#zset )
- [ZADD key score member [score member ...]](#zadd-key-score-member-score-member-)
- [ZCARD key ](#zcard-key )
- [ZCOUNT key min max ](#zcount-key-min-max )
- [ZINCRBY key increment member ](#zincrby-key-increment-member )
- [ZRANGE key start stop [WITHSCORES]](#zrange-key-start-stop-withscores)
- [ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]](#zrangebyscore-key-min-max-withscores-limit-offset-count)
- [ZRANK key member ](#zrank-key-member )
- [ZREM key member [member ...]](#zrem-key-member-member-)
- [ZREMRANGEBYRANK key start stop ](#zremrangebyrank-key-start-stop )
- [ZREMRANGEBYSCORE key min max ](#zremrangebyscore-key-min-max )
- [ZREVRANGE key start stop [WITHSCORES]](#zrevrange-key-start-stop-withscores)
2014-07-15 14:15:03 +04:00
- [ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]](#zrevrangebyscore-key-max-min-withscores-limit-offset-count)
2014-07-08 17:58:27 +04:00
- [ZREVRANK key member ](#zrevrank-key-member )
2014-07-03 05:19:36 +04:00
- [ZSCORE key member ](#zscore-key-member )
- [ZCLEAR key ](#zclear-key )
- [ZMCLEAR key [key ...]](#zmclear-key-key-)
- [ZEXPIRE key seconds ](#zexpire-key-seconds )
- [ZEXPIREAT key timestamp ](#zexpireat-key-timestamp )
- [ZTTL key ](#zttl-key )
- [ZPERSIST key ](#zpersist-key )
2014-08-13 12:28:59 +04:00
- [ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]
](#zunionstore-destination-numkeys-key-key--weights-weight-weight--aggregate-summinmax)
- [ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]
](#zinterstore-destination-numkeys-key-key--weights-weight-weight--aggregate-summinmax)
2014-10-02 11:40:53 +04:00
- [ZRANGEBYLEX key min max [LIMIT offset count]](#zrangebylex-key-min-max-limit-offset-count)
- [ZREMRANGEBYLEX key min max ](#zremrangebylex-key-min-max )
- [ZLEXCOUNT key min max ](#zlexcount-key-min-max )
2014-11-27 09:03:44 +03:00
- [ZDUMP key ](#zdump-key )
2014-07-15 14:15:03 +04:00
- [Bitmap ](#bitmap )
- [BGET key ](#bget-key )
2014-07-16 12:57:38 +04:00
- [BGETBIT key offset ](#bgetbit-key-offset )
- [BSETBIT key offset value ](#bsetbit-key-offset-value )
- [BMSETBIT key offset value[offset value ...]](#bmsetbit-key-offset-value-offset-value-)
- [BOPT operation destkey key [key ...]](#bopt-operation-destkey-key-key-)
2014-07-15 14:15:03 +04:00
- [BCOUNT key [start, end]](#bcount-key-start-end)
- [BEXPIRE key seconds ](#bexpire-key-seconds )
- [BEXPIREAT key timestamp ](#bexpireat-key-timestamp )
- [BTTL key ](#bttl-key )
- [BPERSIST key ](#bpersist-key )
2015-03-02 09:44:00 +03:00
- [Scan ](#scan )
- [XSCAN type cursor [MATCH match] [COUNT count]](#xscan-type-cursor-match-match-count-count)
- [XHSCAN key cursor [MATCH match] [COUNT count]](#xhscan-key-cursor-match-match-count-count)
- [XSSCAN key cursor [MATCH match] [COUNT count]](#xsscan-key-cursor-match-match-count-count)
- [XZSCAN key cursor [MATCH match] [COUNT count]](#xzscan-key-cursor-match-match-count-count)
2014-07-03 05:19:36 +04:00
- [Replication ](#replication )
2014-10-10 05:49:16 +04:00
- [SLAVEOF host port [RESTART] [READONLY]](#slaveof-host-port-restart-readonly)
2014-10-11 13:44:31 +04:00
- [FULLSYNC [NEW]](#fullsync-new)
2014-09-22 13:50:51 +04:00
- [SYNC logid ](#sync-logid )
2014-07-03 05:19:36 +04:00
- [Server ](#server )
- [PING ](#ping )
- [ECHO message ](#echo-message )
- [SELECT index ](#select-index )
2014-08-27 06:57:18 +04:00
- [FLUSHALL ](#flushall )
- [FLUSHDB ](#flushdb )
- [INFO [section]](#info-section)
2014-10-08 09:55:46 +04:00
- [TIME ](#time )
2014-10-08 12:39:14 +04:00
- [CONFIG REWRITE ](#config-rewrite )
2014-11-27 09:06:00 +03:00
- [RESTORE key ttl value ](#restore-key-ttl-value )
2015-02-03 09:22:12 +03:00
- [ROLE ](#role )
2014-09-25 06:44:07 +04:00
- [Transaction ](#transaction )
- [BEGIN ](#begin )
- [ROLLBACK ](#rollback )
- [COMMIT ](#commit )
2014-09-02 18:36:50 +04:00
- [Script ](#script )
- [EVAL script numkeys key [key ...] arg [arg ...]](#eval-script-numkeys-key-key--arg-arg-)
- [EVALSHA sha1 numkeys key [key ...] arg [arg ...]](#evalsha-sha1-numkeys-key-key--arg-arg-)
- [SCRIPT LOAD script ](#script-load-script )
- [SCRIPT EXISTS script [script ...]](#script-exists-script-script-)
- [SCRIPT FLUSH ](#script-flush )
2014-07-03 05:19:36 +04:00
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.
2014-07-01 14:09:23 +04:00
An error returns if the value for the key is a wrong type that can not be represented as a `signed 64 bit integer` .
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> 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
2014-07-01 14:09:23 +04:00
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
2014-07-01 14:09:23 +04:00
Get the value of key. If the key does not exists, it returns `nil` value.
2014-06-25 10:22:48 +04:00
**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 14:09:23 +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 14:09:23 +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
2014-07-01 14:09:23 +04:00
Returns the values of all specified keys. If the key does not exists, a `nil` will return.
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
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-10-26 10:15:43 +03:00
### SETEX key seconds value
Set key to hold the string value and set key to timeout after a given number of seconds. This command is equivalent to executing the following commands:
```
SET mykey value
EXPIRE mykey seconds
```
**Return value**
Simple string reply
**Examples**
```
ledis> SETEX mykey 10 "Hello"
OK
ledis> TTL mykey
(integer) 10
ledis> GET mykey
"Hello"
ledis>
```
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-11-27 09:03:44 +03:00
### DUMP key
Serialize the value stored at key with KV type in a Redis-specific format like RDB and return it to the user. The returned value can be synthesized back into a key using the RESTORE command.
**Return value**
bulk: the serialized value
**Examples**
```
ledis> set mykey 10
OK
ledis>DUMP mykey
"\x00\xc0\n\x06\x00\xf8r?\xc5\xfb\xfb_("
```
2014-10-20 18:36:16 +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**
2014-07-01 14:09:23 +04:00
bulk: the value associated with field, or `nil` .
2014-06-26 12:26:09 +04:00
**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
2014-07-01 14:09:23 +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-26 12:26:09 +04:00
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
2014-08-15 13:30:15 +04:00
Deletes the specified hash key
2014-06-26 12:26:09 +04:00
2014-06-25 10:22:48 +04:00
**Return value**
2014-06-27 12:28:26 +04:00
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...]
2014-06-27 12:28:26 +04:00
2014-07-01 14:09:23 +04:00
Deletes the specified hash keys.
2014-06-27 12:28:26 +04:00
**Return value**
int64: the number of input keys
**Examples**
```
2014-07-01 13:29:37 +04:00
ledis> HMSET myhash field1 "hello" field2 "world"
2014-06-27 12:28:26 +04:00
OK
2014-07-01 13:29:37 +04:00
ledis> HMCLEAR myhash
2014-06-27 12:28:26 +04:00
(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**
```
2014-07-01 13:39:10 +04:00
ledis> HSET myhash a 100
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> HGET myhash a
2014-07-01 13:29:37 +04:00
100
2014-07-01 13:39:10 +04:00
ledis> HEXPIRE myhash 100
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> HTTL myhash
2014-07-01 13:29:37 +04:00
(integer) 94
2014-07-01 13:39:10 +04:00
ledis> HPERSIST myhash
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> HTTL myhash
2014-07-01 13:29:37 +04:00
(integer) -1
2014-07-01 13:39:10 +04:00
ledis> HEXPIRE not_exists_key 100
2014-07-01 13:29:37 +04:00
(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**
```
2014-07-01 13:39:10 +04:00
ledis> HSET myhash a 100
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> HEXPIREAT myhash 1404999999
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> HTTL myhash
2014-07-01 13:29:37 +04:00
(integer) 802475
2014-07-01 13:39:10 +04:00
ledis> HEXPIREAT not_exists_key 1404999999
2014-07-01 13:29:37 +04:00
(integer) 0
```
### HTTL key
2014-07-01 14:09:23 +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-07-01 13:29:37 +04:00
**Return value**
int64: TTL in seconds
**Examples**
```
2014-07-01 13:39:10 +04:00
ledis> HSET myhash a 100
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> HEXPIREAT myhash 1404999999
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> HTTL myhash
2014-07-01 13:29:37 +04:00
(integer) 802475
2014-07-01 13:39:10 +04:00
ledis> HTTL not_set_timeout
2014-07-01 13:29:37 +04:00
(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 14:09:23 +04:00
Remove the existing timeout on key.
2014-07-01 13:29:37 +04:00
**Return value**
int64:
- 1 if the timeout was removed
- 0 if key does not exist or does not have an timeout
```
2014-07-01 13:39:10 +04:00
ledis> HSET myhash a 100
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> HEXPIREAT myhash 1404999999
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> HTTL myhash
2014-07-01 13:29:37 +04:00
(integer) 802475
2014-07-01 13:39:10 +04:00
ledis> HPERSIST myhash
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> HTTL myhash
2014-07-01 13:29:37 +04:00
(integer) -1
2014-07-01 13:39:10 +04:00
ledis> HPERSIST not_exists_key
2014-07-01 13:29:37 +04:00
(integer) 0
```
2014-11-27 09:03:44 +03:00
### HDUMP key
See [DUMP ](#dump-key ) for more information.
2014-06-25 10:22:48 +04:00
## List
2014-10-17 07:41:15 +04:00
### BLPOP key [key ...] timeout
BLPOP is a blocking list pop primitive. It is the blocking version of LPOP because it blocks the connection when there are no elements to pop from any of the given lists. An element is popped from the head of the first list that is non-empty, with the given keys being checked in the order that they are given.
When BLPOP causes a client to block and a non-zero timeout is specified, the client will unblock returning a nil multi-bulk value when the specified timeout has expired.
The timeout argument is interpreted as an double value specifying the maximum number of seconds to block. You can use 0.005 format to support milliseconds timeout.
A timeout of zero can be used to block indefinitely.
2014-10-17 07:44:26 +04:00
BLPOP and BRPOP can not work correctly in transaction now!
2014-10-17 07:41:15 +04:00
**Return value**
array:
+ A nil multi-bulk when no element could be popped and the timeout expired.
+ A two-element multi-bulk with the first element being the name of the key where an element was popped and the second element being the value of the popped element.
**Examples**
```
ledis> RPUSH list1 a b c
(integer) 3
ledis> BLPOP list1 list2 0
1) "list1"
2) "a"
```
### BRPOP key [key ...] timeout
See [BLPOP key [key ...] timeout](#blpop-key-key--timeout) for more information.
2014-07-01 13:29:37 +04:00
### LINDEX key index
2014-07-01 14:09:23 +04:00
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.
2014-07-01 13:29:37 +04:00
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 14:09:23 +04:00
string: the requested element, or `nil` when index is out of range.
2014-07-01 13:29:37 +04:00
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
2014-07-01 13:39:10 +04:00
ledis> RPUSH a 1 2 3
2014-07-01 13:29:37 +04:00
(integer) 3
2014-07-01 13:39:10 +04:00
ledis> LINDEX a 0
2014-07-01 13:29:37 +04:00
1
2014-07-01 13:39:10 +04:00
ledis> LINDEX a 1
2014-07-01 13:29:37 +04:00
2
2014-07-01 13:39:10 +04:00
ledis> LINDEX a 2
2014-07-01 13:29:37 +04:00
3
2014-07-01 13:39:10 +04:00
ledis> LINDEX a 3
2014-07-01 13:29:37 +04:00
(nil)
2014-07-01 13:39:10 +04:00
ledis> LINDEX a -1
2014-07-01 13:29:37 +04:00
3
```
### LLEN key
2014-07-01 14:09:23 +04:00
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-07-01 13:29:37 +04:00
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
```
2014-07-01 13:39:10 +04:00
ledis> RPUSH a 'foo'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> RPUSH a 'bar'
2014-07-01 13:29:37 +04:00
(integer) 2
2014-07-01 13:39:10 +04:00
ledis> LLEN a
2014-07-01 13:29:37 +04:00
(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 14:09:23 +04:00
bulk: the value of the first element, or `nil` when key does not exist.
2014-07-01 13:29:37 +04:00
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
2014-07-01 13:39:10 +04:00
ledis> RPUSH a 'one'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> RPUSH a 'two'
2014-07-01 13:29:37 +04:00
(integer) 2
2014-07-01 13:39:10 +04:00
ledis> RPUSH a 'three'
2014-07-01 13:29:37 +04:00
(integer) 3
2014-07-01 13:39:10 +04:00
ledis> LPOP a
2014-07-01 13:29:37 +04:00
one
```
### LRANGE key start stop
2014-07-01 14:09:23 +04:00
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-07-01 13:29:37 +04:00
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
```
2014-07-01 13:39:10 +04:00
ledis> RPUSH a 'one' 'two' 'three'
2014-07-01 13:29:37 +04:00
(integer) 3
2014-07-01 13:39:10 +04:00
ledis> LRANGE a 0 0
2014-07-01 13:29:37 +04:00
1) "one"
2014-07-01 13:39:10 +04:00
ledis> LRANGE a -100 100
2014-07-01 13:29:37 +04:00
1) "one"
2) "two"
3) "three"
2014-07-01 13:39:10 +04:00
ledis> LRANGE a -3 2
2014-07-01 13:29:37 +04:00
1) "one"
2) "two"
3) "three"
2014-07-01 13:39:10 +04:00
ledis> LRANGE a 0 -1
2014-07-01 13:29:37 +04:00
(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
```
2014-07-01 13:39:10 +04:00
ledis> LPUSH a 1
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> LPUSH a 2
2014-07-01 13:29:37 +04:00
(integer) 2
2014-07-01 13:39:10 +04:00
ledis> LRANGE a 0 2
2014-07-01 13:29:37 +04:00
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 14:09:23 +04:00
bulk: the value of the last element, or `nil` when key does not exist.
2014-07-01 13:29:37 +04:00
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
edis > RPUSH a 1
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> RPUSH a 2
2014-07-01 13:29:37 +04:00
(integer) 2
2014-07-01 13:39:10 +04:00
ledis> RPUSH a 3
2014-07-01 13:29:37 +04:00
(integer) 3
2014-07-01 13:39:10 +04:00
ledis> RPOP a
2014-07-01 13:29:37 +04:00
3
2014-07-01 13:39:10 +04:00
ledis> LRANGE a 0 3
2014-07-01 13:29:37 +04:00
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
```
2014-07-01 13:39:10 +04:00
ledis> RPUSH a 'hello'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> RPUSH a 'world'
2014-07-01 13:29:37 +04:00
(integer) 2
2014-07-01 13:39:10 +04:00
ledis> LRANGE a 0 2
2014-07-01 13:29:37 +04:00
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
```
2014-07-01 13:39:10 +04:00
ledis> RPUSH a 1 2 3
2014-07-01 13:29:37 +04:00
(integer) 3
2014-07-01 13:39:10 +04:00
ledis> LLEN a
2014-07-01 13:29:37 +04:00
(integer) 3
2014-07-01 13:39:10 +04:00
ledis> LCLEAR a
2014-07-01 13:29:37 +04:00
(integer) 3
2014-07-01 13:39:10 +04:00
ledis> LLEN a
2014-07-01 13:29:37 +04:00
(integer) 0
```
2014-07-08 18:05:50 +04:00
### LMCLEAR key [key ...]
2014-07-08 17:58:27 +04:00
Delete multiple keys from list
**Return value**
int64: the number of input keys
**Examples**
```
ledis> rpush a 1
(integer) 1
ledis> rpush b 2
(integer) 1
ledis> lmclear a b
(integer) 2
```
2014-07-01 13:29:37 +04:00
### 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
```
2014-07-01 13:39:10 +04:00
ledis> RPUSH a 1
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> LEXPIRE a 100
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> LTTL a
2014-07-01 13:29:37 +04:00
(integer) 96
2014-07-01 13:39:10 +04:00
ledis> LPERSIST a
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> LTTL a
2014-07-01 13:29:37 +04:00
(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
```
2014-07-01 13:39:10 +04:00
ledis> RPUSH a 1
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> LEXPIREAT a 1404140183
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> LTTL a
2014-07-01 13:29:37 +04:00
(integer) 570
2014-07-01 13:39:10 +04:00
ledis> LPERSIST a
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> LTTL a
2014-07-01 13:29:37 +04:00
(integer) -1
2014-07-01 13:39:10 +04:00
ledis>
2014-07-01 13:29:37 +04:00
```
### LTTL key
2014-07-01 14:09:23 +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-07-01 13:29:37 +04:00
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
```
2014-07-01 13:39:10 +04:00
ledis> RPUSH a 1
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> LEXPIREAT a 1404140183
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> LTTL a
2014-07-01 13:29:37 +04:00
(integer) 570
2014-07-01 13:39:10 +04:00
ledis> LPERSIST a
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> LTTL a
2014-07-01 13:29:37 +04:00
(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
```
2014-07-01 13:39:10 +04:00
ledis> RPUSH a 1
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> LEXPIREAT a 1404140183
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> LTTL a
2014-07-01 13:29:37 +04:00
(integer) 570
2014-07-01 13:39:10 +04:00
ledis> LPERSIST a
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> LTTL a
2014-07-01 13:29:37 +04:00
(integer) -1
2014-07-01 13:39:10 +04:00
ledis> LPERSIST b
2014-07-01 13:29:37 +04:00
(integer) 0
```
2014-11-27 09:03:44 +03:00
### LDUMP key
See [DUMP ](#dump-key ) for more information.
2014-07-01 13:29:37 +04:00
2014-08-15 13:30:15 +04:00
## Set
### SADD key member [member ...]
Add the specified members to the set stored at key. Specified members that are already a member of this set are ignored. If key does not exist, a new set is created before adding the specified members.
**Return value**
int64: the number of elements that were added to the set, not including all the elements already present into the set.
**Examples**
```
ledis> SADD myset hello
(integer) 1
ledis> SADD myset world
(integer) 1
ledis> SADD myset hello
(integer) 0
ledis> SMEMBERS myset
1) "hello"
2) "world"
```
### SCARD key
Returns the set cardinality (number of elements) of the set stored at key.
**Return value**
int64: the cardinality (number of elements) of the set, or 0 if key does not exist.
**Examples**
```
ledis> SADD myset hello
(integer) 1
ledis> SADD myset world
(integer) 1
ledis> SADD myset hello
(integer) 0
ledis> SCARD myset
(integer) 2
```
### SDIFF key [key ...]
Returns the members of the set resulting from the difference between the first set and all the successive sets.
For example:
```
key1 = {a,b,c,d}
key2 = {c}
key3 = {a,c,e}
SDIFF key1 key2 key3 = {b,d}
```
Keys that do not exist are considered to be empty sets.
**Return value**
bulk: list with members of the resulting set.
**Examples**
```
ledis> SADD key1 a b c
(integer) 3
ledis> SADD key2 c d e
(integer) 3
ledis> SDIFF key1 key2
1) "a"
2) "b"
ledis> SDIFF key2 key1
1) "d"
2) "e"
```
### SDIFFSTORE destination key [key ...]
This command is equal to `SDIFF` , but instead of returning the resulting set, it is stored in destination.
If destination already exists, it is overwritten.
**Return value**
int64: the number of elements in the resulting set.
**Examples**
```
ledis> SADD key1 a b c
(integer) 3
ledis> SADD key2 c d e
(integer) 3
ledis> SDIFF key1 key2
1) "a"
2) "b"
ledis> SDIFFSTORE key key1 key2
(integer) 2
ledis> SMEMBERS key
1) "a"
2) "b"
```
### SINTER key [key ...]
Returns the members of the set resulting from the intersection of all the given sets.
For example:
```
key1 = {a,b,c,d}
key2 = {c}
key3 = {a,c,e}
SINTER key1 key2 key3 = {c}
```
Keys that do not exist are considered to be empty sets. With one of the keys being an empty set, the resulting set is also empty (since set intersection with an empty set always results in an empty set).
**Return value**
bulk: list with members of the resulting set.
**Examples**
```
ledis> SADD key1 a b c
(integer) 3
ledis> SADD key2 c d e
(integer) 3
ledis> SINTER key1 key2
1) "c"
ledis> SINTER key2 key_empty
(nil)
```
### SINTERSTORE destination key [key ...]
This command is equal to `SINTER` , but instead of returning the resulting set, it is stored in destination.
If destination already exists, it is overwritten.
**Return value**
int64: the number of elements in the resulting set.
**Examples**
```
ledis> SADD key1 a b c
(integer) 3
ledis> SADD key2 c d e
(integer) 3
ledis> SINTERSTORE key key1 key2
(integer) 1
ledis> SMEMBERS key
1) "c"
```
### SISMEMBER key member
Returns if member is a member of the set stored at key.
**Return value**
Int64 reply, specifically:
- 1 if the element is a member of the set.
- 0 if the element is not a member of the set, or if key does not exist.
**Examples**
```
ledis> SADD myset hello
(integer) 1
ledis> SISMEMBER myset hello
(integer) 1
ledis> SISMEMBER myset hell
(integer) 0
```
### SMEMBERS key
Returns all the members of the set value stored at key.
This has the same effect as running `SINTER` with one argument key.
**Return value**
bulk: all elements of the set.
**Examples**
```
ledis> SADD myset hello
(integer) 1
ledis> SADD myset world
(integer) 1
ledis> SMEMBERS myset
1) "hello"
2) "world"
```
### SREM key member [member ...]
Remove the specified members from the set stored at key. Specified members that are not a member of this set are ignored. If key does not exist, it is treated as an empty set and this command returns 0.
**Return value**
int64: the number of members that were removed from the set, not including non existing members.
**Examples**
```
ledis> SADD myset one
(integer) 1
ledis> SADD myset two
(integer) 1
ledis> SADD myset three
(integer) 1
ledis> SREM myset one
(integer) 1
ledis> SREM myset four
(integer) 0
ledis> SMEMBERS myset
1) "three"
2) "two"
```
### SUNION key [key ...]
Returns the members of the set resulting from the union of all the given sets.
For example:
```
key1 = {a,b,c,d}
key2 = {c}
key3 = {a,c,e}
SUNION key1 key2 key3 = {a,b,c,d,e}
```
Keys that do not exist are considered to be empty sets.
**Return value**
bulk: list with members of the resulting set.
**Examples**
```
ledis> SMEMBERS key1
1) "a"
2) "b"
3) "c"
ledis> SMEMBERS key2
1) "c"
2) "d"
3) "e"
ledis> SUNION key1 key2
1) "a"
2) "b"
3) "c"
4) "d"
5) "e"
```
### SUNIONSTORE destination key [key]
This command is equal to SUNION, but instead of returning the resulting set, it is stored in destination.
If destination already exists, it is overwritten.
**Return value**
int64: the number of elements in the resulting set.
**Examples**
```
ledis> SMEMBERS key1
1) "a"
2) "b"
3) "c"
ledis> SMEMBERS key2
1) "c"
2) "d"
3) "e"
ledis> SUNIONSTORE key key1 key2
(integer) 5
ledis> SMEMBERS key
1) "a"
2) "b"
3) "c"
4) "d"
5) "e"
```
### SCLEAR key
Deletes the specified set key
**Return value**
int64: the number of fields in the hash stored at key
**Examples**
```
ledis> SMEMBERS key
1) "a"
2) "b"
3) "c"
4) "d"
5) "e"
ledis> SCLEAR key
(integer) 5
```
### SMCLEAR key [key ...]
Deletes the specified set keys.
**Return value**
int64: the number of input keys
**Examples**
```
ledis> SMCLEAR key1 key2
(integer) 2
ledis> SMCLEAR em1 em2
(integer) 2
```
### SEXPIRE key seconds
Sets a set key’ s time to live in seconds, like expire similarly.
**Return value**
int64:
- 1 if the timeout was set
- 0 if key does not exist or the timeout could not be set
**Examples**
```
ledis> SADD key 1 2
(integer) 2
ledis> SEXPIRE key 100
(integer) 1
ledis> STTL key
(integer) 95
```
### SEXPIREAT key timestamp
Sets the expiration for a set key as a unix timestamp, like expireat similarly.
**Return value**
int64:
- 1 if the timeout was set
- 0 if key does not exist or the timeout could not be set
**Examples**
```
ledis> SADD key 1 2
(integer) 2
ledis> SEXPIREAT key 1408094999
(integer) 1
ledis> STTL key
(integer) 908
```
### STTL 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**
```
ledis> SADD key 1 2
(integer) 2
ledis> SEXPIREAT key 1408094999
(integer) 1
ledis> STTL key
(integer) 908
```
### SPERSIST key
Remove the expiration from a set key, like persist similarly. 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
**Examples**
```
ledis> SEXPIREAT key 1408094999
(integer) 1
ledis> STTL key
(integer) 908
ledis> SPERSIST key
(integer) 1
ledis> STTL key
(integer) -1
```
2014-11-27 09:03:44 +03:00
### SDUMP key
See [DUMP ](#dump-key ) for more information.
2014-06-25 10:22:48 +04:00
## ZSet
2014-07-01 13:29:37 +04:00
### ZADD key score member [score member ...]
2014-07-01 14:09:23 +04:00
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.
2014-07-01 13:29:37 +04:00
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.
2014-07-01 14:09:23 +04:00
The score values should be the string representation of an `int64` number. `+inf` and `-inf` values are valid values as well.
**Currently, we only support int64 type, not double type.**
2014-07-01 13:29:37 +04:00
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 13:29:37 +04:00
int64, specifically:
2014-07-01 14:09:23 +04:00
The number of elements added to the sorted sets, **not** including elements already existing for which the score was updated.
2014-07-01 13:29:37 +04:00
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 1 'one'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 1 'uno'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 2 'two' 3 'three'
2014-07-01 13:29:37 +04:00
(integer) 2
2014-08-15 13:30:15 +04:00
ledis> ZRANGE myzset 0 -1 WITHSCORES
2014-07-01 13:29:37 +04:00
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 14:09:23 +04:00
int64: the cardinality (number of elements) of the sorted set, or `0` if key does not exist.
2014-07-01 13:29:37 +04:00
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
2014-08-15 13:30:15 +04:00
edis > ZADD myzset 1 'one'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 1 'uno'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 2 'two' 3 'three'
2014-07-01 13:29:37 +04:00
(integer) 2
2014-08-15 13:30:15 +04:00
ledis> ZRANGE myzset 0 -1 WITHSCORES
2014-07-01 13:29:37 +04:00
1) "one"
2) "1"
3) "uno"
4) "1"
5) "two"
6) "2"
7) "three"
8) "3"
2014-08-15 13:30:15 +04:00
ledis> ZCARD myzset
2014-07-01 13:29:37 +04:00
(integer) 4
```
### ZCOUNT key min max
2014-07-01 14:09:23 +04:00
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-07-01 13:29:37 +04:00
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
```
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 1 'one'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 1 'uno'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 2 'two' 3 'three'
2014-07-01 13:29:37 +04:00
(integer) 2
2014-08-15 13:30:15 +04:00
ledis> ZRANGE myzset 0 -1 WITHSCORES
2014-07-01 13:29:37 +04:00
1) "one"
2) "1"
3) "uno"
4) "1"
5) "two"
6) "2"
7) "three"
8) "3"
2014-08-15 13:30:15 +04:00
ledis> ZCOUNT myzset -inf +inf
2014-07-01 13:29:37 +04:00
(integer) 4
2014-08-15 13:30:15 +04:00
ledis> ZCOUNT myzset (1 3
2014-07-01 13:29:37 +04:00
(integer) 2
```
### ZINCRBY key increment member
2014-07-01 14:09:23 +04:00
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). If key does not exist, a new sorted set with the specified member as its sole member is created.
2014-07-01 13:29:37 +04:00
An error is returned when key exists but does not hold a sorted set.
2014-07-01 14:09:23 +04:00
The score value should be the string representation of a numeric value. It is possible to provide a negative value to decrement the score.
2014-07-01 13:29:37 +04:00
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 14:09:23 +04:00
bulk: the new score of member (an int64 number), represented as string.
2014-07-01 13:29:37 +04:00
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 1 'one'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 2 'two'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZINCRBY myzset 2 'one'
2014-07-01 13:29:37 +04:00
3
2014-08-15 13:30:15 +04:00
ledis> ZRANGE myzset 0 -1 WITHSCORES
2014-07-01 13:29:37 +04:00
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
```
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 1 'one'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 2 'two'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 3 'three'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZRANGE myzset 0 -1
2014-07-01 13:29:37 +04:00
1) "one"
2) "two"
3) "three"
2014-08-15 13:30:15 +04:00
ledis> ZRANGE myzset 2 3
2014-07-01 13:29:37 +04:00
1) "three"
2014-08-15 13:30:15 +04:00
ledis> ZRANGE myzset -2 -1
2014-07-01 13:29:37 +04:00
1) "two"
2) "three"
```
### ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]
2014-07-01 14:09:23 +04:00
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.
**Exclusive intervals and infinity**
`min` and `max` can be `-inf` and `+inf` , so that you are not required to know the highest or lowest score in the sorted set to get all elements from or up to a certain score.
By default, the interval specified by min and max is closed (inclusive). It is possible to specify an open interval (exclusive) by prefixing the score with the character (. For example:
```
ZRANGEBYSCORE zset (1 5
```
Will return all elements with 1 < score < = 5 while:
```
ZRANGEBYSCORE zset (5 (10
```
Will return all the elements with 5 < score < 10 ( 5 and 10 excluded ) .
2014-07-01 13:29:37 +04:00
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
```
2014-07-01 13:39:10 +04:00
ledis> ZADD myzset 1 'one'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> ZADD myzset 2 'two'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> ZADD myzset 3 'three'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> ZRANGEBYSCORE myzset -inf +inf WITHSCORES
2014-07-01 13:29:37 +04:00
1) "one"
2) "1"
3) "two"
4) "2"
5) "three"
6) "3"
2014-07-01 13:39:10 +04:00
ledis> ZRANGEBYSCORE myzset -inf +inf WITHSCORES LIMIT 2 5
2014-07-01 13:29:37 +04:00
1) "three"
2) "3"
2014-07-01 13:39:10 +04:00
ledis> ZRANGEBYSCORE myzset (1 2 WITHSCORES
2014-07-01 13:29:37 +04:00
1) "two"
2) "2"
2014-07-01 13:39:10 +04:00
ledis> ZRANGEBYSCORE myzset (1 (2 WITHSCORES
2014-07-01 13:29:37 +04:00
```
### ZRANK key member
2014-07-01 14:09:23 +04:00
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-07-01 13:29:37 +04:00
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
```
2014-07-01 13:39:10 +04:00
ledis> ZADD myzset 1 'one'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> ZADD myzset 2 'two'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> ZADD myzset 3 'three'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> ZRANGEBYSCORE myzset -inf +inf WITHSCORES
2014-07-01 13:29:37 +04:00
1) "one"
2) "1"
3) "two"
4) "2"
5) "three"
6) "3"
2014-07-01 13:39:10 +04:00
ledis> ZRANK myzset 'three'
2014-07-01 13:29:37 +04:00
(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
```
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 1 one 2 two 3 three 4 four
2014-07-01 13:29:37 +04:00
(integer) 3
2014-08-15 13:30:15 +04:00
ledis> ZRANGE myzset 0 -1
2014-07-01 13:29:37 +04:00
1) "one"
2) "two"
3) "three"
4) "four"
2014-08-15 13:30:15 +04:00
ledis> ZREM myzset three
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZREM myzset one four three
2014-07-01 13:29:37 +04:00
(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**
```
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 1 one 2 two 3 three 4 four
2014-07-01 13:29:37 +04:00
(integer) 3
2014-08-15 13:30:15 +04:00
ledis> ZREMRANGEBYRANK myzset 0 2
2014-07-01 13:29:37 +04:00
(integer) 3
2014-08-15 13:30:15 +04:00
ledis> ZRANGE myzset 0 -1 WITHSCORES
2014-07-01 13:29:37 +04:00
1) "four"
2) "4"
```
### ZREMRANGEBYSCORE key min max
2014-07-01 14:09:23 +04:00
Removes all elements in the sorted set stored at key with a score between `min` and `max` (inclusive). `Min` and `max` can be exclusive, following the syntax of `ZRANGEBYSCORE` .
2014-07-01 13:29:37 +04:00
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
```
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 1 one 2 two 3 three 4 four
2014-07-01 13:29:37 +04:00
(integer) 4
2014-08-15 13:30:15 +04:00
ledis> ZREMRANGEBYSCORE myzset -inf (2
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZRANGE myzset 0 -1 WITHSCORES
2014-07-01 13:29:37 +04:00
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.
2014-07-01 14:09:23 +04:00
Apart from the reversed ordering, ZREVRANGE is similar to `ZRANGE` .
2014-07-01 13:29:37 +04:00
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
```
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 1 one 2 two 3 three 4 four
2014-07-01 13:29:37 +04:00
(integer) 4
2014-08-15 13:30:15 +04:00
ledis> ZREVRANGE myzset 0 -1
2014-07-01 13:29:37 +04:00
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
```
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 1 one 2 two 3 three 4 four
2014-07-01 13:29:37 +04:00
(integer) 4
2014-08-15 13:30:15 +04:00
ledis> ZREVRANGEBYSCORE myzset +inf -inf
2014-07-01 13:29:37 +04:00
1) "four"
2) "three"
3) "two"
4) "one"
2014-08-15 13:30:15 +04:00
ledis> ZREVRANGEBYSCORE myzset 2 1
2014-07-01 13:29:37 +04:00
1) "two"
2) "one"
2014-08-15 13:30:15 +04:00
ledis> ZREVRANGEBYSCORE myzset 2 (1
2014-07-01 13:29:37 +04:00
1) "two"
2014-08-15 13:30:15 +04:00
ledis> ZREVRANGEBYSCORE myzset (2 (1
2014-07-01 13:29:37 +04:00
(empty list or set)
2014-08-15 13:30:15 +04:00
ledis> ZREVRANGEBYSCORE myzset +inf -inf WITHSCORES LIMIT 1 2
2014-07-01 13:29:37 +04:00
1) "three"
2) "3"
3) "two"
4) "2"
```
2014-07-08 17:58:27 +04:00
### ZREVRANK key member
Returns the rank of member in the sorted set stored at key, with the scores ordered from high to low. The rank (or index) is 0-based, which means that the member with the highest score has rank 0.
Use ZRANK to get the rank of an element with the scores ordered from low to high.
**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.
**Examples**
```
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 1 one
2014-07-08 17:58:27 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 2 two
2014-07-08 17:58:27 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZREVRANK myzset one
2014-07-08 17:58:27 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZREVRANK myzset three
2014-07-08 17:58:27 +04:00
(nil)
```
2014-07-01 13:29:37 +04:00
### ZSCORE key member
Returns the score of member in the sorted set at key.
2014-07-01 14:09:23 +04:00
If member does not exist in the sorted set, or key does not exist, `nil` is returned.
2014-07-01 13:29:37 +04:00
2014-06-25 10:22:48 +04:00
**Return value**
2014-07-01 14:09:23 +04:00
bulk: the score of member (an `int64` number), represented as string.
2014-07-01 13:29:37 +04:00
2014-06-25 10:22:48 +04:00
**Examples**
2014-07-01 13:29:37 +04:00
```
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 1 'one'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZSCORE myzset 'one'
2014-07-01 13:29:37 +04:00
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
```
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 1 'one'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 2 'two'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 3 'three'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZRANGE myzset 0 -1
2014-07-01 13:29:37 +04:00
1) "one"
2) "two"
3) "three"
2014-08-15 13:30:15 +04:00
ledis> ZCLEAR myzset
2014-07-01 13:29:37 +04:00
(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
```
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset1 1 'one'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset2 2 'two'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZMCLEAR myzset1 myzset2
2014-07-01 13:29:37 +04:00
(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
```
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 1 'one'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZEXPIRE myzset 100
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZTTL myzset
2014-07-01 13:29:37 +04:00
(integer) 97
2014-08-15 13:30:15 +04:00
ledis> ZPERSIST myzset
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> ZTTL mset
2014-07-01 13:29:37 +04:00
(integer) -1
2014-08-15 13:30:15 +04:00
ledis> ZEXPIRE myzset1 100
2014-07-01 13:29:37 +04:00
(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
```
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 1 'one'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZEXPIREAT myzset 1404149999
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZTTL myzset
2014-07-01 13:29:37 +04:00
(integer) 7155
2014-08-15 13:30:15 +04:00
ledis> ZPERSIST myzset
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> ZTTL mset
2014-07-01 13:29:37 +04:00
(integer) -1
2014-08-15 13:30:15 +04:00
ledis> ZEXPIREAT myzset1 1404149999
2014-07-01 13:29:37 +04:00
(integer) 0
```
### ZTTL key
2014-07-01 14:09:23 +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-07-01 13:29:37 +04:00
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
```
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 1 'one'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZEXPIRE myzset 100
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZTTL myzset
2014-07-01 13:29:37 +04:00
(integer) 97
2014-08-15 13:30:15 +04:00
ledis> ZTTL myzset2
2014-07-01 13:29:37 +04:00
(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
```
2014-08-15 13:30:15 +04:00
ledis> ZADD myzset 1 'one'
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZEXPIRE myzset 100
2014-07-01 13:29:37 +04:00
(integer) 1
2014-08-15 13:30:15 +04:00
ledis> ZTTL myzset
2014-07-01 13:29:37 +04:00
(integer) 97
2014-08-15 13:30:15 +04:00
ledis> ZPERSIST myzset
2014-07-01 13:29:37 +04:00
(integer) 1
2014-07-01 13:39:10 +04:00
ledis> ZTTL mset
2014-07-01 13:29:37 +04:00
(integer) -1
```
2014-08-13 12:28:59 +04:00
### ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]
Computes the union of numkeys sorted sets given by the specified keys, and stores the result in destination. It is mandatory to provide the number of input keys (numkeys) before passing the input keys and the other (optional) arguments.
By default, the resulting score of an element is the sum of its scores in the sorted sets where it exists.
Using the WEIGHTS option, it is possible to specify a multiplication factor for each input sorted set. This means that the score of every element in every input sorted set is multiplied by this factor before being passed to the aggregation function. When WEIGHTS is not given, the multiplication factors default to 1.
With the AGGREGATE option, it is possible to specify how the results of the union are aggregated. This option defaults to SUM, where the score of an element is summed across the inputs where it exists. When this option is set to either MIN or MAX, the resulting set will contain the minimum or maximum score of an element across the inputs where it exists.
If destination already exists, it is overwritten.
**Return value**
int64: the number of elements in the resulting sorted set at destination.
**Examples**
```
ledis> ZADD zset1 1 "one"
(interger) 1
ledis> ZADD zset1 2 "two"
(interger) 1
ledis> ZADD zset2 1 "one"
(interger) 1
ledis> ZADD zset2 2 "two"
(interger) 1
ledis> ZADD zset2 3 "three"
(interger) 1
ledis> ZUNIONSTORE out 2 zset1 zset2 WEIGHTS 2 3
(interger) 3
ledis> ZRANGE out 0 -1 WITHSCORES
1) "one"
2) "5"
3) "three"
4) "9"
5) "two"
6) "10"
```
### ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]
Computes the intersection of numkeys sorted sets given by the specified keys, and stores the result in destination. It is mandatory to provide the number of input keys (numkeys) before passing the input keys and the other (optional) arguments.
By default, the resulting score of an element is the sum of its scores in the sorted sets where it exists. Because intersection requires an element to be a member of every given sorted set, this results in the score of every element in the resulting sorted set to be equal to the number of input sorted sets.
For a description of the `WEIGHTS` and `AGGREGATE` options, see [ZUNIONSTORE ](#zunionstore-destination-numkeys-key-key--weights-weight-weight--aggregate-summinmax ).
If destination already exists, it is overwritten.
**Return value**
int64: the number of elements in the resulting sorted set at destination.
**Examples**
```
ledis> ZADD zset1 1 "one"
(interger) 1
ledis> ZADD zset1 2 "two"
(interger) 1
ledis> ZADD zset2 1 "one"
(interger) 1
ledis> ZADD zset2 2 "two"
(interger) 1
ledis> ZADD zset2 3 "three"
(interger) 1
ledis> ZINTERSTORE out 2 zset1 zset2 WEIGHTS 2 3
(interger) 3
ledis> ZRANGE out 0 -1 WITHSCORES
1) "one"
2) "5"
3) "two"
4) "10"
```
2014-07-01 13:29:37 +04:00
2014-10-02 11:40:53 +04:00
### ZRANGEBYLEX key min max [LIMIT offset count]
2014-07-16 12:57:38 +04:00
2014-10-02 11:40:53 +04:00
When all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command returns all the elements in the sorted set at key with a value between min and max.
If the elements in the sorted set have different scores, the returned elements are unspecified.
Valid start and stop must start with ( or [, in order to specify if the range item is respectively exclusive or inclusive. The special values of + or - for start and stop have the special meaning or positively infinite and negatively infinite strings, so for instance the command ZRANGEBYLEX myzset - + is guaranteed to return all the elements in the sorted set, if all the elements have the same score.
**Return value**
array: list of elements in the specified score range
**Example**
```
ledis> ZADD myzset 0 a 0 b 0 c 0 d 0 e 0 f 0 g
(integer) 7
ledis> ZRANGEBYLEX myzset - [c
1) "a"
2) "b"
3) "c"
ledis> ZRANGEBYLEX myzset - (c
1) "a"
2) "b"
ledis> ZRANGEBYLEX myzset [aaa (g
1) "b"
2) "c"
3) "d"
4) "e"
5) "f"
```
### ZREMRANGEBYLEX key min max
Removes all elements in the sorted set stored at key between the lexicographical range specified by min and max.
**Return value**
2014-07-15 14:15:03 +04:00
2014-10-02 11:40:53 +04:00
int64: he number of elements removed.
**Example**
```
ledis> ZADD myzset 0 a 0 b 0 c 0 d 0 e 0 f 0 g
(integer) 7
ledis> ZREMRANGEBYLEX myzset - [c
(integer) 3
```
### ZLEXCOUNT key min max
Returns the number of elements in the sorted set at key with a value between min and max.
**Return value**
int64: the number of elements in the specified score range.
**Example**
```
ledis> ZADD myzset 0 a 0 b 0 c 0 d 0 e 0 f 0 g
(integer) 7
ledis> ZLEXCOUNT myzset - [c
(integer) 3
```
2014-11-27 09:03:44 +03:00
### ZDUMP key
See [DUMP ](#dump-key ) for more information.
2014-10-02 11:40:53 +04:00
## Bitmap
2014-07-15 14:15:03 +04:00
2014-07-16 12:57:38 +04:00
### BGET key
Returns the whole binary data stored at `key` .
2014-07-15 14:15:03 +04:00
**Return value**
2014-07-16 12:57:38 +04:00
bulk: the raw value of key, or nil when key does not exist.
2014-07-15 14:15:03 +04:00
**Examples**
```
2014-07-16 12:57:38 +04:00
ledis> BMSETBIT flag 0 1 5 1 6 1
(integer) 3
ledis> BGET flag
a
2014-07-15 14:15:03 +04:00
```
### BGETBIT key offset
Returns the bit value at `offset` in the string value stored at `key` .
When *offset* beyond the data length, ot the target data is not exist, the bit value will be 0 always.
**Return value**
int64 : the bit value stored at offset.
**Examples**
```
ledis> BSETBIT flag 1024 1
(integer) 0
ledis> BGETBIT flag 0
(integer) 0
ledis> BGETBIT flag 1024
(integer) 1
ledis> BGETBIT flag 65535
(integer) 0
```
2014-07-16 12:57:38 +04:00
### BSETBIT key offset value
2014-07-15 14:15:03 +04:00
2014-07-16 12:57:38 +04:00
Sets or clear the bit at `offset` in the binary data sotred at `key` .
The bit is either set or cleared depending on `value` , which can be either `0` or `1` .
The *offset* argument is required to be qual to 0, and smaller than
2^23 (this means bitmap limits to 8MB).
2014-07-15 14:15:03 +04:00
**Return value**
2014-07-16 12:57:38 +04:00
int64 : the original bit value stored at offset.
2014-07-15 14:15:03 +04:00
**Examples**
```
2014-07-16 12:57:38 +04:00
ledis> BSETBIT flag 0 1
(integer) 0
ledis> BSETBIT flag 0 0
(integer) 1
ledis> BGETBIT flag 0 99
ERR invalid command param
```
### BMSETBIT key offset value [offset value ...]
Sets the given *offset* to their respective values.
**Return value**
int64 : The number of input *offset*
**Examples**
2014-07-15 14:15:03 +04:00
```
2014-07-16 12:57:38 +04:00
ledis> BMSETBIT flag 0 1 1 1 2 0 3 1
(integer) 4
ledis> BCOUNT flag
(integer) 3
```
2014-07-15 14:15:03 +04:00
2014-07-16 12:57:38 +04:00
### BOPT operation destkey key [key ...]
Perform a bitwise operation between multiple keys (containing string values) and store the result in the destination key.
2014-07-15 14:15:03 +04:00
2014-07-16 12:57:38 +04:00
**Return value**
Int64:
The size of the string stored in the destination key, that is equal to the size of the longest input string.
**Examples**
```
ledis> BMSETBIT a 0 1 2 1
(integer) 2
ledis> BMSETBIT b 1 1
(integer) 1
ledis> BOPT AND res a b
(integer) 3
ledis> BCOUNT res
(integer) 0
ledis> BOPT OR res2 a b
(integer) 3
ledis> BCOUNT res2
(integer) 3
ledis> BOPT XOR res3 a b
(integer) 3
ledis> BCOUNT res3
(integer) 3
```
### BCOUNT key [start end]
Count the number of set bits in a bitmap.
2014-07-15 14:15:03 +04:00
**Return value**
2014-07-16 12:57:38 +04:00
int64 : The number of bits set to 1.
2014-07-15 14:15:03 +04:00
**Examples**
```
2014-07-16 12:57:38 +04:00
ledis> BMSETBIT flag 0 1 5 1 6 1
(integer) 3
ledis> BGET flag
a
ledis> BCOUNT flag
(integer) 3
ledis> BCOUNT flag 0 0s
(integer) 1
ledis> BCOUNT flag 0 4
(integer) 1
ledis> BCOUNT flag 0 5
(integer) 2
ledis> BCOUNT flag 5 6
(integer) 2
2014-07-15 14:15:03 +04:00
```
### BEXPIRE key seconds
2014-07-15 20:10:50 +04:00
(refer to [EXPIRE ](#expire-key-seconds ) api for other types)
2014-07-15 14:15:03 +04:00
### BEXPIREAT key timestamp
2014-07-15 20:10:50 +04:00
(refer to [EXPIREAT ](#expireat-key-timestamp ) api for other types)
2014-07-15 14:15:03 +04:00
### BTTL key
2014-07-15 20:10:50 +04:00
(refer to [TTL ](#ttl-key ) api for other types)
2014-07-15 14:15:03 +04:00
2014-07-16 07:29:57 +04:00
### BPERSIST key
2014-07-15 14:15:03 +04:00
2014-07-15 20:10:50 +04:00
(refer to [PERSIST ](#persist-key ) api for other types)
2014-07-15 14:15:03 +04:00
2015-03-02 09:44:00 +03:00
## Scan
2014-08-27 06:29:17 +04:00
2015-03-02 09:44:00 +03:00
### XSCAN type cursor [MATCH match] [COUNT count]
2014-08-27 06:29:17 +04:00
2015-03-02 09:44:00 +03:00
Iterate data type keys incrementally.
2014-08-27 06:29:17 +04:00
2015-03-02 09:44:00 +03:00
Type is "KV", "LIST", "HASH", "SET" or "ZSET".
Cursor is the start for the current iteration.
Match is the regexp for checking matched key.
Count is the maximum retrieved elememts number, default is 10.
**Return value**
2014-10-20 18:36:16 +04:00
2015-03-02 09:44:00 +03:00
an array of two values, first value is the cursor for next iteration, second value is an array of elements.
2014-10-20 18:36:16 +04:00
2015-03-02 09:44:00 +03:00
**Examples**
```
ledis>set a 1
OK
ledis>set b 2
OK
ledis>set c 3
OK
127.0.0.1:6380>xscan "KV" ""
1) ""
2) ["a" "b" "c"]
ledis>xscan "KV" "" count 1
1) "a"
2) ["a"]
ledis>xscan "KV" "a" count 1
1) "b"
2) ["b"]
ledis>xscan "KV" "b" count 1
1) "c"
2) ["c"]
ledis>xscan "KV" "c" count 1
1) ""
2) []
```
2015-01-24 06:07:26 +03:00
2015-03-02 09:44:00 +03:00
### XHSCAN key cursor [MATCH match] [COUNT count]
2015-01-24 06:07:26 +03:00
2015-03-02 09:44:00 +03:00
Same like [XSCAN type cursor [MATCH match] [COUNT count]](#xscan-type-cursor-match-match-count-count), but return array of elements
contains two elements, a field and a value.
2015-01-24 06:07:26 +03:00
2015-03-02 09:44:00 +03:00
### XSSCAN key cursor [MATCH match] [COUNT count]
2015-01-24 06:07:26 +03:00
2015-03-02 09:44:00 +03:00
Same like [XSCAN type cursor [MATCH match] [COUNT count]](#xscan-type-cursor-match-match-count-count)
2015-01-24 06:07:26 +03:00
2015-03-02 09:44:00 +03:00
### XZSCAN key cursor [MATCH match] [COUNT count]
2015-01-24 06:07:26 +03:00
2015-03-02 09:44:00 +03:00
Same like [XSCAN type cursor [MATCH match] [COUNT count]](#xscan-type-cursor-match-match-count-count), but return array of elements
contains two elements, a member and its associated score.
2014-10-20 18:36:16 +04:00
2014-08-27 06:29:17 +04:00
2014-06-25 10:22:48 +04:00
## Replication
2014-10-10 05:49:16 +04:00
### SLAVEOF host port [RESTART] [READONLY]
2014-07-02 03:55:21 +04:00
2014-10-10 05:49:16 +04:00
Changes the replication settings of a slave on the fly. If the server is already acting as slave, `SLAVEOF NO ONE` will turn off the replication and turn the server into master. `SLAVEOF NO ONE READONLY` will turn the server into master with readonly mode.
2014-07-02 03:55:21 +04:00
2014-10-10 05:49:16 +04:00
If the server is already master, `SLAVEOF NO ONE READONLY` will force the server to readonly mode, and `SLAVEOF NO ONE` will disable readonly.
2014-07-02 03:55:21 +04:00
2014-10-10 05:49:16 +04:00
`SLAVEOF host port` will make the server a slave of another server listening at the specified host and port.
If a server is already a slave of a master, `SLAVEOF host port` will stop the replication against the old and start the synchronization against the new one, if RESTART is set, it will discard the old dataset, otherwise it will sync with LastLogID + 1.
2014-07-02 03:55:21 +04:00
2014-06-25 10:22:48 +04:00
2014-10-11 13:44:31 +04:00
### FULLSYNC [NEW]
2014-06-25 10:22:48 +04:00
2014-07-02 03:55:21 +04:00
Inner command, starts a fullsync from the master set by SLAVEOF.
FULLSYNC will first try to sync all data from the master, save in local disk, then discard old dataset and load new one.
2014-10-11 13:44:31 +04:00
`FULLSYNC NEW` will generate a new snapshot and sync, otherwise it will use the latest existing snapshot if possible.
2014-06-25 10:22:48 +04:00
**Return value**
**Examples**
2014-07-01 13:29:37 +04:00
2014-09-22 13:50:51 +04:00
### SYNC logid
2014-07-02 03:55:21 +04:00
2014-09-22 13:50:51 +04:00
Inner command, syncs the new changed from master set by SLAVEOF with logid.
2014-07-02 03:55:21 +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
```
2014-07-01 13:39:10 +04:00
ledis> PING
2014-07-01 13:29:37 +04:00
PONG
2014-07-01 13:39:10 +04:00
ledis> PING
2014-07-01 13:29:37 +04:00
dial tcp 127.0.0.1:6665: connection refused
2014-07-01 13:39:10 +04:00
ledis>
2014-07-01 13:29:37 +04:00
```
### 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
```
2014-07-01 13:39:10 +04:00
ledis> ECHO "hello"
2014-07-01 13:29:37 +04:00
hello
```
### SELECT index
2014-07-01 14:09:23 +04:00
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-07-01 13:29:37 +04:00
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
```
2014-07-01 13:39:10 +04:00
ledis> SELECT 2
2014-07-01 13:29:37 +04:00
OK
2014-07-01 13:39:10 +04:00
ledis> SELECT 15
2014-07-01 13:29:37 +04:00
OK
2014-07-01 13:39:10 +04:00
ledis> SELECT 16
2014-07-01 13:29:37 +04:00
ERR invalid db index 16
```
2014-07-03 05:19:36 +04:00
2014-08-27 06:57:18 +04:00
### FLUSHALL
2014-09-23 13:28:09 +04:00
Delete all the keys of all the existing databases and replication logs, not just the currently selected one. This command never fails.
2014-08-27 06:57:18 +04:00
Very dangerous to use!!!
### FLUSHDB
Delete all the keys of the currently selected DB. This command never fails.
Very dangerous to use!!!
### INFO [section]
Return information and statistic about the server in a format that is simple to parse by computers and easy to read by humans.
2014-10-15 06:41:43 +04:00
The optional parameter can be used to select a specific section of information. When no parameter is provided, all will return.
2014-08-27 06:57:18 +04:00
2014-10-08 09:55:46 +04:00
### TIME
The TIME command returns the current server time as a two items lists: a Unix timestamp and the amount of microseconds already elapsed in the current second
**Return value**
array: two elements, one is unix time in seconds, the other is microseconds.
2014-10-08 12:39:14 +04:00
### CONFIG REWRITE
Rewrites the config file the server was started with.
**Unlike Redis rewrite, it will discard all comments in origin config file.**
**Return value**
String: OK or error msg.
2014-11-27 09:03:44 +03:00
### RESTORE key ttl value
Create a key associated with a value that is obtained by deserializing the provided serialized value (obtained via DUMP, LDUMP, HDUMP, SDUMP, ZDUMP).
If ttl is 0 the key is created without any expire, otherwise the specified expire time (in milliseconds) is set. But you must know that now the checking ttl accuracy is second.
RESTORE checks the RDB version and data checksum. If they don't match an error is returned.
2015-02-03 09:22:12 +03:00
### ROLE
Provide information on the role of an intance in the context of replication.
Role: master and slave
Master output:
```
1) "master"
2) (integer) 3129659
3) 1) 1) "127.0.0.1"
2) "9001"
3) "3129242"
2) 1) "127.0.0.1"
2) "9002"
3) "3129543"
```
1. The string master.
2. The current master replication binlog last log id.
3. An array about the slaves, each sub array contains slave IP, port, and the last acknowledged replication binlog id.
Slave output:
```
1) "slave"
2) "127.0.0.1"
3) (integer) 9000
4) "connected"
5) (integer) 3167038
```
1. The string slave
2. The slave IP
3. The slave port
4. The slave replication state, includes connect, connecting, sync and connected.
5. The slave current replication binlog id.
2014-09-25 06:44:07 +04:00
## Transaction
### BEGIN
Marks the start of a transaction block. Subsequent commands will be in a transaction context util using COMMIT or ROLLBACK.
You must known that `BEGIN` will block any other write operators before you `COMMIT` or `ROLLBACK` . Don't use long-time transaction.
**Return value**
Returns `OK` if the backend store engine in use supports transaction, otherwise, returns `Err` .
**Examples**
```
ledis> BEGIN
OK
ledis> SET HELLO WORLD
OK
ledis> COMMIT
OK
```
### ROLLBACK
Discards all the changes of previously commands in a transaction and restores the connection state to normal.
**Return value**
Returns `OK` if in a transaction context, otherwise, `Err`
**Examples**
```
ledis> BEGIN
OK
ledis> SET HELLO WORLD
OK
ledis> GET HELLO
"WORLD"
ledis> ROLLBACK
OK
ledis> GET HELLO
(nil)
```
### COMMIT
Persists the changes of all the commands in a transaction and restores the connection state to normal.
**Return value**
Returns `OK` if in a transaction context, otherwise, `Err`
**Examples**
```
ledis> BEGIN
OK
ledis> SET HELLO WORLD
OK
ledis> GET HELLO
"WORLD"
ledis> COMMIT
OK
ledis> GET HELLO
"WORLD"
```
2014-08-25 10:18:23 +04:00
2014-09-02 18:36:50 +04:00
## Script
LedisDB's script is refer to Redis, you can see more [http://redis.io/commands/eval ](http://redis.io/commands/eval )
You must notice that executing lua will block any other write operations.
### EVAL script numkeys key [key ...] arg [arg ...]
### EVALSHA sha1 numkeys key [key ...] arg [arg ...]
### SCRIPT LOAD script
### SCRIPT EXISTS script [script ...]
### SCRIPT FLUSH
2014-07-03 05:19:36 +04:00
Thanks [doctoc ](http://doctoc.herokuapp.com/ )