Git Product home page Git Product logo

redis-lua's People

Contributors

agladysh avatar catwell avatar elcuervo avatar ignacio avatar jbochi avatar nrk avatar slact avatar spk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

redis-lua's Issues

Redis 2.0+ Support

It would be super nice if redis-lua development would keep up-to-date (more or less) with current Redis development.

Redis 2.0 is officially stable now and antirez strongly encourages the use of Redis 2.0 instead of 1.2.

Hash commands

For support hash command need another multibulk version:

if #args == 1 and type(args[1]) == 'table' then
    for k, v in pairs(args[1]) do

pls., add multibulk2 and change args[1] to args[2]

ImportError: BasePipeline with redis-3.2.1

With redis-3.2.1 (python library) I get the following error:

/usr/local/lib/python3.7/site-packages/redis_lua/script.py in <module>
     17 from functools import partial
     18 from redis.client import Script as RedisScript
---> 19 from redis.client import BasePipeline
     20
     21 from .exceptions import error_handler

ImportError: cannot import name 'BasePipeline' from 'redis.client' (/usr/local/lib/python3.7/site-packages/redis/client.py)

With redis-2.10.6 not.

command pipeline with dynamic parameters

the below code does not work with redis-lua because redis:pipeline() consider the variable "key" and "otherkey" as redis command instead of being part of the command parameter list.
Or am I missing something?
[quote]
local key="foo"
local otherkey="bar"
val1,val2 = lRedis:pipeline(function()
set_cardinality("k:" .. key .. ":list")
get("k:" .. otherkey .. ":val")
end)
lua: test.lua:x: unknown redis command: key
[/quote]

Connect ignores database number in path of URL

Given the code:

local client = redis.connect('redis://localhost:6379/9')

The expected result is that database #9 is either selected, or the connect should fail. This is standard in many other client libs for Redis.

This is similar to issue #44, where a password in the URL is also ignored.

test relies on removed CONFIG entry

list-max-ziplist-entries was removed (in 3.2-rc1 as far as I can tell). I cannot immediately figure out a different key that has been stable over a long time to replace it with. Alternatively we could make the test conditional on < versus > 3.2 and replace it with hash-max-ziplist-entries which exists at least in 3.2.5 and current unstable.

How to get return values via EVAL?

local REDIS = require 'redis'
local redis = REDIS.connect('127.0.0.1', 6379)
local v = redis:eval("local v = redis.call('get',KEYS[1]) return v",1,"v")
print(v)

v is 'nil' even though the command appears to be successful (no error thrown).

The same EVAL in redis-cli works ok....

127.0.0.1:6379[1]> set v value
OK
127.0.0.1:6379[1]> eval "local v = redis.call('get',KEYS[1]) return v" 1 "v"
"value"
127.0.0.1:6379[1]>

Am I misunderstanding the implementation of EVAL in your library? Is it even possible to get return values out of a script?

Best regards and thanks for a great library ... I'd just love to improve my work by using scripts as I'm reaching the limits of what I can do with transactions.

The lettercase of the package name and the file base name mismatch

The package name is "Redis" while the file name is "redis.lua", which breaks usage like below:

local Redis = require "redis"
local redis = Redis.connect(...)

We'll get the error message: "attempt to index local 'Redis' (a boolean value)".

Hopefully you can do me a favor by fixing this ;)

Thanks!
-agentzh

library is blocking main thread when connection drops

example:
I issue command: redis:ping(), connection drops, it takes around 10s for main thread to resume, are there any workarounds?

it would be nice to have it as non-blocking library, where you could issue
commands like that

local callback=function(event)
local response=event.response
if response=="PONG" then return "pong"
elseif response=="TIMEOUT" then --do time-out-case stuff here --
elseif response=="ERROR" then --do error-case stuff here --
end
end

redis:ping(callback)

How do I use a redis URI to connect

Hey guys thanks for all the good work. I am trying to connect to a Heroku Redis server using the provide URI but I am getting back an error. I am using the following:

redis.connect(redis://username:paswword@host:port)

But this just gives me back the following error:

lua: /usr/local/share/lua/5.2/redis.lua:380: redis error: NOAUTH Authentication required

Is it not possible to use the URI, or is there another way I should be trying to connect using the URI's provided data.

cluster support?

Are there any plans to add support for connecting to a redis cluster? (Establish connections to all servers and select server based on a key hash)

How to handle redis down

Hi,
When redis down, connect function will failed without giving any return value.
How to handle this situation?
Thanks

Can it hold connect pool with Redis?

I got a lot of Lua logic that need to write/read Redis in multiple thread(C call Lua). My original Redis-C client hold a connect pool with redis. Do I need the connect pool in redis-lua? or does the connect pool was required in redis-lua?

`nil` as key in `:set()` hangs the connection

Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> redis =require 'redis'
> r = redis.connect()
> =r:get('foo')
bar
> r:set(nil, 'bar')

it never returns. On the wire we see

*3
$3
SET
$3
bar

i.e. the key is simply skipped and Redis is waiting for the third argument.

Version is 2.0.4-1 from luarocks.

Support for Unix Sockets

I might have overlooked something but I think redis-lua doesn't support Unix Sockets. Do you think it would be possible to add support for them?

Support for luvit?

I'm wondering whether you have considered adding luvit support, now that a stable branch exists. Any thoughts?

Feature Request: Pub/Sub Support

Thanks for the great Lua library, we use it throughout our application.

One feature we'd love to see is pub/sub support. At present, we're sending out the same data N times, once for each worker. It would be great to move that to a pub/sub system in the future.

Thanks very much!

Cannot specify redis db index

I can only seem to connect to redis db 0.

I would like to connect to the redis db at index 15 at this uri redis://localhost:6379/15.

is this possible? if I was to open a PR to make this happen, where would changes need to be made?

the pipline of hmset

Does this pipeline provide command for hmset in order to improve performance of using hmset to store large amounts of data in lua?

how to maintain a long-time connection with Redis

I have implemented the Redis pool. But sometimes (maybe 1 hour) the connection within the pool will fail to execute commands(Redis is running, not down), I think the connection is closed(may be by server or client), is there any way to maintain a longtime(maybe forever) connection?

problem with lib socket in lua 5.1

redis-lua doesn't seem to be working with Lua 5.1.4, version that I'm using in my project.
when I try to connect, I get this error:

error loading module 'socket.core' from file '/usr/local/lib/lua/5.1/socket/core.so':
    dlopen(/usr/local/lib/lua/5.1/socket/core.so, 2): Symbol not found: _luaL_prepbuffsize
  Referenced from: /usr/local/lib/lua/5.1/socket/core.so
  Expected in: flat namespace
 in /usr/local/lib/lua/5.1/socket/core.so
stack traceback:
    [C]: ?
    [C]: in function 'require'
    /usr/local/share/lua/5.1/socket.lua:12: in main chunk
    [C]: in function 'require'
    /usr/local/share/lua/5.1/redis.lua:793: in function 'create_connection'
    /usr/local/share/lua/5.1/redis.lua:836: in function 'connect'
    stdin:1: in main chunk
    [C]: ?

Why client lost in Redis server?

I use redis_connect(ip, port) to connect the Redis server(long time connection), then it works well, but about 10 minutes later,the connection is closed(active or passive, I don't know)

false : lua_scripts/lib/redis.lua:264: connection error: closed

And all the successive command are failed. I have browsed the out put of CLIENT LIST, and not list my client's IP, why this happened?

hkeys return nothing

Hello.
Try to get some value from my db

print(client:select(0)) -- return true

value={}
value=client:hkeys("myhashtabe") -- like key field1 val1 field2 val2
for k,v in pairs(value) do
print(k.." "..v) -- return nothing
end

If I do this from redis-cli - everything works

redis_version:2.8.16

`nil` argument wrongly gets converted to empty string

From the protocol docs:

The client library API should not return an empty string, but a nil object, when the server replies with a Null Bulk String. For example a Ruby library should return 'nil' while a C library should return NULL (or set a special flag in the reply object), and so forth.

There is no language on nils in commands, and sending an actual nil makes Redis complain. This leads me to believe there is simply no valid situation in which you pass nil to a command. Because of that, I think the 'map to empty' fix for #29 is wrong.

attempt to index a boolean value

Exception in thread "main" com.naef.jnlua.LuaRuntimeException: D:\workspaces\luaWrokspace\test\src\redis.lua:793: attempt to index a boolean value
at com.naef.jnlua.LuaState.lua_pcall(Native Method)
at com.naef.jnlua.LuaState.call(LuaState.java:555)
at org.eclipse.ldt.support.lua51.internal.interpreter.JNLua51Launcher.run(JNLua51Launcher.java:128)
at org.eclipse.ldt.support.lua51.internal.interpreter.JNLua51DebugLauncher.main(JNLua51DebugLauncher.java:24)

how to set expire key:value for redis

i read the readme file but there is no docs for expire time of key
client:set('foo', 'bar')

how to set expire time for key "foo" about 3 minutes

thank you

Pub/Sub is not tolerant of timeouts

Since Lua uses cooperative multitasking and is single-threaded in most environments, libraries like LuaSocket depend heavily on timeouts and doing small batches of work at a time.

As a Redis subscriber, I have a similar requirement, and want to receive notifications within a function call that has a max-runtime duration budget. So I set a LuaSocket timeout:

client.network.socket:settimeout(0.25)
for message, abort in client:pubsub({subscribe=topics}) do
  -- Handle message and abort
  if (my elapsed time budget is up) then return end
end

But the client library is currently unforgiving of LuaSocket timeout errors and treats them like a hard failure:

lua: .///mytestfile.lua:46: /usr/local/share/lua/5.2/redis.lua:271: attempt to index local 'payload' (a nil value)

Lack of auto-reconnect

Lack of auto-reconnect causes major unreliability in production.

Why is that there is no re-connect like redis-rb?

One trivial solution is every time the client is called, to check for a live connection:

redis_client = Redis.connect('127.0.0.1', 6379)
function redis()
  local ok, err = pcall(redis_client:ping())
  if not ok then redis_client = Redis.connect('127.0.0.1', 6379); end

  return redis_client;
end

There are two problems with this approach:

  • Keep calling pcall(redis_client:ping()) is not efficient.
  • This does not work for the pubsub subscriber case.

The `hmget` command fails to retrieve a second argument if the first argument is nil

I know this is not an active project, but I thought I'd report the error anyway.

The hmget command fails to retrieve a second argument if the first argument is nil. For example:

redis = require('redis')

local client = redis.connect()
client:hset(1, 'exists', 'yay!')
local _, exists = client:hmget(1, 'notexists', 'exists')
print(exists) -- should print 'yay!', but doesn't

Large integers support

You use tostring to convert numbers to the Redis protocol format. This does not work correctly with integers above 10^14:

> =tostring(10^14-1)
99999999999999
> =tostring(10^14)
1e+14

It is possible to support numbers up to about 2^53, i.e. about 9*10^15, by using string.format instead:

> =string.format("%d",10^14)
100000000000000

Everything above 2^53-1 or below 2^53+1 is dangerous anyway, because you start seeing this:

> x = 2^53
> =(x == x+1)
true

Not sure how the client should handle this.

Question regarding redis-lua and luasocket

I've been actively using your redis-lua library in my company's project. It's cool and simple, thanks for sharing it. Primarily we use it in lua script which is a plugin for advanced MTA, we're using. The problem we're experiencing is quite a number of segfaults (perhaps in luasocket) while creating connections to redis. Have you experienced such a behaviour? Maybe you can point me to some known bugs of luascoket.

Another thing, I've made a minor patch to you library setting timeout(1) for tcp socket in connect method.

Any insight would be appreciated.

-Konstantin

Bug on command while there was `nil` parameter

I have wrapped the redis command as:

-- Lua 5.1.5
local function redis_cmd(cli, cmd, ...)
    local arg = {...}

    -- XXX: add here to avoid the first arg is `nil`,
    -- but do nothing with multi-cmd mode
    if #arg > 1 then    
        print(unpack(arg))
        assert(arg[1])
    end

    cmd = string.lower(cmd)
    local ok, res = nil, nil
    if #arg > 0 then
        ok, res = pcall(cli[cmd], cli, unpack(arg))
    else
        ok, res = pcall(cli[cmd], cli)
    end

    return ok, res
end

and I call redis_cmd like that:

local redis_cli = redis.connect('192.168.1.103', 6379)
local ok, res = redis_cmd(redis_cli, 'set', nil, 1)

while the command need 2 or more parameters(i.e., lrange, set, and so on), and the key is nil, the redis_cmd will hang there without any error message. And I added a if judgement(XXX:) on this situation, but while I call multi-set like this:

local ok, res = redis_cmd(redis_cli, 'mset', 'key', 2, nil, 1)

it still hang, I think my if statement do nothing with this situation. Is it a bug in redis.lua?


Add just for more information:
After testing in LuaJIT 2.0.1, the form:

local ok, res = redis_cmd(redis_cli, 'mset', 'key', 2, nil, 1)

will not hang and return true, but the form still hang.

local ok, res = redis_cmd(redis_cli, 'set', nil, 1)

Git update hist:

    commit 61e77607a39321017a7399be644ab7d33ce5c707
    Author: Pierre Chapuis <[email protected]>
    Date:   Mon Aug 19 16:25:51 2013 +0200

        Return score as a number when parsing response from ZINCRBY.

Return value of EXISTS is inconsistent with core redis

This library, will return true or false for all calls to EXISTS. However, this is not consistent with the return value for core redis. According to the documentation:

Return value

Integer reply, specifically:

  • 1 if the key exists.
  • 0 if the key does not exist.

Since Redis 3.0.3 the command accepts a variable number of keys and the return value is generalized:

  • The number of keys existing among the ones specified as arguments. Keys mentioned multiple times and existing are counted multiple times.

When passing multiple keys, there is no way to determine how many of the keys exist.

Docs clarification request

Please include somewhere in documentation answers on these "Frequently asked" questions (change answers if I did not guess right):

Q: Does redis-lua attempt to reestablish connection if it is lost?
A: No

Q: Is transaction() inside pipeline() supported?
A: No

Q: Is it possible to use return nil, error_message strategy instead of throwing error() on every error?
A: No.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.