在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:JuliaDatabases/Redis.jl开源软件地址:https://github.com/JuliaDatabases/Redis.jl开源编程语言:Julia 100.0%开源软件介绍:Redis.jlRedis.jl is a fully-featured Redis client for the Julia programming language. The implementation is an attempt at an easy to understand, minimalistic API that mirrors actual Redis commands as closely as possible. BasicsThe Redis.jl API resides in the using Redis The main entrypoint into the API is the conn = RedisConnection() # host=127.0.0.1, port=6379, db=0, no password
# conn = RedisConnection(host="192.168.0.1", port=6380, db=15, password="supersecure")
set(conn, "foo", "bar")
get(conn, "foo") # Returns "bar" Anywhere that set(conn, :keyword, :value)
get(conn, :keyword) # Returns "value" For any Redis command
When the user is finished interacting with Redis, the connection should be destroyed to prevent resource leaks: disconnect(conn) The Commands with optionsSome Redis commands have a more complex syntax that allows for options to be passed to the command. Redis.jl supports these options through the use of a final varargs parameter to those functions (for example, scan(conn, 0, "match", "foo*")
scan(conn, 2, :count, 2) If users are interested, the API could be improved to provide custom functions for these complex commands. An exception to this option syntax are the functions PipeliningRedis.jl supports pipelining through the pipeline = open_pipeline(conn)
set(pipeline, "somekey", "somevalue") Commands will be sent directly to the Redis server without waiting for a response. Responses can be read at any time in the future using the responses = read_pipeline(pipeline) # responses == ["OK"] Important: The current TransactionsRedis.jl supports MULTI/EXEC transactions through two methods: using a Transactions using the RedisConnectionIf the user wants to build a transaction a single time and execute it on the server, the simplest way to do so is to send the commands as you would at the Redis cli. multi(conn)
set(conn, "foo", "bar")
get(conn, "foo") # Returns "QUEUED"
exec(conn) # Returns ["OK", "bar"]
get(conn, "foo") # Returns "bar" It is important to note that after the final call to Transactions using the TransactionConnectionIf the user is planning on using multiple transactions on the same connection, it may make sense for the user to keep a separate connection for transactional use. The trans = open_transaction(conn)
set(trans, "foo", "bar")
get(trans, "foo") # Returns "QUEUED"
exec(trans) # Returns ["OK", "bar"]
get(trans, "foo") # Returns "QUEUED"
multi(trans) # Throws a ServerException Notice the subtle difference from the previous example; after calling Pub/subRedis.jl provides full support for Redis pub/sub. Publishing is accomplished by using the command as normal: publish(conn, "channel", "hello, world!") Subscriptions are handled using the x = Any[]
f(y) = push!(x, y)
sub = open_subscription(conn)
subscribe(sub, "baz", f)
publish(conn, "baz", "foobar")
x # Returns ["foobar"] Multiple channels can be subscribed together by providing a x = Any[]
f(y::SubscriptionMessage) = push!(x, y)
sub = open_subscription(conn)
d = Dict{String, Function}({"baz" => f, "bar" => println})
subscribe(sub, d)
publish(conn, "baz", "foobar")
x # Returns ["foobar"]
publish(conn, "bar", "anything") # "anything" written to stdout Pattern subscription works in the same way through use of the Note that the event loop spawned with Threads.@spawn currently runs until the Subscription error handlingWhen a SentinelRedis.jl also provides functionality for interacting with Redis Sentinel instances through the sentinel = SentinelConnection() # Constructor has the same options as RedisConnection
sentinel_masters(sentinel) # Returns an Array{Dict{String, String}} of master info
NotesActual API usage can be found in test/redis_tests.jl. Redis Commands returning 'NIL'The following methods return a Strings
Lists
Sets
Sorted Sets
Hashes
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论