Skip to content

Latest commit

 

History

History
474 lines (268 loc) · 7.76 KB

README.md

File metadata and controls

474 lines (268 loc) · 7.76 KB

mruby-redis Build Status

Hiredis binding for mruby. Hiredis is a minimalistic C client library for the Redis database. Redis is an open source, BSD-licensed, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets. Plese visit redis' official website for more details about Redis.

Running Redis might be impossible for memory/CPU-constrained environments, so we can recommend mruby-vedis. vedis is an embeddable datastore distributed as a C library. It supports over 70 commands similar to Redis, but runs in memory (hence doesn't require a networking layer). Please visit vedis' website for more details.

INSTALLATION

Using mrbgems

Add conf.gem line to build_config.rb:

MRuby::Build.new do |conf|

    # ... (snip) ...

    conf.gem :git => 'https://github.com/matsumoto-r/mruby-redis.git'
end

USAGE

Connecting to a Redis server

client = Redis.new "127.0.0.1", 6379, 2 # Connect to the server
client.host                             # => "127.0.0.1"
client.port                             # => 6379
client.select 0                         # Select the database
client.auth "secret"                    # Required if Redis is password-protected
client.enable_keepalive                 # Turn on TCP keepalive if needed
client.keepalive                        # => :on

Commands

Redis#auth doc

client.auth "secret"

Redis#asking

client.asking

Redis#[]=

TBD

Redis#[]

client["key"]

Redis#bulk_reply

TBD

Redis#close

TBD

Redis#cluster doc

client.cluster "info"
client.cluster "nodes"
client.cluster "slots"

Redis#decr doc

client.decr "key"

Redis#decrby doc

TBD

Redis#del doc

client.del "key"

Redis#discard doc

# discard the transaction
client.discard

Redis#exec doc

# execute the transaction
client.exec

Redis#exists? doc

client.exists?("key")

Redis#expire doc

TBD

Redis#flushall doc

client.flushall

Redis#flushdb doc

client.flushdb

Redis#get doc

client.get "key"

Redis#hdel doc

client.hdel "myhash", "field1"

Redis#hexists? doc

client.hexists? "myhash", "field1"

Redis#hget doc

client.hget "myhash", "field1"

Redis#hgetall doc

TBD

Redis#hkeys doc

TBD

Redis#hmset doc

client.hmset "myhash", "field1", "a", "field2", "b"

Redis#hmget doc

client.hmget "myhash", "field1", "field2"

Redis#hvals doc

client.hvals "myhash"

Redis#hset doc

client.hset "myhash", "field1", "a"

Redis#hsetnx doc

client.hsetnx "myhash", "field1", "a"

Redis#hincrby doc

client.hincrby "myhash", "field", 1

Redis#incr doc

client.incr "key"

Redis#incrby doc

TBD

Redis#keys doc

TBD

Redis#lindex doc

TBD

Redis#llen doc

TBD

Redis#lpop doc

TBD

Redis#lpush doc

TBD

Redis#lrange doc

client.lrange "logs", 0, -1

Redis#ltrim doc

client.ltrim "logs", 1, -1

Redis#mget doc

client.mget "key1", "key2"

Redis#mset doc

client.mset "key1", "value1", "key2", "value2"

Redis#multi doc

# start new transaction. Its finished by exec or discard
client.multi

Redis#ping doc

pong = client.ping

Redis#publish doc

number_of_subscribed_clients = client.publish "queue", "some value"

Redis#pfadd doc

number_of_internal_registers_altered = client.pfadd "hyperloglog_structure", "some value"

Redis#pfcount doc

approximated_number_of_unique_elements = client.pfcount "hyperloglog_structure"

Redis#pfmerge doc

client.pfmerge "hll3", "hll1", "hll2"

Redis#queue doc

TBD

Redis#randomkey doc

TBD

Redis#reply doc

TBD

Redis#rpop doc

TBD

Redis#rpush doc

TBD

Redis#sadd doc

TBD

Redis#scard doc

TBD

Redis#set doc

client.set key, "200"

Redis#setnx doc

client.setnx key, "foo" # => true
client.setnx key, "bar" # => false
client.get key          # => "foo"

Redis#sismember doc

TBD

Redis#smembers doc

TBD

Redis#spop doc

TBD

Redis#srem doc

client.srem "set", "fuge", "hoga"

Redis#ttl doc

TBD

Redis#unwatch doc

client.unwatch

Redis#watch doc

# watch key(s) for a transaction
client.watch "key1", "key2"

Redis#zadd doc

client.zadd "hs", 80, "a"

Redis#zcard doc

TBD

Redis#zrange doc

client.zrange "hs", 0, -1

Redis#zrank doc

client.zrank "hs", "a"

Redis#zrevrange doc

client.zrevrange "hs", 0, -1

Redis#zrevrank doc

client.zrevrank "hs", "a"

Redis#zscore doc

client.zscore "hs", "a"

See example/redis.rb for more details.

LICENSE

MIT License - Copyright (c) mod_mruby developers 2012