Skip to content

Commit

Permalink
[FEAT] Add new commands
Browse files Browse the repository at this point in the history
- New commands: exists, hexists, keys, hkeys, lpos, lrem
- Fix copy(client) function
- Handle empty response from host
  • Loading branch information
captchanjack committed Jun 9, 2021
1 parent 2f622e1 commit da30f8a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Jedis"
uuid = "b89ccfe0-2c5f-46f6-b89b-da3e1c2e286f"
authors = ["Jack Chan <[email protected]>"]
version = "0.1.0"
version = "0.1.1"

[deps]
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
Expand Down
6 changes: 3 additions & 3 deletions src/Jedis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module Jedis
export Client, Pipeline, RedisError, get_global_client, set_global_client, disconnect!, reconnect!,
add!, copy, wait_until_subscribed, wait_until_unsubscribed, wait_until_channel_unsubscribed,
wait_until_pattern_unsubscribed, execute, auth, select, ping, flushdb, flushall, quit,
set, get, del, setex, expire, ttl, multi, exec, multi_exec, pipeline, hset, hget, hgetall,
hmget, hdel, rpush, lpush, lpop, rpop, blpop, brpop, llen, lrange, publish, subscribe,
unsubscribe, psubscribe, punsubscribe
set, get, del, exists, hexists, keys, hkeys, setex, expire, ttl, multi, exec, multi_exec,
pipeline, hset, hget, hgetall, hmget, hdel, rpush, lpush, lpos, lrem, lpop, rpop, blpop,
brpop, llen, lrange, publish, subscribe, unsubscribe, psubscribe, punsubscribe

using Sockets

Expand Down
2 changes: 1 addition & 1 deletion src/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ end
Creates a new Client instance, copying the connection parameters of the input.
"""
function copy(client::Client)
function Base.copy(client::Client)
return Client(; host=client.host, port=client.port, database=client.database, password=client.password, username=client.username)
end

Expand Down
42 changes: 42 additions & 0 deletions src/commands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,34 @@ Delete a key.
"""
del(key, keys...; client=get_global_client()) = execute(["DEL", key, keys...], client)

"""
exists(key[, keys...])
Determine if a key exists.
"""
exists(key, keys...; client=get_global_client()) = execute(["EXISTS", key, keys...], client)

"""
hexists(key, field)
Determine if a hash field exists.
"""
hexists(key, field; client=get_global_client()) = execute(["HEXISTS", key, field], client)

"""
keys(pattern)
Find all keys matching the pattern.
"""
Base.keys(pattern; client=get_global_client()) = execute(["KEYS", pattern], client)

"""
hkeys(key)
Get all fields in a hash.
"""
hkeys(key; client=get_global_client()) = execute(["HKEYS", key], client)

"""
setex(key, seconds, value)
Expand Down Expand Up @@ -199,6 +227,20 @@ Append one or multiple elements to a list.
"""
rpush(key, element, elements...; client=get_global_client()) = execute(["RPUSH", key, element, elements...], client)

"""
lpos(key, element[, rank, num_matches, len])
Return the index of matching element on a list.
"""
lpos(key, element, rank="", num_matches="", len=""; client=get_global_client()) = execute(["LPOS", key, element, [isempty(rank) ? "" : "RANK", rank]..., [isempty(num_matches) ? "" : "COUNT", num_matches]..., [isempty(len) ? "" : "MAXLEN", len]...], client)

"""
lrem(key, count, element)
Remove elements from a list.
"""
lrem(key, count, element; client=get_global_client()) = execute(["LREM", key, count, element], client)

"""
lpop(key)
Expand Down
5 changes: 5 additions & 0 deletions src/protocol.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ Reads any bytes before the next CRLF (\r\n) in a TCPScoket, blocks if no bytes a
"""
function recv(s::TCPSocket)
line = readline(s)

if isempty(line)
return nothing
end

handler = RESPHandler[line[1]]
return handler(s, line[2:end])
end

2 comments on commit da30f8a

@captchanjack
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/38485

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.1 -m "<description of version>" da30f8afcf1174c6e36217df636e42f377930c1a
git push origin v0.1.1

Please sign in to comment.