Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7511147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:27:30+00:00 2026-05-29T23:27:30+00:00

Redis (a key-value store) supports lua scripts – it executes the script on the

  • 0

Redis (a key-value store) supports lua scripts – it executes the script on the server. I am interacting with Redis using a java client. I am passing a byte array to lua and in lua, I would have to convert that to a int or string.

The following is the java code snippet

byte[] exclScore = ByteBuffer.allocate(8).putDouble(1.5).array();
args.add(exclScore);

args is an ArrayList of type byte[]

Following is the lua script that I tried

byteScore = table.remove(ARGV)
size = string.len(byteScore)
x = string.sub(byteScore,1,1)
local output = 0
for i = 1,size do
  bit = tonumber(string.sub(byteScore,i,1))
  val2 = bit * (2 ^ i)
  output = output + val2
end
return output

ARGV is the table which receives all the arguments sent by the java client and the score is the last entry. I checked the type(byteScore) and it turned out to be string. tonumber() returns a nil (which is the error I get, since I multiply it by 2)

Is there anyway in which we can convert this byte array into double or string representation of that double (1.5) in lua? Note that, we cannot use any external lua libraries inside redis scripts.

Any help is appreciated. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:27:31+00:00Added an answer on May 29, 2026 at 11:27 pm

    Lua is not a low-level language. It does not know how to handle byte arrays.

    In theory, you could write a binary-to-double decoder (though that would be hard since Lua 5.1 doesn’t have any bit manipulation stuff). But your time would be better spent trying to pass Lua data that is in a form Lua understands. Lua can convert strings to numbers, so you can pass Lua a string representation of that number.

    Sanitize your data outside of Lua.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am storing key-value pairs in a Redis database via the Redis-py client. All
I am trying to do data replication using redis server and jedis client. What
I have been reading that lots of people use Redis or another key-value store/NoSQL
I am interested to know the performance impacts of using MySQL as a key-value
I'm pulling data from Redis using Aleph: (apply hash-map @(@r [:hgetall (key-medication id)])) The
Problem I need a key-value store that can store values of the following form:
Is it possible to have list of key/value pairs within redis? or possibly a
Leveldb seems to be a new interesting persistent key value store from Google. How
Redis persists data and works on key value stores with a great feature called
I'm using redis to store hashes with ~100k records per hash. I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.