Skip to content

JoverZhang/redis-decimal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Docker Cloud Build Status GitHub

RedisDecimal: Floating-Point Number based on 10 for Redis

Quick Start Guide

1. Building and Loading

To build RedisDecimal, ensure you have cmake and make, and afterwards run the following command.

cmake .
make

If the build is successful, you'll have a shared library called libdecimal.so in the lib directory.

To load the library, pass its path to the --loadmodule directive when starting redis-server:

$ redis-server --loadmodule ./lib/libdecimal.so

2. Use RedisDecimal with redis-cli

# redis-cli
127.0.0.1:6379>

And run the following command:

127.0.0.1:6379> DECIMAL ADD 10 20
"30.000000"
127.0.0.1:6379> DECIMAL SUB 10 20
"-10.000000"
127.0.0.1:6379> DECIMAL MUL 10 20
"200.000000"
127.0.0.1:6379> DECIMAL DIV 10 20
"0.500000"

And specify the precision:

127.0.0.1:6379> DECIMAL ADD 10 20 2
"30.00"
127.0.0.1:6379> DECIMAL SUB 10 20 2
"-10.00"
127.0.0.1:6379> DECIMAL MUL 10 20 2
"200.00"
127.0.0.1:6379> DECIMAL DIV 10 20 2
"0.50"

And round policy for division:

127.0.0.1:6379> DECIMAL DIV 10 3 2
"3.33"
127.0.0.1:6379> DECIMAL DIV 20 3 2
"6.66"

Extensions

Test for RedisDecimal

To build RedisDecimal, and run the unit testing.

cmake .
make
./.tests/tests