forked from valkey-io/valkey-glide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated install_and_test.sh so that it accounts for babushkaclient.
Updated lib.rs with types for SuccessCallback and FailureCallback to automate binding creation. Reformatted project structure for babushkaclient and also the benchmarkApp. Cleaned up babushkaclient -Got rid of Callback indexes -Fixed naming conventions
- Loading branch information
1 parent
cb49434
commit ebde38f
Showing
8 changed files
with
128 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package babushkaclient | ||
|
||
/* | ||
#cgo LDFLAGS: -L./target/release -lbabushkaclient | ||
#include "lib.h" | ||
void successCallback(char *message, uintptr_t channelPtr); | ||
void failureCallback(uintptr_t channelPtr); | ||
*/ | ||
import "C" | ||
|
||
import ( | ||
"fmt" | ||
"github.com/aws/babushka/go/benchmarks" | ||
"unsafe" | ||
) | ||
|
||
type BabushkaRedisClient struct { | ||
coreClient unsafe.Pointer | ||
} | ||
|
||
//export successCallback | ||
func successCallback(message *C.char, channelPtr C.uintptr_t) { | ||
goMessage := C.GoString(message) | ||
channelAddress := uintptr(channelPtr) | ||
channel := *(*chan string)(unsafe.Pointer(channelAddress)) | ||
channel <- goMessage | ||
} | ||
|
||
//export failureCallback | ||
func failureCallback(channelPtr C.uintptr_t) { | ||
panic("Failure for get or set") | ||
} | ||
|
||
func (babushkaRedisClient *BabushkaRedisClient) ConnectToRedis(connectionSettings *benchmarks.ConnectionSettings) error { | ||
caddress := C.CString(connectionSettings.Host) | ||
defer C.free(unsafe.Pointer(caddress)) | ||
|
||
babushkaRedisClient.coreClient = C.create_connection(caddress, C.uint32_t(connectionSettings.Port), C._Bool(connectionSettings.UseSsl), C._Bool(connectionSettings.ClusterModeEnabled), (C.SuccessCallback)(unsafe.Pointer(C.successCallback)), (C.FailureCallback)(unsafe.Pointer(C.failureCallback))) | ||
if babushkaRedisClient.coreClient == nil { | ||
return fmt.Errorf("error connecting to babushkaRedisClient") | ||
} | ||
return nil | ||
} | ||
|
||
func (babushkaRedisClient *BabushkaRedisClient) Set(key string, value interface{}) error { | ||
strValue := fmt.Sprintf("%v", value) | ||
ckey := C.CString(key) | ||
cval := C.CString(strValue) | ||
defer C.free(unsafe.Pointer(ckey)) | ||
defer C.free(unsafe.Pointer(cval)) | ||
|
||
result := make(chan string) | ||
chAddress := uintptr(unsafe.Pointer(&result)) | ||
|
||
C.set(babushkaRedisClient.coreClient, ckey, cval, C.uintptr_t(chAddress)) | ||
|
||
<-result | ||
|
||
return nil | ||
} | ||
|
||
func (babushkaRedisClient *BabushkaRedisClient) Get(key string) (string, error) { | ||
ckey := C.CString(key) | ||
defer C.free(unsafe.Pointer(ckey)) | ||
|
||
result := make(chan string) | ||
chAddress := uintptr(unsafe.Pointer(&result)) | ||
|
||
C.get(babushkaRedisClient.coreClient, ckey, C.uintptr_t(chAddress)) | ||
value := <-result | ||
|
||
return value, nil | ||
} | ||
|
||
func (babushkaRedisClient *BabushkaRedisClient) CloseConnection() error { | ||
C.close_connection(babushkaRedisClient.coreClient) | ||
return nil | ||
} | ||
|
||
func (babushkaRedisClient *BabushkaRedisClient) GetName() string { | ||
return "babushka" | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters