Skip to content

Instantly share code, notes, and snippets.

Kunal Anand anandkunal

Block or report user

Report or block anandkunal

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am anandkunal on github.
  • I am kunalanand (https://keybase.io/kunalanand) on keybase.
  • I have a public key ASBB49TMrvEQLZhvjuWQsz6Poc28_OuAEcKicNB-7AGnSAo

To claim this, I am signing this object:

View rpc_tests.sh
PASS
ok _/Users/ka/rpc_tutorial 0.038s
View rpc_test_bits.go
func TestColdGet(t *testing.T) {
item, _ := c.Get(cacheItem.Key)
if item != nil {
t.Errorf("Cache key should not exist: %s\n", cacheItem.Key)
}
}
func TestPut(t *testing.T) {
_, err := c.Put(cacheItem)
if err != nil {
View rpc_test_init.go
var (
c *Client
err error
dsn = "localhost:9876"
cacheItem = &CacheItem{Key: "some key", Value: "some value"}
)
func init() {
c, err = NewClient(dsn, time.Millisecond*500)
View client_funcs.go
func (c *Client) Get(key string) (*CacheItem, error) {
var item *CacheItem
err := c.connection.Call("RPC.Get", key, &item)
return item, err
}
func (c *Client) Put(item *CacheItem) (bool, error) {
var added bool
err := c.connection.Call("RPC.Put", item, &added)
return added, err
View client_constructor.go
type (
Client struct {
connection *rpc.Client
}
)
func NewClient(dsn string, timeout time.Duration) (*Client, error) {
connection, err := net.DialTimeout("tcp", dsn, timeout)
if err != nil {
return nil, err
View rpc_server.go
package main
import (
"log"
"net"
"net/rpc"
"runtime"
)
func init() {
View rpc_stats.go
func (r *RPC) Stats(skip bool, requests *Requests) error {
*requests = *r.requests
return nil
}
View rpc_clear.go
func (r *RPC) Clear(skip bool, ack *bool) error {
r.mu.Lock()
defer r.mu.Unlock()
r.cache = make(map[string]string)
*ack = true
r.requests.Clear++
return nil
}
View rpc_delete.go
func (r *RPC) Delete(key string, ack *bool) error {
r.mu.Lock()
defer r.mu.Unlock()
var found bool
_, found = r.cache[key]
if !found {
return NotFoundError
}
You can’t perform that action at this time.