Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
175 commits
Select commit Hold shift + click to select a range
2d31ac0
[ch66649] initial copy from moonshot (and minor template fill in)
hroederld Feb 20, 2020
b41bd5a
[ch66755] Add variationDetail variation handlers (#2)
hroederld Feb 28, 2020
4a001eb
[ch68367] prefix functions with local
hroederld Mar 9, 2020
c66ed75
[ch68610] Basic generated doc (#4)
hroederld Mar 10, 2020
e69359c
[ch70062] rename to launchdarkly-server-sdk.lua
hroederld Mar 19, 2020
24b9487
[ch70700] prepare 1.0.0-beta.1
hroederld Mar 24, 2020
6ed903a
Update CONTRIBUTING.md (#8)
bwoskow-ld Mar 24, 2020
17a35ef
Update README.md (#7)
bwoskow-ld Mar 24, 2020
f2bb53c
Merge github.com:launchdarkly/lua-server-sdk
hroederld Mar 25, 2020
791dd2e
remove circle badge (#9)
hroederld Mar 25, 2020
0e9db0d
Merge github.com:launchdarkly/lua-server-sdk
hroederld Mar 25, 2020
b1f585c
[ch70699] releaser support (#11)
hroederld Apr 1, 2020
3ab1ee2
[ch73979] document version constraints (#12)
hroederld Apr 17, 2020
f2ed7f1
[ch76282] add wrapper meta config (#13)
hroederld May 12, 2020
57517c1
prepare 1.0.0-beta.2 (content approved in previous failed release PR)
hroederld May 12, 2020
153dd3f
Merge github.com:launchdarkly/lua-server-sdk
hroederld May 12, 2020
bf8fd31
[ch80640] logging handler (#14)
hroederld Jun 23, 2020
77e52a1
[ch80816] basic unit tests (#15)
hroederld Jun 23, 2020
89806d4
[ch80958] remove beta warning
hroederld Jun 24, 2020
6b6a4c5
fix timeout (#17)
hroederld Jun 25, 2020
39da875
[ch70870] redis module (#18)
hroederld Jul 7, 2020
cbc133f
[ch70870] ldoc releaser redis (#19)
hroederld Jul 9, 2020
ad96c4e
[ch82399] document c server-side sdk version requirement (#20)
hroederld Jul 9, 2020
5eb0fdc
[ch82565] collect between tests (#21)
hroederld Jul 10, 2020
c5ab6f2
[ch82639] rewrite for lua 5.1 5.2 5.3 (#22)
hroederld Jul 20, 2020
8a76638
[ch83425] prepare beta 3 (#23)
hroederld Jul 20, 2020
d5ac988
merge public
hroederld Jul 20, 2020
368253a
remove beta warning (#24)
hroederld Jul 27, 2020
fd7e7e3
set source in rockspec (#25)
hroederld Jul 27, 2020
7d20fcc
merge from public after release
LaunchDarklyCI Jul 27, 2020
772a103
[ch87476] Always use custom `luaL_setfuncs` (#26)
hroederld Aug 28, 2020
9b8af72
merge from public after release
LaunchDarklyCI Aug 28, 2020
d248b20
adding circleci badge and issue/PR templates (#27)
bwoskow-ld Nov 20, 2020
6243cfb
[ch99754] add alias method (#28)
hroederld Feb 3, 2021
4b43131
Removed the guides link
bwoskow-ld Feb 3, 2021
fffb6ff
merge from public after release
LaunchDarklyCI Feb 4, 2021
355062b
Merge github.com:launchdarkly/lua-server-sdk
hroederld Mar 20, 2021
9006383
Updates docs URLs (#29)
ember-stevens Nov 17, 2021
d03089f
SC-127348: Add LuaLDVersion function to return current SDK version (#30)
cwaldren-ld Nov 19, 2021
78eadf3
Remove references to unneeded lua-cjson package (#31)
cwaldren-ld Jan 27, 2022
d5b97c9
Fix memory leak in AllFlags (#32)
cwaldren-ld Feb 4, 2022
619604a
Update to releaser v2 config (#33)
cwaldren-ld Feb 5, 2022
bc02168
Add .gitignore
cwaldren-ld Feb 5, 2022
9a04888
merge from public after release
Feb 8, 2022
46a456e
Fix documentation generation for Releaser v2 config (#34)
cwaldren-ld Feb 8, 2022
34a9eef
Fix Releaser v2 documentation generation & optimize build (#35)
cwaldren-ld Feb 8, 2022
8cf7d39
merge from public after release
Feb 8, 2022
b50485b
Remove tmp dir (#36)
cwaldren-ld Feb 8, 2022
1904c53
Remove tmp dir (continued)
cwaldren-ld Feb 8, 2022
2648158
merge from public after release
Feb 8, 2022
8dcaac6
Update master->main in pull request template (#37)
cwaldren-ld May 4, 2022
f823656
Fix CircleCI build, update to matrix builds for Ubuntu 18.04 and 20.0…
cwaldren-ld Aug 31, 2022
55c3083
Updates daily flag count
ember-stevens Jun 8, 2023
cf8a7a4
[sc-205159] Update README with current number of flags served (#39)
ember-stevens Jun 8, 2023
94a8489
Add file CODEOWNERS
ld-repository-standards[bot] Jun 26, 2023
2d67f82
Add file CODEOWNERS (#40)
kparkinson-ld Jun 26, 2023
39b8a47
chore: update CODEOWNERS (#41)
cwaldren-ld Oct 5, 2023
c459931
rename .ldrelease dir to scripts
cwaldren-ld Dec 11, 2023
7282b70
add build docs action
cwaldren-ld Dec 11, 2023
a57331a
ci: add github action to replace CircleCI
cwaldren-ld Dec 11, 2023
eb986de
force lua 5.3 temporarily
cwaldren-ld Dec 11, 2023
42f079d
rename matrix version
cwaldren-ld Dec 11, 2023
b7b7057
add libcurl
cwaldren-ld Dec 11, 2023
5f330b5
add redis
cwaldren-ld Dec 11, 2023
d07c4e8
Add luarocks
cwaldren-ld Dec 11, 2023
30e5777
fix uses syntax
cwaldren-ld Dec 11, 2023
0c47b66
remove sudo
cwaldren-ld Dec 11, 2023
544b5a1
run unit tests
cwaldren-ld Dec 11, 2023
020766b
remove luaL_register call
cwaldren-ld Dec 11, 2023
78bf8c2
use luajit test
cwaldren-ld Dec 11, 2023
45962d4
add publish docs action
cwaldren-ld Dec 11, 2023
2ce3c0a
Revert "remove luaL_register call"
cwaldren-ld Dec 11, 2023
027be6d
add manual publish docs
cwaldren-ld Dec 11, 2023
48921ae
add stale workflow
cwaldren-ld Dec 11, 2023
e7b8bfe
add release please config
cwaldren-ld Dec 11, 2023
e8d9392
update copyright on license
cwaldren-ld Dec 11, 2023
efd43ec
update README badges
cwaldren-ld Dec 11, 2023
4d97538
update extra-files with verison
cwaldren-ld Dec 11, 2023
e5f3856
use public repo links in README
cwaldren-ld Dec 11, 2023
12e46da
Update .github/actions/ci/action.yml
cwaldren-ld Dec 12, 2023
baec337
revert copyright change
cwaldren-ld Dec 12, 2023
afbece9
Use SHAs instead of version tags
cwaldren-ld Dec 12, 2023
abc7f65
fetch cpp server sdk v3
cwaldren-ld Dec 12, 2023
e1c5400
updating bindings
cwaldren-ld Dec 13, 2023
daad0d6
updating to use new API, many compiler errors
cwaldren-ld Dec 13, 2023
f6c41b1
launchdarkly-server-sdk.c compiles
cwaldren-ld Dec 13, 2023
9942fef
update unit tests
cwaldren-ld Dec 13, 2023
0f1a6f8
add logging callbacks
cwaldren-ld Dec 14, 2023
bf2ffba
update redis binding
cwaldren-ld Dec 19, 2023
5766002
Adds singleton guidance to Lua docs
scribblingfox Feb 15, 2022
ee9fcf4
Add file SECURITY.md
ld-repository-standards[bot] Jun 26, 2023
4bebbdf
Add file SECURITY.md
ld-repository-standards[bot] Jul 7, 2023
1722755
ci: replace Releaser/circleCI with release-please/Github Actions (#29)
cwaldren-ld Dec 18, 2023
ca21a6c
install boost on runner
cwaldren-ld Dec 18, 2023
aa43136
fix bindings
cwaldren-ld Dec 19, 2023
39d16ef
try using prebuilt artifacts
cwaldren-ld Dec 18, 2023
a7ed3b6
add install dir
cwaldren-ld Dec 18, 2023
9aadad4
add release subdir
cwaldren-ld Dec 18, 2023
0f5b408
debug downloaded files
cwaldren-ld Dec 19, 2023
d595249
update redis dir
cwaldren-ld Dec 19, 2023
638c314
use prerelease tags
cwaldren-ld Dec 19, 2023
35f0505
update prebuilt artifact tag
cwaldren-ld Dec 19, 2023
f7c9413
run CI
cwaldren-ld Dec 19, 2023
2de15df
fix compilation
cwaldren-ld Dec 19, 2023
22a4209
add boost to dependencies
cwaldren-ld Dec 19, 2023
6e92dfc
try removing BOOST_LIBDIR frm libdirs
cwaldren-ld Dec 19, 2023
9005ed8
Try adding ld-cpp-server to external dependencies
cwaldren-ld Dec 19, 2023
6a107e3
add redis test
cwaldren-ld Dec 19, 2023
9e56561
update redis test
cwaldren-ld Dec 19, 2023
b75c2f7
add HIREDIS path
cwaldren-ld Dec 19, 2023
da4567a
try using modules.libraries for hiredis
cwaldren-ld Dec 19, 2023
e58ef90
attempt to fix build
cwaldren-ld Dec 20, 2023
99c1ea4
fix invocation of makeRedisSource
cwaldren-ld Dec 20, 2023
b873c38
using a table driven approach for arg parsing
cwaldren-ld Dec 20, 2023
75be09e
fix table-driven parser
cwaldren-ld Dec 20, 2023
9efa84f
fix bug in parsers
cwaldren-ld Dec 20, 2023
63552f4
cleanup
cwaldren-ld Dec 20, 2023
59eac4a
update gitignore
cwaldren-ld Dec 20, 2023
1c86f20
add privateAttributes support
cwaldren-ld Dec 20, 2023
0a2cb20
will it segfault?
cwaldren-ld Dec 20, 2023
e5eb9f4
try again
cwaldren-ld Dec 20, 2023
8b6a610
more logging
cwaldren-ld Dec 20, 2023
8a9f3cc
fewer unit tests
cwaldren-ld Dec 20, 2023
e7a83d7
less config
cwaldren-ld Dec 20, 2023
288201f
theory: table parsing casues segfault
cwaldren-ld Dec 20, 2023
b27effb
try removing a lua pop inside the table traverse
cwaldren-ld Dec 20, 2023
83493fa
test
cwaldren-ld Dec 21, 2023
6aaecdb
add serviceendpoints
cwaldren-ld Dec 21, 2023
d7a2997
add datasystem
cwaldren-ld Dec 21, 2023
9ce31bc
parse backgroundSync
cwaldren-ld Dec 21, 2023
c1e45d9
add streaming
cwaldren-ld Dec 21, 2023
a5dcff2
add initialReconnect
cwaldren-ld Dec 21, 2023
af9c958
grow stack
cwaldren-ld Dec 21, 2023
8ba6b4c
theory: passes
cwaldren-ld Dec 21, 2023
d4870de
theory: still broken
cwaldren-ld Dec 21, 2023
9871228
try changing function signature
cwaldren-ld Dec 21, 2023
bff148b
theory: passes
cwaldren-ld Dec 21, 2023
44fb819
theory: segfault
cwaldren-ld Dec 21, 2023
0845132
maybeit's just numbers that are broken
cwaldren-ld Dec 21, 2023
bea0aea
go back to number
cwaldren-ld Dec 21, 2023
be508b9
theory: crash
cwaldren-ld Dec 21, 2023
5022a3f
implement sub builders
cwaldren-ld Dec 21, 2023
2641b5c
cleanup
cwaldren-ld Dec 21, 2023
7392b54
fix segfault
cwaldren-ld Dec 21, 2023
56d8432
update redis tests
cwaldren-ld Dec 21, 2023
ba01ab0
more polish
cwaldren-ld Dec 21, 2023
ff40734
test invalid redis argument
cwaldren-ld Dec 21, 2023
4c10ba2
re-enable more config options in test
cwaldren-ld Dec 21, 2023
6185b59
add init timeout
cwaldren-ld Dec 21, 2023
9768f99
update docs
cwaldren-ld Dec 21, 2023
98eaffa
Merge branch 'main' into cw/sc-227439/updated-c-bindings
cwaldren-ld Dec 21, 2023
e7d8171
update docs
cwaldren-ld Dec 21, 2023
5b7a0e4
bump C++ release version
cwaldren-ld Dec 21, 2023
2e6be35
add contextKeysCacheCapacity
cwaldren-ld Dec 21, 2023
280d6c3
add some unit tests
cwaldren-ld Dec 21, 2023
909b4b9
update tests
cwaldren-ld Dec 21, 2023
50602c0
begin implementing context parsing logic
cwaldren-ld Dec 21, 2023
5acfeaa
update tests
cwaldren-ld Dec 22, 2023
7c779c1
more docs
cwaldren-ld Dec 22, 2023
246d188
add context:canonicalKey
cwaldren-ld Dec 22, 2023
38aa381
add privateAttributes binding
cwaldren-ld Dec 22, 2023
7616dda
add equivalent context tests for variations
cwaldren-ld Dec 22, 2023
4dcee37
add anonymous and name support
cwaldren-ld Dec 22, 2023
8e41672
implement allFlags
cwaldren-ld Dec 26, 2023
e11d160
bump redis source version
cwaldren-ld Dec 26, 2023
c74c247
update min version in readme
cwaldren-ld Dec 27, 2023
96376c1
add log level config
cwaldren-ld Dec 27, 2023
b214285
add custom logging support
cwaldren-ld Dec 27, 2023
3c5ac36
try removing boost depend from rockspec
cwaldren-ld Dec 27, 2023
501b98b
update docs
cwaldren-ld Dec 27, 2023
a80171b
Update scripts/get-cpp-sdk-locally.sh
cwaldren-ld Dec 28, 2023
da43dd4
remove type-specific checkers and replace with one generic routine
cwaldren-ld Dec 28, 2023
f0eb8be
indent markdown
cwaldren-ld Dec 28, 2023
e94b610
fix docs
cwaldren-ld Dec 28, 2023
99c8391
remove some todos
cwaldren-ld Dec 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 52 additions & 17 deletions .github/actions/ci/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,70 @@ inputs:
runs:
using: composite
steps:
- uses: leafo/gh-actions-lua@35bcb06abec04ec87df82e08caa84d545348536e
- name: Install Lua
uses: leafo/gh-actions-lua@35bcb06abec04ec87df82e08caa84d545348536e
with:
luaVersion: ${{ inputs.lua-version }}
- uses: leafo/gh-actions-luarocks@e65774a6386cb4f24e293dca7fc4ff89165b64c5
- name: Install C Server-side SDK Dependencies
shell: bash
run: |
sudo apt-get update -y
sudo apt-get install -y libcurl4-openssl-dev
sudo apt-get install -y libhiredis-dev

- name: Setup C Server-side SDK
shell: bash
run: ./scripts/build-c-server.sh
- name: Install LuaRocks
uses: leafo/gh-actions-luarocks@e65774a6386cb4f24e293dca7fc4ff89165b64c5
- name: Install Boost
id: install-boost
uses: MarkusJx/install-boost@v2.4.4
with:
boost_version: 1.81.0
platform_version: "22.04"
- name: Install CPP SDK
uses: ./.github/actions/install-cpp-sdk-redis
with:
version: launchdarkly-cpp-server-redis-source-v2.1.0
path: cpp-sdk

- name: Build Lua Server-side SDK
shell: bash
run: luarocks make launchdarkly-server-sdk-1.0-0.rockspec
run: |
luarocks make launchdarkly-server-sdk-1.0-0.rockspec \
LD_DIR=./cpp-sdk/build-dynamic/release

- name: Build Lua Server-side SDK with Redis
shell: bash
run: luarocks make launchdarkly-server-sdk-redis-1.0-0.rockspec
run: |
luarocks make launchdarkly-server-sdk-redis-1.0-0.rockspec \
LDREDIS_DIR=./cpp-sdk/build-dynamic/release

- name: Run tests
- name: Run Lua Server-side SDK Tests
shell: bash
if: ${{ ! contains(inputs.lua-version, 'jit') }}
run: lua test.lua
run: luarocks test launchdarkly-server-sdk-1.0-0.rockspec
env:
# Needed because boost isn't installed in default system paths, which is
# what the C++ Server-side SDK shared object expects.
LD_LIBRARY_PATH: ${{ steps.install-boost.outputs.BOOST_ROOT }}/lib

- name: Run tests (JIT)
- name: Run Lua Server-side SDK Tests (JIT)
shell: bash
if: ${{ contains(inputs.lua-version, 'jit') }}
run: luajit test.lua
env:
# Needed because boost isn't installed in default system paths, which is
# what the C++ Server-side SDK shared object expects.
LD_LIBRARY_PATH: ${{ steps.install-boost.outputs.BOOST_ROOT }}/lib

- name: Run Lua Server-side SDK with Redis Tests
shell: bash
if: ${{ ! contains(inputs.lua-version, 'jit') }}
run: luarocks test launchdarkly-server-sdk-redis-1.0-0.rockspec
env:
# Needed because boost isn't installed in default system paths, which is
# what the C++ Server-side SDK shared object expects. Same for hiredis which is bundled
# with the SDK release.
LD_LIBRARY_PATH: ${{ steps.install-boost.outputs.BOOST_ROOT }}/lib;./cpp-sdk/build-dynamic/release/lib

- name: Run Lua Server-side SDK with Redis Tests (JIT)
shell: bash
if: ${{ contains(inputs.lua-version, 'jit') }}
run: luajit test-redis.lua
env:
# Needed because boost isn't installed in default system paths, which is
# what the C++ Server-side SDK shared object expects. Same for hiredis which is bundled
# with the SDK release.
LD_LIBRARY_PATH: ${{ steps.install-boost.outputs.BOOST_ROOT }}/lib;./cpp-sdk/build-dynamic/release/lib
27 changes: 27 additions & 0 deletions .github/actions/install-cpp-sdk-redis/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This custom action is used because the MarkusJx/install-boost does
# not include all built libraries for mac or windows builds.
# Specifically, it was missing boost_json.
name: Install C++ Server-side SDK with Redis Source
description: 'Obtain prebuilt libraries for the Launchdarkly C++ server-side SDK with Redis Source.'
inputs:
version:
required: true
description: "Version of the C++ SDK with Redis Source."
default: "v1.0.1"
path:
description: "Where to download the SDK."
default: "cpp-sdk"

runs:
using: composite
steps:
- name: Download C++ Server-side SDK with Redis Source
uses: robinraju/release-downloader@efa4cd07bd0195e6cc65e9e30c251b49ce4d3e51
id: download-cpp-sdk
with:
repository: "launchdarkly/cpp-sdks"
latest: false
tag: ${{ inputs.version }}
fileName: linux-gcc-x64-dynamic.zip
out-file-path: ${{ inputs.path }}
extract: true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.idea
cpp-sdks
*.o
*.so
45 changes: 42 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,57 @@ LaunchDarkly overview
Supported Lua versions
-----------

This version of the LaunchDarkly SDK is compatible with the Lua 5.1-5.3 interpreter, and LuaJIT.
This version of the LaunchDarkly SDK is known to be compatible with the Lua 5.1-5.3 interpreter, and LuaJIT 2.0.5.

Supported C server-side SDK versions
Supported C++ server-side SDK versions
-----------

This version of the Lua server-side SDK depends on the C server-side SDK. The minimum required version is `2.1.0`, and under `3.0.0`.
This version of the Lua server-side SDK depends on the LaunchDarkly C++ Server-side SDK.

If Redis support is desired, then it optionally depends on the C++ server-side SDK's Redis Source.

| Dependency | Minimum Version | Notes |
|--------------------------------|------------------------------------------------------------------------------------------------------------|--------------------------------------------|
| C++ Server-Side SDK | [3.3.0](https://github.com/launchdarkly/cpp-sdks/releases/tag/launchdarkly-cpp-server-v3.3.0) | Required dependency. |
| C++ Server-Side SDK with Redis | [2.1.0](https://github.com/launchdarkly/cpp-sdks/releases/tag/launchdarkly-cpp-server-redis-source-v2.1.0) | Optional, if using Redis as a data source. |


3rd Party Dependencies
------------
Depending on how the C++ server-side SDK was built, the Lua SDK may require additional runtime dependencies to work properly.


| Dependency | If C++ SDK compiled with.. | Notes |
|------------|------------------------------|------------------------------------------------------------------------|
| OpenSSL | `LD_DYNAMIC_LINK_OPENSSL=ON` | If linking OpenSSL dynamically, it must be present on target system. |
| Boost | `LD_DYNAMIC_LINK_BOOST=ON` | If linking Boost dynamically, it must be present on the target system. |

_Note: The CI process builds against the C++ Server-side SDK's Linux shared libraries, which were compiled with `LD_DYNAMIC_LINK_BOOST=ON` so
Boost is fetched as part of the build process._


Getting started
-----------

Refer to the [SDK documentation](https://docs.launchdarkly.com/sdk/server-side/lua#getting-started) for instructions on getting started with using the SDK.

To compile the LuaRock modules:
1. Install [LuaRocks](https://github.com/luarocks/luarocks/wiki/Download)
2. Build the [C++ Server-side SDK](https://github.com/launchdarkly/cpp-sdks) from source using CMake, or obtain pre-built artifacts from the [releases page](https://github.com/launchdarkly/cpp-sdks/releases?q=%22launchdarkly-cpp-server%22)
3. Run `luarocks make`:
```bash
# Base SDK
luarocks make launchdarkly-server-sdk-1.0-0.rockspec \
LD_DIR=./path-to-installed-cpp-sdk

# SDK with Redis
luarocks make launchdarkly-server-sdk-redis-1.0-0.rockspec \
LDREDIS_DIR=./path-to-installed-cpp-sdk
```

Please note that the Lua SDK uses the C++ server-side SDK's C bindings, so if you're using prebuilt artifacts
then only a C99 compiler is necessary.

Learn more
-----------

Expand Down
17 changes: 14 additions & 3 deletions launchdarkly-server-sdk-1.0-0.rockspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package = "launchdarkly-server-sdk"

rockspec_format = "3.0"

version = "1.0-0"

source = {
Expand All @@ -13,18 +15,27 @@ dependencies = {

external_dependencies = {
LD = {
header = "launchdarkly/api.h"
}
header = "launchdarkly/server_side/bindings/c/sdk.h",
library = "launchdarkly-cpp-server"
},
}

test = {
type = "command",
script = "test.lua"
}

build = {
type = "builtin",
modules = {
["launchdarkly_server_sdk"] = {
sources = { "launchdarkly-server-sdk.c" },
-- Uncomment to compile with debug messages, mainly to help debug parsing configuration/context
-- builders.
-- defines = {"DEBUG=1"},
incdirs = {"$(LD_INCDIR)"},
libdirs = {"$(LD_LIBDIR)"},
libraries = {"ldserverapi"}
libraries = {"launchdarkly-cpp-server"},
}
}
}
12 changes: 10 additions & 2 deletions launchdarkly-server-sdk-redis-1.0-0.rockspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package = "launchdarkly-server-sdk-redis"

rockspec_format = "3.0"

version = "1.0-0"

source = {
Expand All @@ -12,18 +14,24 @@ dependencies = {

external_dependencies = {
LDREDIS = {
header = "launchdarkly/store/redis.h"
header = "launchdarkly/server_side/bindings/c/integrations/redis/redis_source.h",
library = "launchdarkly-cpp-server-redis-source"
}
}

test = {
type = "command",
script = "test-redis.lua"
}

build = {
type = "builtin",
modules = {
["launchdarkly_server_sdk_redis"] = {
sources = { "launchdarkly-server-sdk-redis.c" },
incdirs = {"$(LDREDIS_INCDIR)"},
libdirs = {"$(LDREDIS_LIBDIR)"},
libraries = {"ldserverapi-redis"}
libraries = {"launchdarkly-cpp-server-redis-source"}
}
}
}
76 changes: 27 additions & 49 deletions launchdarkly-server-sdk-redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,73 +9,51 @@ Server-side SDK for LaunchDarkly Redis store.
#include <stdbool.h>
#include <string.h>

#include <launchdarkly/api.h>
#include <launchdarkly/store/redis.h>
#include <launchdarkly/server_side/bindings/c/integrations/redis/redis_source.h>



/***
Initialize a store backend
@function makeStore
@tparam table fields list of configuration options
@tparam[opt] string fields.host Hostname for Redis.
@tparam[opt] int fields.port Port for Redis.
@tparam[opt] string fields.prefix Redis key prefix for SDK values.
@tparam[opt] int fields.poolSize Number of Redis connections to maintain.
@return A fresh Redis store backend.
Create a Redis data source, which can be used instead
of a LaunchDarkly Streaming or Polling data source. This should be configured
in the SDK's configuration table, under the dataSystem.lazyLoad.source property.
@function makeRedisSource
@tparam string uri Redis URI. Example: 'redis://localhost:6379'.
@tparam string prefix Prefix to use when reading SDK data from Redis. This is prefixed to all
Redis keys used by this SDK. Example: 'my-environment'.
@return A new Redis data source.
*/
static int
LuaLDRedisMakeStore(lua_State *const l)
LuaLDRedisMakeSource(lua_State *const l)
{
struct LDRedisConfig *config;
struct LDStoreInterface *storeInterface;

if (lua_gettop(l) != 1) {
return luaL_error(l, "expecting exactly 1 argument");
}

luaL_checktype(l, 1, LUA_TTABLE);

config = LDRedisConfigNew();

lua_getfield(l, 1, "host");

if (lua_isstring(l, -1)) {
LDRedisConfigSetHost(config, luaL_checkstring(l, -1));
if (lua_gettop(l) != 2) {
return luaL_error(l, "expecting exactly 2 arguments");
}

lua_getfield(l, 1, "prefix");

if (lua_isstring(l, -1)) {
LDRedisConfigSetPrefix(config, luaL_checkstring(l, -1));
}

lua_getfield(l, 1, "port");
const char* uri = luaL_checkstring(l, 1);
const char* prefix = luaL_checkstring(l, 2);

if (lua_isnumber(l, -1)) {
LDRedisConfigSetPort(config, luaL_checkinteger(l, -1));
struct LDServerLazyLoadRedisResult out_result;
bool success = LDServerLazyLoadRedisSource_New(uri, prefix, &out_result);
if (!success) {
return luaL_error(l, "failed to create Redis source: %s", out_result.error_message);
}

lua_getfield(l, 1, "poolSize");

if (lua_isnumber(l, -1)) {
LDRedisConfigSetPoolSize(config, luaL_checkinteger(l, -1));
}

storeInterface = LDStoreInterfaceRedisNew(config);

struct LDStoreInterface **i =
(struct LDStoreInterface **)lua_newuserdata(l, sizeof(storeInterface));
LDServerLazyLoadRedisSource *i =
(LDServerLazyLoadRedisSource *) lua_newuserdata(l, sizeof(out_result.source));

*i = storeInterface;
*i = out_result.source;

luaL_getmetatable(l, "LaunchDarklyStoreInterface");
luaL_getmetatable(l, "LaunchDarklySourceInterface");
lua_setmetatable(l, -2);

return 1;
}

static const struct luaL_Reg launchdarkly_functions[] = {
{ "makeStore", LuaLDRedisMakeStore },
{ NULL, NULL }
{ "makeRedisSource", LuaLDRedisMakeSource },
{ NULL, NULL}
};

#if !defined LUA_VERSION_NUM || LUA_VERSION_NUM==501
Expand All @@ -99,7 +77,7 @@ static void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
int
luaopen_launchdarkly_server_sdk_redis(lua_State *const l)
{
#if LUA_VERSION_NUM == 503 || LUA_VERSION_NUM == 502
#if LUA_VERSION_NUM >= 502
luaL_newlib(l, launchdarkly_functions);
#else
luaL_register(l, "launchdarkly-server-sdk-redis",
Expand Down
Loading