Skip to content

Commit

Permalink
Fix some points of #1
Browse files Browse the repository at this point in the history
  • Loading branch information
bpaquet committed Nov 22, 2016
1 parent 921a621 commit b33897d
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 20 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,17 @@ Please feel free to open an issue if you discover problems.

Tests are only integration tests, and are written in PHP.

## undocumented functions
## Undocumented functions

* Statsd statistics
* Write back
* Backward compatibility

## License

[Apache 2 license](license.txt)





Expand Down
10 changes: 5 additions & 5 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"strconv"
"reflect"
"strings"
"encoding/base64"

Expand Down Expand Up @@ -171,10 +170,10 @@ func array_pop(wf write_func, ctx *context, args [][]byte, f string) (error) {
}
x := rec.([]interface{})[0]
// backward compat
t := reflect.TypeOf(x).Kind()
if t == reflect.Int {
switch x.(type) {
case int:
return WriteByteArray(wf, []byte(strconv.Itoa(x.(int))))
} else if t == reflect.String {
case string:
s := x.(string)
if strings.HasPrefix(s, "__64__") {
bytes, err := base64.StdEncoding.DecodeString(s[6:])
Expand All @@ -185,8 +184,9 @@ func array_pop(wf write_func, ctx *context, args [][]byte, f string) (error) {
}
return WriteByteArray(wf, []byte(s))
// end of backward compat
default:
return WriteByteArray(wf, x.([]byte))
}
return WriteByteArray(wf, x.([]byte))
}

func cmd_RPOP(wf write_func, ctx *context, args [][]byte) (error) {
Expand Down
13 changes: 13 additions & 0 deletions license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2016 Bertrand Paquet

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
7 changes: 3 additions & 4 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"errors"
"math/rand"
"time"
"reflect"
"runtime/pprof"

as "github.com/aerospike/aerospike-client-go"
Expand Down Expand Up @@ -78,15 +77,15 @@ func ExpandedMapHandlers() (map[string]handler) {
}

func getIntFromJson(x interface{}) (int) {
if reflect.TypeOf(x).Kind() == reflect.String {
switch x.(type) {
case string:
v, err := strconv.Atoi(x.(string))
if err != nil {
panic(err)
}
return v
} else {
return int(x.(float64))
}
return int(x.(float64))
}

func DisplayExpandedMapCacheStat(ctx *context) {
Expand Down
3 changes: 1 addition & 2 deletions test/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"sets": [{
"proto": "tcp",
"listen": "0.0.0.0:6379",
"set": "redis",
"expanded_map": 1
"set": "redis"
}]
}
11 changes: 11 additions & 0 deletions test/config_expanded_map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"aerospike_ips": [
"192.168.56.80"
],
"sets": [{
"proto": "tcp",
"listen": "0.0.0.0:6379",
"set": "redis",
"expanded_map": 1
}]
}
17 changes: 17 additions & 0 deletions test/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash -e

pkill aerodis || true

echo "Standard test"
../aerodis --config_file config.json &
sleep 3
php test.php
pkill aerodis || true
sleep 3

echo "Expanded map test"
../aerodis --config_file config_expanded_map.json &
sleep 3
php test.php
pkill aerodis || true
sleep 3
16 changes: 8 additions & 8 deletions writers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"log"
"strconv"
"reflect"
"encoding/base64"
"strings"
"bytes"
Expand Down Expand Up @@ -35,8 +34,8 @@ func WriteArray(wf write_func, array []interface{}) error {
}
for _, e := range array {
// backward compat
t := reflect.TypeOf(e).Kind()
if t == reflect.String {
switch e.(type) {
case string:
s := e.(string)
if strings.HasPrefix(s, "__64__") {
bytes, err := base64.StdEncoding.DecodeString(s[6:])
Expand All @@ -53,7 +52,7 @@ func WriteArray(wf write_func, array []interface{}) error {
return err
}
}
} else {
default:
// end of backward compat
err := WriteByteArray(wf, e.([]byte))
if err != nil {
Expand All @@ -69,11 +68,11 @@ func WriteLine(wf write_func, s string) error {
}

func WriteValue(wf write_func, x interface{}) error {
t := reflect.TypeOf(x).Kind()
if t == reflect.Int {
switch x.(type) {
case int:
return WriteByteArray(wf, []byte(strconv.Itoa(x.(int))))
// backward compat
} else if t == reflect.String {
case string:
s := x.(string)
if strings.HasPrefix(s, "__64__") {
bytes, err := base64.StdEncoding.DecodeString(s[6:])
Expand All @@ -85,8 +84,9 @@ func WriteValue(wf write_func, x interface{}) error {
return WriteByteArray(wf, []byte(s))
}
// end of backward compat
default:
return WriteByteArray(wf, x.([]byte))
}
return WriteByteArray(wf, x.([]byte))
}

func WriteBin(wf write_func, rec * as.Record, bin_name string, nil_value string) error {
Expand Down

0 comments on commit b33897d

Please sign in to comment.