Removed the parseBulkStr() proc in redis.nim
This commit is contained in:
parent
491e325608
commit
e9dcf26841
1 changed files with 20 additions and 23 deletions
|
|
@ -107,10 +107,6 @@ proc parseBulk(r: TRedis, allowMBNil = False): TRedisString =
|
||||||
var s = r.socket.recv(numBytes+2)
|
var s = r.socket.recv(numBytes+2)
|
||||||
result = stripNewline(s)
|
result = stripNewline(s)
|
||||||
|
|
||||||
proc parseBulkStr(r: TRedis, allowMBNil = False): TRedisString =
|
|
||||||
result = r.parseBulk(allowMBNil)
|
|
||||||
if result == RedisNil: result = redisNil
|
|
||||||
|
|
||||||
proc parseMultiBulk(r: TRedis): TRedisList =
|
proc parseMultiBulk(r: TRedis): TRedisList =
|
||||||
var line = ""
|
var line = ""
|
||||||
if not r.socket.recvLine(line):
|
if not r.socket.recvLine(line):
|
||||||
|
|
@ -168,7 +164,7 @@ proc persist*(r: TRedis, key: string): bool =
|
||||||
proc randomKey*(r: TRedis): TRedisString =
|
proc randomKey*(r: TRedis): TRedisString =
|
||||||
## Return a random key from the keyspace
|
## Return a random key from the keyspace
|
||||||
r.socket.send("RANDOMKEY\c\L")
|
r.socket.send("RANDOMKEY\c\L")
|
||||||
return r.parseBulkStr()
|
return r.parseBulk()
|
||||||
|
|
||||||
proc rename*(r: TRedis, key, newkey: string): TRedisStatus =
|
proc rename*(r: TRedis, key, newkey: string): TRedisStatus =
|
||||||
## Rename a key.
|
## Rename a key.
|
||||||
|
|
@ -214,7 +210,7 @@ proc decrBy*(r: TRedis, key: string, decrement: int): TRedisInteger =
|
||||||
proc get*(r: TRedis, key: string): TRedisString =
|
proc get*(r: TRedis, key: string): TRedisString =
|
||||||
## Get the value of a key. Returns `nil` when `key` doesn't exist.
|
## Get the value of a key. Returns `nil` when `key` doesn't exist.
|
||||||
r.socket.send("GET $1\c\L" % key)
|
r.socket.send("GET $1\c\L" % key)
|
||||||
return r.parseBulkStr()
|
return r.parseBulk()
|
||||||
|
|
||||||
proc getBit*(r: TRedis, key: string, offset: int): TRedisInteger =
|
proc getBit*(r: TRedis, key: string, offset: int): TRedisInteger =
|
||||||
## Returns the bit value at offset in the string value stored at key
|
## Returns the bit value at offset in the string value stored at key
|
||||||
|
|
@ -224,13 +220,13 @@ proc getBit*(r: TRedis, key: string, offset: int): TRedisInteger =
|
||||||
proc getRange*(r: TRedis, key: string, start, stop: int): TRedisString =
|
proc getRange*(r: TRedis, key: string, start, stop: int): TRedisString =
|
||||||
## Get a substring of the string stored at a key
|
## Get a substring of the string stored at a key
|
||||||
r.socket.send("GETRANGE $1 $2 $3\c\L" % [key, $start, $stop])
|
r.socket.send("GETRANGE $1 $2 $3\c\L" % [key, $start, $stop])
|
||||||
return r.parseBulkStr()
|
return r.parseBulk()
|
||||||
|
|
||||||
proc getSet*(r: TRedis, key: string, value: string): TRedisString =
|
proc getSet*(r: TRedis, key: string, value: string): TRedisString =
|
||||||
## Set the string value of a key and return its old value. Returns `nil` when
|
## Set the string value of a key and return its old value. Returns `nil` when
|
||||||
## key doesn't exist.
|
## key doesn't exist.
|
||||||
r.socket.send("GETSET $1 \"$2\"\c\L" % [key, value])
|
r.socket.send("GETSET $1 \"$2\"\c\L" % [key, value])
|
||||||
return r.parseBulkStr()
|
return r.parseBulk()
|
||||||
|
|
||||||
proc incr*(r: TRedis, key: string): TRedisInteger =
|
proc incr*(r: TRedis, key: string): TRedisInteger =
|
||||||
## Increment the integer value of a key by one.
|
## Increment the integer value of a key by one.
|
||||||
|
|
@ -292,7 +288,7 @@ proc hExists*(r: TRedis, key, field: string): bool =
|
||||||
proc hGet*(r: TRedis, key, field: string): TRedisString =
|
proc hGet*(r: TRedis, key, field: string): TRedisString =
|
||||||
## Get the value of a hash field
|
## Get the value of a hash field
|
||||||
r.socket.send("HGET $1 $2\c\L" % [key, field])
|
r.socket.send("HGET $1 $2\c\L" % [key, field])
|
||||||
return r.parseBulkStr()
|
return r.parseBulk()
|
||||||
|
|
||||||
proc hGetAll*(r: TRedis, key: string): TRedisList =
|
proc hGetAll*(r: TRedis, key: string): TRedisList =
|
||||||
## Get all the fields and values in a hash
|
## Get all the fields and values in a hash
|
||||||
|
|
@ -364,12 +360,12 @@ proc bRPopLPush*(r: TRedis, source, destination: string,
|
||||||
##
|
##
|
||||||
## http://redis.io/commands/brpoplpush
|
## http://redis.io/commands/brpoplpush
|
||||||
r.socket.send("BRPOPLPUSH $1 $2 $3\c\L" % [source, destination, $timeout])
|
r.socket.send("BRPOPLPUSH $1 $2 $3\c\L" % [source, destination, $timeout])
|
||||||
return r.parseBulkStr(true) # Multi-Bulk nil allowed.
|
return r.parseBulk(true) # Multi-Bulk nil allowed.
|
||||||
|
|
||||||
proc lIndex*(r: TRedis, key: string, index: int): TRedisString =
|
proc lIndex*(r: TRedis, key: string, index: int): TRedisString =
|
||||||
## Get an element from a list by its index
|
## Get an element from a list by its index
|
||||||
r.socket.send("LINDEX $1 $2\c\L" % [key, $index])
|
r.socket.send("LINDEX $1 $2\c\L" % [key, $index])
|
||||||
return r.parseBulkStr()
|
return r.parseBulk()
|
||||||
|
|
||||||
proc lInsert*(r: TRedis, key: string, before: bool, pivot, value: string):
|
proc lInsert*(r: TRedis, key: string, before: bool, pivot, value: string):
|
||||||
TRedisInteger =
|
TRedisInteger =
|
||||||
|
|
@ -386,7 +382,7 @@ proc lLen*(r: TRedis, key: string): TRedisInteger =
|
||||||
proc lPop*(r: TRedis, key: string): TRedisString =
|
proc lPop*(r: TRedis, key: string): TRedisString =
|
||||||
## Remove and get the first element in a list
|
## Remove and get the first element in a list
|
||||||
r.socket.send("LPOP $1\c\L" % key)
|
r.socket.send("LPOP $1\c\L" % key)
|
||||||
return r.parseBulkStr()
|
return r.parseBulk()
|
||||||
|
|
||||||
proc lPush*(r: TRedis, key, value: string, create: bool = True): TRedisInteger =
|
proc lPush*(r: TRedis, key, value: string, create: bool = True): TRedisInteger =
|
||||||
## Prepend a value to a list. Returns the length of the list after the push.
|
## Prepend a value to a list. Returns the length of the list after the push.
|
||||||
|
|
@ -424,12 +420,12 @@ proc lTrim*(r: TRedis, key: string, start, stop: int) =
|
||||||
proc rPop*(r: TRedis, key: string): TRedisString =
|
proc rPop*(r: TRedis, key: string): TRedisString =
|
||||||
## Remove and get the last element in a list
|
## Remove and get the last element in a list
|
||||||
r.socket.send("RPOP $1\c\L" % key)
|
r.socket.send("RPOP $1\c\L" % key)
|
||||||
return r.parseBulkStr()
|
return r.parseBulk()
|
||||||
|
|
||||||
proc rPopLPush*(r: TRedis, source, destination: string): TRedisString =
|
proc rPopLPush*(r: TRedis, source, destination: string): TRedisString =
|
||||||
## Remove the last element in a list, append it to another list and return it
|
## Remove the last element in a list, append it to another list and return it
|
||||||
r.socket.send("RPOPLPUSH $1 $2\c\L" % [source, destination])
|
r.socket.send("RPOPLPUSH $1 $2\c\L" % [source, destination])
|
||||||
return r.parseBulkStr()
|
return r.parseBulk()
|
||||||
|
|
||||||
proc rPush*(r: TRedis, key, value: string, create: bool = True): TRedisInteger =
|
proc rPush*(r: TRedis, key, value: string, create: bool = True): TRedisInteger =
|
||||||
## Append a value to a list. Returns the length of the list after the push.
|
## Append a value to a list. Returns the length of the list after the push.
|
||||||
|
|
@ -495,12 +491,12 @@ proc smove*(r: TRedis, source: string, destination: string,
|
||||||
proc spop*(r: TRedis, key: string): TRedisString =
|
proc spop*(r: TRedis, key: string): TRedisString =
|
||||||
## Remove and return a random member from a set
|
## Remove and return a random member from a set
|
||||||
r.socket.send("SPOP $#\c\L" % key)
|
r.socket.send("SPOP $#\c\L" % key)
|
||||||
return r.parseBulkStr()
|
return r.parseBulk()
|
||||||
|
|
||||||
proc srandmember*(r: TRedis, key: string): TRedisString =
|
proc srandmember*(r: TRedis, key: string): TRedisString =
|
||||||
## Get a random member from a set
|
## Get a random member from a set
|
||||||
r.socket.send("SRANDMEMBER $#\c\L" % key)
|
r.socket.send("SRANDMEMBER $#\c\L" % key)
|
||||||
return r.parseBulkStr()
|
return r.parseBulk()
|
||||||
|
|
||||||
proc srem*(r: TRedis, key: string, member: string): TRedisInteger =
|
proc srem*(r: TRedis, key: string, member: string): TRedisInteger =
|
||||||
## Remove a member from a set
|
## Remove a member from a set
|
||||||
|
|
@ -539,7 +535,7 @@ proc zincrby*(r: TRedis, key: string, increment: string,
|
||||||
member: string): TRedisString =
|
member: string): TRedisString =
|
||||||
## Increment the score of a member in a sorted set
|
## Increment the score of a member in a sorted set
|
||||||
r.socket.send("ZINCRBY $# $# \"$#\"\c\L" % [key, increment, member])
|
r.socket.send("ZINCRBY $# $# \"$#\"\c\L" % [key, increment, member])
|
||||||
return r.parseBulkStr()
|
return r.parseBulk()
|
||||||
|
|
||||||
proc zinterstore*(r: TRedis, destination: string, numkeys: string,
|
proc zinterstore*(r: TRedis, destination: string, numkeys: string,
|
||||||
key: openarray[string], weights: openarray[string] = [],
|
key: openarray[string], weights: openarray[string] = [],
|
||||||
|
|
@ -580,7 +576,7 @@ proc zrangebyscore*(r: TRedis, key: string, min: string, max: string,
|
||||||
proc zrank*(r: TRedis, key: string, member: string): TRedisString =
|
proc zrank*(r: TRedis, key: string, member: string): TRedisString =
|
||||||
## Determine the index of a member in a sorted set
|
## Determine the index of a member in a sorted set
|
||||||
r.socket.send("ZRANK $# \"$#\"\c\L" % [key, member])
|
r.socket.send("ZRANK $# \"$#\"\c\L" % [key, member])
|
||||||
return r.parseBulkStr()
|
return r.parseBulk()
|
||||||
|
|
||||||
proc zrem*(r: TRedis, key: string, member: string): TRedisInteger =
|
proc zrem*(r: TRedis, key: string, member: string): TRedisInteger =
|
||||||
## Remove a member from a sorted set
|
## Remove a member from a sorted set
|
||||||
|
|
@ -626,12 +622,12 @@ proc zrevrank*(r: TRedis, key: string, member: string): TRedisString =
|
||||||
## Determine the index of a member in a sorted set, with
|
## Determine the index of a member in a sorted set, with
|
||||||
## scores ordered from high to low
|
## scores ordered from high to low
|
||||||
r.socket.send("ZREVRANK $# \"$#\"\c\L" % [key, member])
|
r.socket.send("ZREVRANK $# \"$#\"\c\L" % [key, member])
|
||||||
return r.parseBulkStr()
|
return r.parseBulk()
|
||||||
|
|
||||||
proc zscore*(r: TRedis, key: string, member: string): TRedisString =
|
proc zscore*(r: TRedis, key: string, member: string): TRedisString =
|
||||||
## Get the score associated with the given member in a sorted set
|
## Get the score associated with the given member in a sorted set
|
||||||
r.socket.send("ZSCORE $# \"$#\"\c\L" % [key, member])
|
r.socket.send("ZSCORE $# \"$#\"\c\L" % [key, member])
|
||||||
return r.parseBulkStr()
|
return r.parseBulk()
|
||||||
|
|
||||||
proc zunionstore*(r: TRedis, destination: string, numkeys: string,
|
proc zunionstore*(r: TRedis, destination: string, numkeys: string,
|
||||||
key: openarray[string], weights: openarray[string] = [],
|
key: openarray[string], weights: openarray[string] = [],
|
||||||
|
|
@ -717,7 +713,7 @@ proc auth*(r: TRedis, password: string) =
|
||||||
proc echoServ*(r: TRedis, message: string): TRedisString =
|
proc echoServ*(r: TRedis, message: string): TRedisString =
|
||||||
## Echo the given string
|
## Echo the given string
|
||||||
r.socket.send("ECHO $#\c\L" % message)
|
r.socket.send("ECHO $#\c\L" % message)
|
||||||
return r.parseBulkStr()
|
return r.parseBulk()
|
||||||
|
|
||||||
proc ping*(r: TRedis): TRedisStatus =
|
proc ping*(r: TRedis): TRedisStatus =
|
||||||
## Ping the server
|
## Ping the server
|
||||||
|
|
@ -749,7 +745,7 @@ proc bgsave*(r: TRedis) =
|
||||||
proc configGet*(r: TRedis, parameter: string): TRedisString =
|
proc configGet*(r: TRedis, parameter: string): TRedisString =
|
||||||
## Get the value of a configuration parameter
|
## Get the value of a configuration parameter
|
||||||
r.socket.send("CONFIG GET $#\c\L" % parameter)
|
r.socket.send("CONFIG GET $#\c\L" % parameter)
|
||||||
return r.parseBulkStr()
|
return r.parseBulk()
|
||||||
|
|
||||||
proc configSet*(r: TRedis, parameter: string, value: string) =
|
proc configSet*(r: TRedis, parameter: string, value: string) =
|
||||||
## Set a configuration parameter to the given value
|
## Set a configuration parameter to the given value
|
||||||
|
|
@ -788,7 +784,7 @@ proc flushdb*(r: TRedis): TRedisStatus =
|
||||||
proc info*(r: TRedis): TRedisString =
|
proc info*(r: TRedis): TRedisString =
|
||||||
## Get information and statistics about the server
|
## Get information and statistics about the server
|
||||||
r.socket.send("INFO\c\L")
|
r.socket.send("INFO\c\L")
|
||||||
return r.parseBulkStr()
|
return r.parseBulk()
|
||||||
|
|
||||||
proc lastsave*(r: TRedis): TRedisInteger =
|
proc lastsave*(r: TRedis): TRedisInteger =
|
||||||
## Get the UNIX time stamp of the last successful save to disk
|
## Get the UNIX time stamp of the last successful save to disk
|
||||||
|
|
@ -824,6 +820,7 @@ when isMainModule:
|
||||||
r.setk("nim:utf8", "こんにちは")
|
r.setk("nim:utf8", "こんにちは")
|
||||||
echo r.incr("nim:int")
|
echo r.incr("nim:int")
|
||||||
echo r.incr("nim:int")
|
echo r.incr("nim:int")
|
||||||
|
echo r.get("nim:int")
|
||||||
echo r.get("nim:utf8")
|
echo r.get("nim:utf8")
|
||||||
echo repr(r.get("blahasha"))
|
echo repr(r.get("blahasha"))
|
||||||
var p = r.lrange("mylist", 0, -1)
|
var p = r.lrange("mylist", 0, -1)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue